petewil | 7c8537f | 2017-06-16 23:03:15 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_OFFLINE_PAGES_OFFLINER_USER_DATA_H_ |
| 6 | #define CHROME_BROWSER_OFFLINE_PAGES_OFFLINER_USER_DATA_H_ |
| 7 | |
| 8 | #include "chrome/browser/offline_pages/background_loader_offliner.h" |
| 9 | #include "chrome/browser/offline_pages/resource_loading_observer.h" |
petewil | 7c8537f | 2017-06-16 23:03:15 | [diff] [blame] | 10 | #include "content/public/browser/web_contents_user_data.h" |
| 11 | |
| 12 | namespace offline_pages { |
| 13 | |
| 14 | class OfflinerUserData : public content::WebContentsUserData<OfflinerUserData> { |
| 15 | public: |
| 16 | static void AddToWebContents(content::WebContents* webcontents, |
| 17 | BackgroundLoaderOffliner* offliner); |
| 18 | |
| 19 | static BackgroundLoaderOffliner* OfflinerFromWebContents( |
| 20 | content::WebContents* webcontents); |
| 21 | |
| 22 | static ResourceLoadingObserver* ResourceLoadingObserverFromWebContents( |
| 23 | content::WebContents* webcontents); |
| 24 | |
| 25 | explicit OfflinerUserData(BackgroundLoaderOffliner* offliner) { |
| 26 | offliner_ = offliner; |
| 27 | } |
| 28 | BackgroundLoaderOffliner* offliner() { return offliner_; } |
| 29 | |
| 30 | private: |
| 31 | // The offliner that the WebContents is attached to. The offliner owns the |
| 32 | // Delegate which owns the WebContents that this data is attached to. |
| 33 | // Therefore, its lifetime should exceed that of the WebContents, so this |
| 34 | // should always be non-null. |
| 35 | BackgroundLoaderOffliner* offliner_; |
| 36 | }; |
| 37 | |
| 38 | } // namespace offline_pages |
| 39 | |
| 40 | #endif // CHROME_BROWSER_OFFLINE_PAGES_OFFLINER_USER_DATA_H_ |