Chromium Code Reviews| 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_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/android/application_status_listener.h" | 10 #include "base/android/application_status_listener.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 // of an offline page. It uses the BackgroundLoader to load the page and the | 27 // of an offline page. It uses the BackgroundLoader to load the page and the |
| 28 // OfflinePageModel to save it. Only one request may be active at a time. | 28 // OfflinePageModel to save it. Only one request may be active at a time. |
| 29 class BackgroundLoaderOffliner : public Offliner, | 29 class BackgroundLoaderOffliner : public Offliner, |
| 30 public content::WebContentsObserver { | 30 public content::WebContentsObserver { |
| 31 public: | 31 public: |
| 32 BackgroundLoaderOffliner(content::BrowserContext* browser_context, | 32 BackgroundLoaderOffliner(content::BrowserContext* browser_context, |
| 33 const OfflinerPolicy* policy, | 33 const OfflinerPolicy* policy, |
| 34 OfflinePageModel* offline_page_model); | 34 OfflinePageModel* offline_page_model); |
| 35 ~BackgroundLoaderOffliner() override; | 35 ~BackgroundLoaderOffliner() override; |
| 36 | 36 |
| 37 static BackgroundLoaderOffliner* FromWebContents( | |
| 38 content::WebContents* contents); | |
| 39 | |
| 37 // Offliner implementation. | 40 // Offliner implementation. |
| 38 bool LoadAndSave(const SavePageRequest& request, | 41 bool LoadAndSave(const SavePageRequest& request, |
| 39 const CompletionCallback& completion_callback, | 42 const CompletionCallback& completion_callback, |
| 40 const ProgressCallback& progress_callback) override; | 43 const ProgressCallback& progress_callback) override; |
| 41 void Cancel(const CancelCallback& callback) override; | 44 void Cancel(const CancelCallback& callback) override; |
| 42 bool HandleTimeout(const SavePageRequest& request) override; | 45 bool HandleTimeout(const SavePageRequest& request) override; |
| 43 | 46 |
| 44 // WebContentsObserver implementation. | 47 // WebContentsObserver implementation. |
| 45 void DidStopLoading() override; | 48 void DidStopLoading() override; |
| 46 void RenderProcessGone(base::TerminationStatus status) override; | 49 void RenderProcessGone(base::TerminationStatus status) override; |
| 47 void WebContentsDestroyed() override; | 50 void WebContentsDestroyed() override; |
| 48 void DidFinishNavigation( | 51 void DidFinishNavigation( |
| 49 content::NavigationHandle* navigation_handle) override; | 52 content::NavigationHandle* navigation_handle) override; |
| 50 | 53 |
| 51 void SetPageDelayForTest(long delay_ms); | 54 void SetPageDelayForTest(long delay_ms); |
| 55 void OnNetworkBytesChanged(int64_t bytes); | |
| 52 | 56 |
| 53 protected: | 57 protected: |
| 54 // Called to reset internal loader and observer state. | 58 // Called to reset internal loader and observer state. |
| 55 virtual void ResetState(); | 59 virtual void ResetState(); |
| 56 | 60 |
| 57 private: | 61 private: |
| 58 friend class TestBackgroundLoaderOffliner; | 62 friend class TestBackgroundLoaderOffliner; |
| 63 // Currently there should only be one offliner created... | |
| 64 static BackgroundLoaderOffliner* offliner_; | |
|
Dmitry Titov
2017/03/09 03:15:55
Perhaps this can be avoided by setting the Backgro
| |
| 59 | 65 |
| 60 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; | 66 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; |
| 61 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY }; | 67 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY }; |
| 62 | 68 |
| 63 // Called when the page is ready to be saved. | 69 // Called when the page is ready to be saved. |
| 64 void SavePage(); | 70 void SavePage(); |
| 65 | 71 |
| 66 // Called when the page has been saved. | 72 // Called when the page has been saved. |
| 67 void OnPageSaved(SavePageResult save_result, int64_t offline_id); | 73 void OnPageSaved(SavePageResult save_result, int64_t offline_id); |
| 68 | 74 |
| 69 // Called when application state has changed. | 75 // Called when application state has changed. |
| 70 void OnApplicationStateChange( | 76 void OnApplicationStateChange( |
| 71 base::android::ApplicationState application_state); | 77 base::android::ApplicationState application_state); |
| 72 void HandleApplicationStateChangeCancel(const SavePageRequest& request, | 78 void HandleApplicationStateChangeCancel(const SavePageRequest& request, |
| 73 int64_t offline_id); | 79 int64_t offline_id); |
| 74 | 80 |
| 75 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; | 81 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; |
| 76 // Not owned. | 82 // Not owned. |
| 77 content::BrowserContext* browser_context_; | 83 content::BrowserContext* browser_context_; |
| 78 // Not owned. | 84 // Not owned. |
| 79 OfflinePageModel* offline_page_model_; | 85 OfflinePageModel* offline_page_model_; |
| 80 // Tracks pending request, if any. | 86 // Tracks pending request, if any. |
| 81 std::unique_ptr<SavePageRequest> pending_request_; | 87 std::unique_ptr<SavePageRequest> pending_request_; |
| 82 // Callback when pending request completes. | 88 // Callback when pending request completes. |
| 83 CompletionCallback completion_callback_; | 89 CompletionCallback completion_callback_; |
| 90 // Callback to report progress. | |
| 91 ProgressCallback progress_callback_; | |
| 84 // ApplicationStatusListener to monitor if Chrome moves to the foreground. | 92 // ApplicationStatusListener to monitor if Chrome moves to the foreground. |
| 85 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 93 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 86 // Whether we are on a low-end device. | 94 // Whether we are on a low-end device. |
| 87 bool is_low_end_device_; | 95 bool is_low_end_device_; |
| 88 | 96 |
| 89 // Save state. | 97 // Save state. |
| 90 SaveState save_state_; | 98 SaveState save_state_; |
| 91 // Page load state. | 99 // Page load state. |
| 92 PageLoadState page_load_state_; | 100 PageLoadState page_load_state_; |
| 93 // Seconds to delay before taking snapshot. | 101 // Seconds to delay before taking snapshot. |
| 94 long page_delay_ms_; | 102 long page_delay_ms_; |
| 103 // Network bytes loaded. | |
| 104 int64_t network_bytes_; | |
| 95 | 105 |
| 96 // Callback for cancel. | 106 // Callback for cancel. |
| 97 CancelCallback cancel_callback_; | 107 CancelCallback cancel_callback_; |
| 98 | 108 |
| 99 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; | 109 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; |
| 100 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); | 110 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); |
| 101 }; | 111 }; |
| 102 | 112 |
| 103 } // namespace offline_pages | 113 } // namespace offline_pages |
| 104 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 114 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| OLD | NEW |