Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: chrome/browser/android/offline_pages/background_loader_offliner.h

Issue 2789503002: Revert of [Offline pages] Integrate snapshot controller fully into background loader. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/background_loader_offliner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "components/offline_pages/content/background_loader/background_loader_c ontents.h" 12 #include "components/offline_pages/content/background_loader/background_loader_c ontents.h"
13 #include "components/offline_pages/core/background/offliner.h" 13 #include "components/offline_pages/core/background/offliner.h"
14 #include "components/offline_pages/core/offline_page_types.h" 14 #include "components/offline_pages/core/offline_page_types.h"
15 #include "components/offline_pages/core/snapshot_controller.h"
16 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
17 16
18 namespace content { 17 namespace content {
19 class BrowserContext; 18 class BrowserContext;
20 } // namespace content 19 } // namespace content
21 20
22 namespace offline_pages { 21 namespace offline_pages {
23 22
24 class OfflinerPolicy; 23 class OfflinerPolicy;
25 class OfflinePageModel; 24 class OfflinePageModel;
26 25
27 // An Offliner implementation that attempts client-side rendering and saving 26 // An Offliner implementation that attempts client-side rendering and saving
28 // 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
29 // 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.
30 class BackgroundLoaderOffliner : public Offliner, 29 class BackgroundLoaderOffliner : public Offliner,
31 public content::WebContentsObserver, 30 public content::WebContentsObserver {
32 public SnapshotController::Client {
33 public: 31 public:
34 BackgroundLoaderOffliner(content::BrowserContext* browser_context, 32 BackgroundLoaderOffliner(content::BrowserContext* browser_context,
35 const OfflinerPolicy* policy, 33 const OfflinerPolicy* policy,
36 OfflinePageModel* offline_page_model); 34 OfflinePageModel* offline_page_model);
37 ~BackgroundLoaderOffliner() override; 35 ~BackgroundLoaderOffliner() override;
38 36
39 static BackgroundLoaderOffliner* FromWebContents( 37 static BackgroundLoaderOffliner* FromWebContents(
40 content::WebContents* contents); 38 content::WebContents* contents);
41 39
42 // Offliner implementation. 40 // Offliner implementation.
43 bool LoadAndSave(const SavePageRequest& request, 41 bool LoadAndSave(const SavePageRequest& request,
44 const CompletionCallback& completion_callback, 42 const CompletionCallback& completion_callback,
45 const ProgressCallback& progress_callback) override; 43 const ProgressCallback& progress_callback) override;
46 void Cancel(const CancelCallback& callback) override; 44 void Cancel(const CancelCallback& callback) override;
47 bool HandleTimeout(const SavePageRequest& request) override; 45 bool HandleTimeout(const SavePageRequest& request) override;
48 46
49 // WebContentsObserver implementation. 47 // WebContentsObserver implementation.
50 void DocumentLoadedInFrame(content::RenderFrameHost* render_frame) override;
51 void DidStopLoading() override; 48 void DidStopLoading() override;
52 void RenderProcessGone(base::TerminationStatus status) override; 49 void RenderProcessGone(base::TerminationStatus status) override;
53 void WebContentsDestroyed() override; 50 void WebContentsDestroyed() override;
54 void DidFinishNavigation( 51 void DidFinishNavigation(
55 content::NavigationHandle* navigation_handle) override; 52 content::NavigationHandle* navigation_handle) override;
56 53
57 // SnapshotController::Client implementation.
58 void StartSnapshot() override;
59
60 void SetPageDelayForTest(long delay_ms); 54 void SetPageDelayForTest(long delay_ms);
61 void OnNetworkBytesChanged(int64_t bytes); 55 void OnNetworkBytesChanged(int64_t bytes);
62 56
63 protected: 57 protected:
64 // Called to reset internal loader and observer state. 58 // Called to reset internal loader and observer state.
65 virtual void ResetState(); 59 virtual void ResetState();
66 60
67 private: 61 private:
68 friend class TestBackgroundLoaderOffliner; 62 friend class TestBackgroundLoaderOffliner;
69 63
70 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; 64 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE };
71 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY }; 65 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY };
72 66
67 // Called when the page is ready to be saved.
68 void SavePage();
69
73 // Called when the page has been saved. 70 // Called when the page has been saved.
74 void OnPageSaved(SavePageResult save_result, int64_t offline_id); 71 void OnPageSaved(SavePageResult save_result, int64_t offline_id);
75 72
76 // Called when application state has changed. 73 // Called when application state has changed.
77 void OnApplicationStateChange( 74 void OnApplicationStateChange(
78 base::android::ApplicationState application_state); 75 base::android::ApplicationState application_state);
79 void HandleApplicationStateChangeCancel(const SavePageRequest& request, 76 void HandleApplicationStateChangeCancel(const SavePageRequest& request,
80 int64_t offline_id); 77 int64_t offline_id);
81 78
82 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; 79 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_;
83 // Not owned. 80 // Not owned.
84 content::BrowserContext* browser_context_; 81 content::BrowserContext* browser_context_;
85 // Not owned. 82 // Not owned.
86 OfflinePageModel* offline_page_model_; 83 OfflinePageModel* offline_page_model_;
87 // Tracks pending request, if any. 84 // Tracks pending request, if any.
88 std::unique_ptr<SavePageRequest> pending_request_; 85 std::unique_ptr<SavePageRequest> pending_request_;
89 // Handles determining when a page should be snapshotted.
90 std::unique_ptr<SnapshotController> snapshot_controller_;
91 // Callback when pending request completes. 86 // Callback when pending request completes.
92 CompletionCallback completion_callback_; 87 CompletionCallback completion_callback_;
93 // Callback to report progress. 88 // Callback to report progress.
94 ProgressCallback progress_callback_; 89 ProgressCallback progress_callback_;
95 // ApplicationStatusListener to monitor if Chrome moves to the foreground. 90 // ApplicationStatusListener to monitor if Chrome moves to the foreground.
96 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; 91 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
97 // Whether we are on a low-end device. 92 // Whether we are on a low-end device.
98 bool is_low_end_device_; 93 bool is_low_end_device_;
99 94
100 // Save state. 95 // Save state.
101 SaveState save_state_; 96 SaveState save_state_;
102 // Page load state. 97 // Page load state.
103 PageLoadState page_load_state_; 98 PageLoadState page_load_state_;
104 // Seconds to delay before taking snapshot. 99 // Seconds to delay before taking snapshot.
105 long page_delay_ms_; 100 long page_delay_ms_;
106 // Network bytes loaded. 101 // Network bytes loaded.
107 int64_t network_bytes_; 102 int64_t network_bytes_;
108 103
109 // Callback for cancel. 104 // Callback for cancel.
110 CancelCallback cancel_callback_; 105 CancelCallback cancel_callback_;
111 106
112 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; 107 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_;
113 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); 108 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner);
114 }; 109 };
115 110
116 } // namespace offline_pages 111 } // namespace offline_pages
117 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ 112 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/background_loader_offliner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698