| 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/android/application_status_listener.h" | |
| 11 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 12 #include "base/values.h" | 11 #include "base/values.h" |
| 13 #include "components/offline_pages/content/background_loader/background_loader_c
ontents.h" | 12 #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/offliner.h" | 14 #include "components/offline_pages/core/background/offliner.h" |
| 15 #include "components/offline_pages/core/offline_page_types.h" | 15 #include "components/offline_pages/core/offline_page_types.h" |
| 16 #include "components/offline_pages/core/snapshot_controller.h" | 16 #include "components/offline_pages/core/snapshot_controller.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class BrowserContext; | 20 class BrowserContext; |
| 21 } // namespace content | 21 } // namespace content |
| 22 | 22 |
| 23 namespace offline_pages { | 23 namespace offline_pages { |
| 24 | 24 |
| 25 class OfflinerPolicy; | 25 class OfflinerPolicy; |
| 26 class OfflinePageModel; | 26 class OfflinePageModel; |
| 27 | 27 |
| 28 // An Offliner implementation that attempts client-side rendering and saving | 28 // 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 | 29 // 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. | 30 // OfflinePageModel to save it. Only one request may be active at a time. |
| 31 class BackgroundLoaderOffliner : public Offliner, | 31 class BackgroundLoaderOffliner : public Offliner, |
| 32 public content::WebContentsObserver, | 32 public content::WebContentsObserver, |
| 33 public SnapshotController::Client { | 33 public SnapshotController::Client { |
| 34 public: | 34 public: |
| 35 BackgroundLoaderOffliner(content::BrowserContext* browser_context, | 35 BackgroundLoaderOffliner( |
| 36 const OfflinerPolicy* policy, | 36 content::BrowserContext* browser_context, |
| 37 OfflinePageModel* offline_page_model); | 37 const OfflinerPolicy* policy, |
| 38 OfflinePageModel* offline_page_model, |
| 39 std::unique_ptr<LoadTerminationListener> load_termination_listener); |
| 38 ~BackgroundLoaderOffliner() override; | 40 ~BackgroundLoaderOffliner() override; |
| 39 | 41 |
| 40 static BackgroundLoaderOffliner* FromWebContents( | 42 static BackgroundLoaderOffliner* FromWebContents( |
| 41 content::WebContents* contents); | 43 content::WebContents* contents); |
| 42 | 44 |
| 43 // Offliner implementation. | 45 // Offliner implementation. |
| 44 bool LoadAndSave(const SavePageRequest& request, | 46 bool LoadAndSave(const SavePageRequest& request, |
| 45 const CompletionCallback& completion_callback, | 47 const CompletionCallback& completion_callback, |
| 46 const ProgressCallback& progress_callback) override; | 48 const ProgressCallback& progress_callback) override; |
| 47 bool Cancel(const CancelCallback& callback) override; | 49 bool Cancel(const CancelCallback& callback) override; |
| 50 void TerminateLoadIfInProgress() override; |
| 48 bool HandleTimeout(int64_t request_id) override; | 51 bool HandleTimeout(int64_t request_id) override; |
| 49 | 52 |
| 50 // WebContentsObserver implementation. | 53 // WebContentsObserver implementation. |
| 51 void DocumentAvailableInMainFrame() override; | 54 void DocumentAvailableInMainFrame() override; |
| 52 void DocumentOnLoadCompletedInMainFrame() override; | 55 void DocumentOnLoadCompletedInMainFrame() override; |
| 53 void RenderProcessGone(base::TerminationStatus status) override; | 56 void RenderProcessGone(base::TerminationStatus status) override; |
| 54 void WebContentsDestroyed() override; | 57 void WebContentsDestroyed() override; |
| 55 void DidFinishNavigation( | 58 void DidFinishNavigation( |
| 56 content::NavigationHandle* navigation_handle) override; | 59 content::NavigationHandle* navigation_handle) override; |
| 57 | 60 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 74 | 77 |
| 75 // Called when the page has been saved. | 78 // Called when the page has been saved. |
| 76 void OnPageSaved(SavePageResult save_result, int64_t offline_id); | 79 void OnPageSaved(SavePageResult save_result, int64_t offline_id); |
| 77 | 80 |
| 78 // Called to reset internal loader and observer state. | 81 // Called to reset internal loader and observer state. |
| 79 void ResetState(); | 82 void ResetState(); |
| 80 | 83 |
| 81 // Called to attach 'this' as the observer to the loader. | 84 // Called to attach 'this' as the observer to the loader. |
| 82 void AttachObservers(); | 85 void AttachObservers(); |
| 83 | 86 |
| 84 // Called when application state has changed. | |
| 85 void OnApplicationStateChange( | |
| 86 base::android::ApplicationState application_state); | |
| 87 | |
| 88 // Called to remember at what time we started loading. | 87 // Called to remember at what time we started loading. |
| 89 void MarkLoadStartTime(); | 88 void MarkLoadStartTime(); |
| 90 | 89 |
| 91 // Called to add a loading signal as we observe it. | 90 // Called to add a loading signal as we observe it. |
| 92 void AddLoadingSignal(const char* signal_name); | 91 void AddLoadingSignal(const char* signal_name); |
| 93 | 92 |
| 94 void DeleteOfflinePageCallback(const SavePageRequest& request, | 93 void DeleteOfflinePageCallback(const SavePageRequest& request, |
| 95 DeletePageResult result); | 94 DeletePageResult result); |
| 96 | 95 |
| 97 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; | 96 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; |
| 98 // Not owned. | 97 // Not owned. |
| 99 content::BrowserContext* browser_context_; | 98 content::BrowserContext* browser_context_; |
| 100 // Not owned. | 99 // Not owned. |
| 101 OfflinePageModel* offline_page_model_; | 100 OfflinePageModel* offline_page_model_; |
| 102 // Not owned. | 101 // Not owned. |
| 103 const OfflinerPolicy* policy_; | 102 const OfflinerPolicy* policy_; |
| 104 // Tracks pending request, if any. | 103 // Tracks pending request, if any. |
| 105 std::unique_ptr<SavePageRequest> pending_request_; | 104 std::unique_ptr<SavePageRequest> pending_request_; |
| 106 // Handles determining when a page should be snapshotted. | 105 // Handles determining when a page should be snapshotted. |
| 107 std::unique_ptr<SnapshotController> snapshot_controller_; | 106 std::unique_ptr<SnapshotController> snapshot_controller_; |
| 108 // Callback when pending request completes. | 107 // Callback when pending request completes. |
| 109 CompletionCallback completion_callback_; | 108 CompletionCallback completion_callback_; |
| 110 // Callback to report progress. | 109 // Callback to report progress. |
| 111 ProgressCallback progress_callback_; | 110 ProgressCallback progress_callback_; |
| 112 // ApplicationStatusListener to monitor if Chrome moves to the foreground. | 111 // LoadTerminationListener to monitor external conditions requiring immediate |
| 113 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 112 // termination of the offlining operation (memory conditions etc). |
| 113 std::unique_ptr<LoadTerminationListener> load_termination_listener_; |
| 114 // Whether we are on a low-end device. | 114 // Whether we are on a low-end device. |
| 115 bool is_low_end_device_; | 115 bool is_low_end_device_; |
| 116 | 116 |
| 117 // Save state. | 117 // Save state. |
| 118 SaveState save_state_; | 118 SaveState save_state_; |
| 119 // Page load state. | 119 // Page load state. |
| 120 PageLoadState page_load_state_; | 120 PageLoadState page_load_state_; |
| 121 // Network bytes loaded. | 121 // Network bytes loaded. |
| 122 int64_t network_bytes_; | 122 int64_t network_bytes_; |
| 123 // Whether the low bar of snapshot quality has been met. | 123 // Whether the low bar of snapshot quality has been met. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 | 134 |
| 135 // Callback for cancel. | 135 // Callback for cancel. |
| 136 CancelCallback cancel_callback_; | 136 CancelCallback cancel_callback_; |
| 137 | 137 |
| 138 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; | 138 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; |
| 139 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); | 139 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace offline_pages | 142 } // namespace offline_pages |
| 143 #endif // CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 143 #endif // CHROME_BROWSER_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| OLD | NEW |