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

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

Issue 2769043002: [Offline pages] Integrate snapshot controller fully into background loader. (Closed)
Patch Set: added comment and reset 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"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 17
17 namespace content { 18 namespace content {
18 class BrowserContext; 19 class BrowserContext;
19 } // namespace content 20 } // namespace content
20 21
21 namespace offline_pages { 22 namespace offline_pages {
22 23
23 class OfflinerPolicy; 24 class OfflinerPolicy;
24 class OfflinePageModel; 25 class OfflinePageModel;
25 26
26 // An Offliner implementation that attempts client-side rendering and saving 27 // An Offliner implementation that attempts client-side rendering and saving
27 // of an offline page. It uses the BackgroundLoader to load the page and the 28 // of an offline page. It uses the BackgroundLoader to load the page and the
28 // OfflinePageModel to save it. Only one request may be active at a time. 29 // OfflinePageModel to save it. Only one request may be active at a time.
29 class BackgroundLoaderOffliner : public Offliner, 30 class BackgroundLoaderOffliner : public Offliner,
30 public content::WebContentsObserver { 31 public content::WebContentsObserver,
32 public SnapshotController::Client {
31 public: 33 public:
32 BackgroundLoaderOffliner(content::BrowserContext* browser_context, 34 BackgroundLoaderOffliner(content::BrowserContext* browser_context,
33 const OfflinerPolicy* policy, 35 const OfflinerPolicy* policy,
34 OfflinePageModel* offline_page_model); 36 OfflinePageModel* offline_page_model);
35 ~BackgroundLoaderOffliner() override; 37 ~BackgroundLoaderOffliner() override;
36 38
37 static BackgroundLoaderOffliner* FromWebContents( 39 static BackgroundLoaderOffliner* FromWebContents(
38 content::WebContents* contents); 40 content::WebContents* contents);
39 41
40 // Offliner implementation. 42 // Offliner implementation.
41 bool LoadAndSave(const SavePageRequest& request, 43 bool LoadAndSave(const SavePageRequest& request,
42 const CompletionCallback& completion_callback, 44 const CompletionCallback& completion_callback,
43 const ProgressCallback& progress_callback) override; 45 const ProgressCallback& progress_callback) override;
44 void Cancel(const CancelCallback& callback) override; 46 void Cancel(const CancelCallback& callback) override;
45 bool HandleTimeout(const SavePageRequest& request) override; 47 bool HandleTimeout(const SavePageRequest& request) override;
46 48
47 // WebContentsObserver implementation. 49 // WebContentsObserver implementation.
50 void DocumentLoadedInFrame(content::RenderFrameHost* render_frame) override;
48 void DidStopLoading() override; 51 void DidStopLoading() override;
49 void RenderProcessGone(base::TerminationStatus status) override; 52 void RenderProcessGone(base::TerminationStatus status) override;
50 void WebContentsDestroyed() override; 53 void WebContentsDestroyed() override;
51 void DidFinishNavigation( 54 void DidFinishNavigation(
52 content::NavigationHandle* navigation_handle) override; 55 content::NavigationHandle* navigation_handle) override;
53 56
57 // SnapshotController::Client implementation.
58 void StartSnapshot() override;
59
54 void SetPageDelayForTest(long delay_ms); 60 void SetPageDelayForTest(long delay_ms);
55 void OnNetworkBytesChanged(int64_t bytes); 61 void OnNetworkBytesChanged(int64_t bytes);
56 62
57 protected: 63 protected:
58 // Called to reset internal loader and observer state. 64 // Called to reset internal loader and observer state.
59 virtual void ResetState(); 65 virtual void ResetState();
60 66
61 private: 67 private:
62 friend class TestBackgroundLoaderOffliner; 68 friend class TestBackgroundLoaderOffliner;
63 69
64 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE }; 70 enum SaveState { NONE, SAVING, DELETE_AFTER_SAVE };
65 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY }; 71 enum PageLoadState { SUCCESS, RETRIABLE, NONRETRIABLE, DELAY_RETRY };
66 72
67 // Called when the page is ready to be saved.
68 void SavePage();
69
70 // Called when the page has been saved. 73 // Called when the page has been saved.
71 void OnPageSaved(SavePageResult save_result, int64_t offline_id); 74 void OnPageSaved(SavePageResult save_result, int64_t offline_id);
72 75
73 // Called when application state has changed. 76 // Called when application state has changed.
74 void OnApplicationStateChange( 77 void OnApplicationStateChange(
75 base::android::ApplicationState application_state); 78 base::android::ApplicationState application_state);
76 void HandleApplicationStateChangeCancel(const SavePageRequest& request, 79 void HandleApplicationStateChangeCancel(const SavePageRequest& request,
77 int64_t offline_id); 80 int64_t offline_id);
78 81
79 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_; 82 std::unique_ptr<background_loader::BackgroundLoaderContents> loader_;
80 // Not owned. 83 // Not owned.
81 content::BrowserContext* browser_context_; 84 content::BrowserContext* browser_context_;
82 // Not owned. 85 // Not owned.
83 OfflinePageModel* offline_page_model_; 86 OfflinePageModel* offline_page_model_;
84 // Tracks pending request, if any. 87 // Tracks pending request, if any.
85 std::unique_ptr<SavePageRequest> pending_request_; 88 std::unique_ptr<SavePageRequest> pending_request_;
89 // Handles determining when a page should be snapshotted.
90 std::unique_ptr<SnapshotController> snapshot_controller_;
86 // Callback when pending request completes. 91 // Callback when pending request completes.
87 CompletionCallback completion_callback_; 92 CompletionCallback completion_callback_;
88 // Callback to report progress. 93 // Callback to report progress.
89 ProgressCallback progress_callback_; 94 ProgressCallback progress_callback_;
90 // ApplicationStatusListener to monitor if Chrome moves to the foreground. 95 // ApplicationStatusListener to monitor if Chrome moves to the foreground.
91 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; 96 std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
92 // Whether we are on a low-end device. 97 // Whether we are on a low-end device.
93 bool is_low_end_device_; 98 bool is_low_end_device_;
94 99
95 // Save state. 100 // Save state.
96 SaveState save_state_; 101 SaveState save_state_;
97 // Page load state. 102 // Page load state.
98 PageLoadState page_load_state_; 103 PageLoadState page_load_state_;
99 // Seconds to delay before taking snapshot. 104 // Seconds to delay before taking snapshot.
100 long page_delay_ms_; 105 long page_delay_ms_;
101 // Network bytes loaded. 106 // Network bytes loaded.
102 int64_t network_bytes_; 107 int64_t network_bytes_;
103 108
104 // Callback for cancel. 109 // Callback for cancel.
105 CancelCallback cancel_callback_; 110 CancelCallback cancel_callback_;
106 111
107 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_; 112 base::WeakPtrFactory<BackgroundLoaderOffliner> weak_ptr_factory_;
108 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner); 113 DISALLOW_COPY_AND_ASSIGN(BackgroundLoaderOffliner);
109 }; 114 };
110 115
111 } // namespace offline_pages 116 } // namespace offline_pages
112 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_BACKGROUND_LOADER_OFFLINER_H_ 117 #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