| 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 19 matching lines...) Expand all Loading... |
| 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& completion_callback, | 38 const CompletionCallback& completion_callback, |
| 39 const ProgressCallback& progress_callback) override; | 39 const ProgressCallback& progress_callback) override; |
| 40 void Cancel(const CancelCallback& callback) override; | 40 bool Cancel(const CancelCallback& callback) override; |
| 41 bool HandleTimeout(const SavePageRequest& request) override; | 41 bool HandleTimeout(int64_t request_id) override; |
| 42 | 42 |
| 43 // Allows a loader to be injected for testing. This may only be done once | 43 // Allows a loader to be injected for testing. This may only be done once |
| 44 // and must be called before any of the Offliner interface methods are called. | 44 // and must be called before any of the Offliner interface methods are called. |
| 45 void SetLoaderForTesting(std::unique_ptr<PrerenderingLoader> loader); | 45 void SetLoaderForTesting(std::unique_ptr<PrerenderingLoader> loader); |
| 46 | 46 |
| 47 void SetLowEndDeviceForTesting(bool is_low_end_device); | 47 void SetLowEndDeviceForTesting(bool is_low_end_device); |
| 48 | 48 |
| 49 void SetApplicationStateForTesting( | 49 void SetApplicationStateForTesting( |
| 50 base::android::ApplicationState application_state); | 50 base::android::ApplicationState application_state); |
| 51 | 51 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 int64_t offline_id); | 73 int64_t offline_id); |
| 74 | 74 |
| 75 // Write the payload of the loading signal data MHTML section into a string. | 75 // Write the payload of the loading signal data MHTML section into a string. |
| 76 std::string SerializeLoadingSignalData(); | 76 std::string SerializeLoadingSignalData(); |
| 77 | 77 |
| 78 PrerenderingLoader* GetOrCreateLoader(); | 78 PrerenderingLoader* GetOrCreateLoader(); |
| 79 | 79 |
| 80 // Listener function for changes to application background/foreground state. | 80 // Listener function for changes to application background/foreground state. |
| 81 void OnApplicationStateChange( | 81 void OnApplicationStateChange( |
| 82 base::android::ApplicationState application_state); | 82 base::android::ApplicationState application_state); |
| 83 void HandleApplicationStateChangeCancel(const SavePageRequest& request, | |
| 84 int64_t offline_id); | |
| 85 | 83 |
| 86 // Not owned. | 84 // Not owned. |
| 87 content::BrowserContext* browser_context_; | 85 content::BrowserContext* browser_context_; |
| 88 // Not owned. | 86 // Not owned. |
| 89 const OfflinerPolicy* policy_; | 87 const OfflinerPolicy* policy_; |
| 90 // Not owned. | 88 // Not owned. |
| 91 OfflinePageModel* offline_page_model_; | 89 OfflinePageModel* offline_page_model_; |
| 92 // Lazily created. | 90 // Lazily created. |
| 93 std::unique_ptr<PrerenderingLoader> loader_; | 91 std::unique_ptr<PrerenderingLoader> loader_; |
| 94 // Tracks pending request, if any. Owned copy. | 92 // Tracks pending request, if any. Owned copy. |
| 95 // May be used to ensure a callback applies to the pending request (e.g., in | 93 // May be used to ensure a callback applies to the pending request (e.g., in |
| 96 // case we receive a save page callback for an old, canceled request). | 94 // case we receive a save page callback for an old, canceled request). |
| 97 std::unique_ptr<SavePageRequest> pending_request_; | 95 std::unique_ptr<SavePageRequest> pending_request_; |
| 98 // Callback to call when pending request completes/fails. | 96 // Callback to call when pending request completes/fails. |
| 99 CompletionCallback completion_callback_; | 97 CompletionCallback completion_callback_; |
| 100 ProgressCallback progress_callback_; | 98 ProgressCallback progress_callback_; |
| 101 bool is_low_end_device_; | 99 bool is_low_end_device_; |
| 102 bool saved_on_last_retry_; | 100 bool saved_on_last_retry_; |
| 103 // ApplicationStatusListener to monitor if the Chrome moves to the foreground. | 101 // ApplicationStatusListener to monitor if the Chrome moves to the foreground. |
| 104 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; | 102 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; |
| 105 base::WeakPtrFactory<PrerenderingOffliner> weak_ptr_factory_; | 103 base::WeakPtrFactory<PrerenderingOffliner> weak_ptr_factory_; |
| 106 | 104 |
| 107 DISALLOW_COPY_AND_ASSIGN(PrerenderingOffliner); | 105 DISALLOW_COPY_AND_ASSIGN(PrerenderingOffliner); |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 } // namespace offline_pages | 108 } // namespace offline_pages |
| 111 | 109 |
| 112 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ | 110 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PRERENDERING_OFFLINER_H_ |
| OLD | NEW |