| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 5 #ifndef CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| 6 #define CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 6 #define CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/loader/resource_tracker_observer.h" |
| 12 #include "components/offline_pages/content/background_loader/background_loader_c
ontents.h" | 13 #include "components/offline_pages/content/background_loader/background_loader_c
ontents.h" |
| 13 #include "components/offline_pages/core/background/load_termination_listener.h" | 14 #include "components/offline_pages/core/background/load_termination_listener.h" |
| 14 #include "components/offline_pages/core/background/offliner.h" | 15 #include "components/offline_pages/core/background/offliner.h" |
| 15 #include "components/offline_pages/core/offline_page_types.h" | 16 #include "components/offline_pages/core/offline_page_types.h" |
| 16 #include "components/offline_pages/core/snapshot_controller.h" | 17 #include "components/offline_pages/core/snapshot_controller.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 class BrowserContext; | 21 class BrowserContext; |
| 21 } // namespace content | 22 } // namespace content |
| 22 | 23 |
| 23 namespace offline_pages { | 24 namespace offline_pages { |
| 24 | 25 |
| 25 class OfflinerPolicy; | 26 class OfflinerPolicy; |
| 26 class OfflinePageModel; | 27 class OfflinePageModel; |
| 27 | 28 |
| 28 // An Offliner implementation that attempts client-side rendering and saving | 29 // An Offliner implementation that attempts client-side rendering and saving |
| 29 // of an offline page. It uses the BackgroundLoader to load the page and the | 30 // of an offline page. It uses the BackgroundLoader to load the page and the |
| 30 // OfflinePageModel to save it. Only one request may be active at a time. | 31 // OfflinePageModel to save it. Only one request may be active at a time. |
| 31 class BackgroundLoaderOffliner : public Offliner, | 32 class BackgroundLoaderOffliner : public Offliner, |
| 32 public content::WebContentsObserver, | 33 public content::WebContentsObserver, |
| 33 public SnapshotController::Client { | 34 public SnapshotController::Client, |
| 35 public ResourceTrackerObserver { |
| 34 public: | 36 public: |
| 35 BackgroundLoaderOffliner( | 37 BackgroundLoaderOffliner( |
| 36 content::BrowserContext* browser_context, | 38 content::BrowserContext* browser_context, |
| 37 const OfflinerPolicy* policy, | 39 const OfflinerPolicy* policy, |
| 38 OfflinePageModel* offline_page_model, | 40 OfflinePageModel* offline_page_model, |
| 39 std::unique_ptr<LoadTerminationListener> load_termination_listener); | 41 std::unique_ptr<LoadTerminationListener> load_termination_listener); |
| 40 ~BackgroundLoaderOffliner() override; | 42 ~BackgroundLoaderOffliner() override; |
| 41 | 43 |
| 42 static BackgroundLoaderOffliner* FromWebContents( | 44 static BackgroundLoaderOffliner* FromWebContents( |
| 43 content::WebContents* contents); | 45 content::WebContents* contents); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 void RenderProcessGone(base::TerminationStatus status) override; | 58 void RenderProcessGone(base::TerminationStatus status) override; |
| 57 void WebContentsDestroyed() override; | 59 void WebContentsDestroyed() override; |
| 58 void DidFinishNavigation( | 60 void DidFinishNavigation( |
| 59 content::NavigationHandle* navigation_handle) override; | 61 content::NavigationHandle* navigation_handle) override; |
| 60 | 62 |
| 61 // SnapshotController::Client implementation. | 63 // SnapshotController::Client implementation. |
| 62 void StartSnapshot() override; | 64 void StartSnapshot() override; |
| 63 | 65 |
| 64 void SetSnapshotControllerForTest( | 66 void SetSnapshotControllerForTest( |
| 65 std::unique_ptr<SnapshotController> controller); | 67 std::unique_ptr<SnapshotController> controller); |
| 66 void OnNetworkBytesChanged(int64_t bytes); | 68 |
| 69 // ResourceTrackerObserver implemenation |
| 70 void ObserveResourceTracking(ResourceTrackerObserver::ResourceDataType type, |
| 71 bool started) override; |
| 72 void OnNetworkBytesChanged(int64_t bytes) override; |
| 67 | 73 |
| 68 protected: | 74 protected: |
| 69 // Called to reset the loader. | 75 // Called to reset the loader. |
| 70 virtual void ResetLoader(); | 76 virtual void ResetLoader(); |
| 71 | 77 |
| 72 private: | 78 private: |
| 73 friend class TestBackgroundLoaderOffliner; | 79 friend class TestBackgroundLoaderOffliner; |
| 74 | 80 |
| 75 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; | 81 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; |
| 76 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY }; | 82 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY }; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 140 |
| 135 // Callback for cancel. | 141 // Callback for cancel. |
| 136 CancelCallback cancel_callback_; | 142 CancelCallback cancel_callback_; |
| 137 | 143 |
| 138 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; | 144 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; |
| 139 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); | 145 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); |
| 140 }; | 146 }; |
| 141 | 147 |
| 142 } // namespace offline_pages | 148 } // namespace offline_pages |
| 143 #endif // CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 149 #endif // CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| OLD | NEW |