| 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_PRERENDERING_OFFLINER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_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 18 matching lines...) Expand all Loading... |
| 29 class PrerenderingOffliner : public Offliner { | 29 class PrerenderingOffliner : public Offliner { |
| 30 public: | 30 public: |
| 31 PrerenderingOffliner(content::BrowserContext* browser_context, | 31 PrerenderingOffliner(content::BrowserContext* browser_context, |
| 32 const OfflinerPolicy* policy, | 32 const OfflinerPolicy* policy, |
| 33 OfflinePageModel* offline_page_model); | 33 OfflinePageModel* offline_page_model); |
| 34 ~PrerenderingOffliner() override; | 34 ~PrerenderingOffliner() override; |
| 35 | 35 |
| 36 // Offliner implementation. | 36 // Offliner implementation. |
| 37 bool LoadAndSave(const SavePageRequest& request, | 37 bool LoadAndSave(const SavePageRequest& request, |
| 38 const CompletionCallback& callback) override; | 38 const CompletionCallback& callback) override; |
| 39 void Cancel() override; | 39 void Cancel(const CancelCallback& callback) override; |
| 40 | 40 |
| 41 // Allows a loader to be injected for testing. This may only be done once | 41 // Allows a loader to be injected for testing. This may only be done once |
| 42 // and must be called before any of the Offliner interface methods are called. | 42 // and must be called before any of the Offliner interface methods are called. |
| 43 void SetLoaderForTesting(std::unique_ptr<PrerenderingLoader> loader); | 43 void SetLoaderForTesting(std::unique_ptr<PrerenderingLoader> loader); |
| 44 | 44 |
| 45 void SetLowEndDeviceForTesting(bool is_low_end_device); | 45 void SetLowEndDeviceForTesting(bool is_low_end_device); |
| 46 | 46 |
| 47 void SetApplicationStateForTesting( | 47 void SetApplicationStateForTesting( |
| 48 base::android::ApplicationState application_state); | 48 base::android::ApplicationState application_state); |
| 49 | 49 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 // Callback logic for OfflinePageModel::SavePage(). | 65 // Callback logic for OfflinePageModel::SavePage(). |
| 66 void OnSavePageDone(const SavePageRequest& request, | 66 void OnSavePageDone(const SavePageRequest& request, |
| 67 SavePageResult save_result, | 67 SavePageResult save_result, |
| 68 int64_t offline_id); | 68 int64_t offline_id); |
| 69 | 69 |
| 70 PrerenderingLoader* GetOrCreateLoader(); | 70 PrerenderingLoader* GetOrCreateLoader(); |
| 71 | 71 |
| 72 // Listener function for changes to application background/foreground state. | 72 // Listener function for changes to application background/foreground state. |
| 73 void OnApplicationStateChange( | 73 void OnApplicationStateChange( |
| 74 base::android::ApplicationState application_state); | 74 base::android::ApplicationState application_state); |
| 75 void HandleApplicationStateChangeCancel(const SavePageRequest& request, |
| 76 int64_t offline_id); |
| 75 | 77 |
| 76 // Not owned. | 78 // Not owned. |
| 77 content::BrowserContext* browser_context_; | 79 content::BrowserContext* browser_context_; |
| 78 // Not owned. | 80 // Not owned. |
| 79 OfflinePageModel* offline_page_model_; | 81 OfflinePageModel* offline_page_model_; |
| 80 // Lazily created. | 82 // Lazily created. |
| 81 std::unique_ptr<PrerenderingLoader> loader_; | 83 std::unique_ptr<PrerenderingLoader> loader_; |
| 82 // Tracks pending request, if any. Owned copy. | 84 // Tracks pending request, if any. Owned copy. |
| 83 // May be used to ensure a callback applies to the pending request (e.g., in | 85 // May be used to ensure a callback applies to the pending request (e.g., in |
| 84 // case we receive a save page callback for an old, canceled request). | 86 // case we receive a save page callback for an old, canceled request). |
| 85 std::unique_ptr<SavePageRequest> pending_request_; | 87 std::unique_ptr<SavePageRequest> pending_request_; |
| 86 // Callback to call when pending request completes/fails. | 88 // Callback to call when pending request completes/fails. |
| 87 CompletionCallback completion_callback_; | 89 CompletionCallback completion_callback_; |
| 88 bool is_low_end_device_; | 90 bool is_low_end_device_; |
| 89 // ApplicationStatusListener to monitor if the Chrome moves to the foreground. | 91 // ApplicationStatusListener to monitor if the Chrome moves to the foreground. |
| 90 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 92 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 91 base::WeakPtrFactory<PrerenderingOffliner> weak_ptr_factory_; | 93 base::WeakPtrFactory<PrerenderingOffliner> weak_ptr_factory_; |
| 92 | 94 |
| 93 DISALLOW_COPY_AND_ASSIGN(PrerenderingOffliner); | 95 DISALLOW_COPY_AND_ASSIGN(PrerenderingOffliner); |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 } // namespace offline_pages | 98 } // namespace offline_pages |
| 97 | 99 |
| 98 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ | 100 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ |
| OLD | NEW |