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