| 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 19 matching lines...) Expand all Loading... |
| 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 // Offliner implementation. | 37 // Offliner implementation. |
| 38 bool LoadAndSave(const SavePageRequest& request, | 38 bool LoadAndSave(const SavePageRequest& request, |
| 39 const CompletionCallback& callback) override; | 39 const CompletionCallback& callback) override; |
| 40 void Cancel() override; | 40 void Cancel(const CancelCallback& callback) override; |
| 41 | 41 |
| 42 // WebContentsObserver implementation. | 42 // WebContentsObserver implementation. |
| 43 void DidStopLoading() override; | 43 void DidStopLoading() override; |
| 44 void RenderProcessGone(base::TerminationStatus status) override; | 44 void RenderProcessGone(base::TerminationStatus status) override; |
| 45 void WebContentsDestroyed() override; | 45 void WebContentsDestroyed() override; |
| 46 void DidFinishNavigation( | 46 void DidFinishNavigation( |
| 47 content::NavigationHandle* navigation_handle) override; | 47 content::NavigationHandle* navigation_handle) override; |
| 48 | 48 |
| 49 protected: | 49 protected: |
| 50 // Called to reset internal loader and observer state. | 50 // Called to reset internal loader and observer state. |
| 51 virtual void ResetState(); | 51 virtual void ResetState(); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 friend class TestBackgroundLoaderOffliner; | 54 friend class TestBackgroundLoaderOffliner; |
| 55 | 55 |
| 56 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; | 56 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; |
| 57 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE }; | 57 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE }; |
| 58 | 58 |
| 59 // Called when the page has been saved. | 59 // Called when the page has been saved. |
| 60 void OnPageSaved(SavePageResult save_result, int64_t offline_id); | 60 void OnPageSaved(SavePageResult save_result, int64_t offline_id); |
| 61 | 61 |
| 62 // Called when application state has changed. | 62 // Called when application state has changed. |
| 63 void OnApplicationStateChange( | 63 void OnApplicationStateChange( |
| 64 base::android::ApplicationState application_state); | 64 base::android::ApplicationState application_state); |
| 65 void HandleApplicationStateChangeCancel(const SavePageRequest& request, |
| 66 int64_t offline_id); |
| 65 | 67 |
| 66 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; | 68 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; |
| 67 // Not owned. | 69 // Not owned. |
| 68 content::BrowserContext* browser_context_; | 70 content::BrowserContext* browser_context_; |
| 69 // Not owned. | 71 // Not owned. |
| 70 OfflinePageModel* offline_page_model_; | 72 OfflinePageModel* offline_page_model_; |
| 71 // Tracks pending request, if any. | 73 // Tracks pending request, if any. |
| 72 std::unique_ptr<SavePageRequest> pending_request_; | 74 std::unique_ptr<SavePageRequest> pending_request_; |
| 73 // Callback when pending request completes. | 75 // Callback when pending request completes. |
| 74 CompletionCallback completion_callback_; | 76 CompletionCallback completion_callback_; |
| 75 // ApplicationStatusListener to monitor if Chrome moves to the foreground. | 77 // ApplicationStatusListener to monitor if Chrome moves to the foreground. |
| 76 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 78 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 77 // Whether we are on a low-end device. | 79 // Whether we are on a low-end device. |
| 78 bool is_low_end_device_; | 80 bool is_low_end_device_; |
| 81 |
| 79 // Save state. | 82 // Save state. |
| 80 SaveState save_state_; | 83 SaveState save_state_; |
| 81 // Page load state. | 84 // Page load state. |
| 82 PageLoadState page_load_state_; | 85 PageLoadState page_load_state_; |
| 83 | 86 |
| 87 // Callback for cancel. |
| 88 CancelCallback cancel_callback_; |
| 89 |
| 84 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; | 90 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; |
| 85 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); | 91 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); |
| 86 }; | 92 }; |
| 87 | 93 |
| 88 } // namespace offline_pages | 94 } // namespace offline_pages |
| 89 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ | 95 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ |
| OLD | NEW |