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

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

Issue 2602473004: Offline Page Cache uses user interaction triggers for saving pages. (Closed)
Patch Set: Rebased and added the other missing histogram.xml entry... Created 3 years, 11 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
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_RECENT_TAB_HELPER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "components/offline_pages/core/downloads/download_ui_item.h" 12 #include "components/offline_pages/core/downloads/download_ui_item.h"
13 #include "components/offline_pages/core/offline_page_model.h" 13 #include "components/offline_pages/core/offline_page_model.h"
14 #include "components/offline_pages/core/snapshot_controller.h" 14 #include "components/offline_pages/core/snapshot_controller.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h" 16 #include "content/public/browser/web_contents_user_data.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace content { 19 namespace content {
20 class NavigationHandle; 20 class NavigationHandle;
21 } 21 }
22 22
23 namespace offline_pages { 23 namespace offline_pages {
24 24
25 using PageQuality = SnapshotController::PageQuality;
26
25 // Attaches to every WebContent shown in a tab. Waits until the WebContent is 27 // Attaches to every WebContent shown in a tab. Waits until the WebContent is
26 // loaded to proper degree and then makes a snapshot of the page. Removes the 28 // loaded to proper degree and then makes a snapshot of the page. Removes the
27 // oldest snapshot in the 'ring buffer'. As a result, there is always up to N 29 // oldest snapshot in the 'ring buffer'. As a result, there is always up to N
28 // snapshots of recent pages on the device. 30 // snapshots of recent pages on the device.
29 class RecentTabHelper 31 class RecentTabHelper
30 : public content::WebContentsObserver, 32 : public content::WebContentsObserver,
31 public content::WebContentsUserData<RecentTabHelper>, 33 public content::WebContentsUserData<RecentTabHelper>,
32 public SnapshotController::Client { 34 public SnapshotController::Client {
33 public: 35 public:
34 ~RecentTabHelper() override; 36 ~RecentTabHelper() override;
35 37
36 // content::WebContentsObserver 38 // content::WebContentsObserver
37 void DidFinishNavigation( 39 void DidFinishNavigation(
38 content::NavigationHandle* navigation_handle) override; 40 content::NavigationHandle* navigation_handle) override;
39 void DocumentAvailableInMainFrame() override; 41 void DocumentAvailableInMainFrame() override;
40 void DocumentOnLoadCompletedInMainFrame() override; 42 void DocumentOnLoadCompletedInMainFrame() override;
41 void WebContentsDestroyed() override; 43 void WebContentsDestroyed() override;
44 void WasHidden() override;
42 45
43 // SnapshotController::Client 46 // SnapshotController::Client
44 void StartSnapshot() override; 47 void StartSnapshot() override;
45 48
46 // Delegate that is used by RecentTabHelper to get external dependencies. 49 // Delegate that is used by RecentTabHelper to get external dependencies.
47 // Default implementation lives in .cc file, while tests provide an override. 50 // Default implementation lives in .cc file, while tests provide an override.
48 class Delegate { 51 class Delegate {
49 public: 52 public:
50 virtual ~Delegate() {} 53 virtual ~Delegate() {}
51 virtual std::unique_ptr<OfflinePageArchiver> CreatePageArchiver( 54 virtual std::unique_ptr<OfflinePageArchiver> CreatePageArchiver(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 98
96 void EnsureInitialized(); 99 void EnsureInitialized();
97 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids); 100 void ContinueSnapshotWithIdsToPurge(const std::vector<int64_t>& page_ids);
98 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result); 101 void ContinueSnapshotAfterPurge(OfflinePageModel::DeletePageResult result);
99 void SavePageCallback(OfflinePageModel::SavePageResult result, 102 void SavePageCallback(OfflinePageModel::SavePageResult result,
100 int64_t offline_id); 103 int64_t offline_id);
101 void ReportSnapshotCompleted(); 104 void ReportSnapshotCompleted();
102 void ReportDownloadStatusToRequestCoordinator(); 105 void ReportDownloadStatusToRequestCoordinator();
103 bool IsSamePage() const; 106 bool IsSamePage() const;
104 ClientId GetRecentPagesClientId() const; 107 ClientId GetRecentPagesClientId() const;
108 void StartSnapshotInternal();
109 bool isSnapshottingForLastN() const;
105 110
106 // Page model is a service, no ownership. Can be null - for example, in 111 // Page model is a service, no ownership. Can be null - for example, in
107 // case when tab is in incognito profile. 112 // case when tab is in incognito profile.
108 OfflinePageModel* page_model_; 113 OfflinePageModel* page_model_ = nullptr;
109 114
110 // If false, never make snapshots off the attached WebContents. 115 // If false, never make snapshots off the attached WebContents.
111 // Not page-specific. 116 // Not page-specific.
112 bool snapshots_enabled_; 117 bool snapshots_enabled_ = false;
113 118
114 // Becomes true during navigation if the page is ready for snapshot as 119 // Becomes true during navigation if the page is ready for snapshot as
115 // indicated by at least one callback from SnapshotController. 120 // indicated by at least one callback from SnapshotController.
116 bool is_page_ready_for_snapshot_; 121 bool is_page_ready_for_snapshot_ = false;
117 122
118 // Info for the offline page to capture. Null if the tab is not capturing 123 // Info for the offline page to capture. Null if the tab is not capturing
119 // current page. 124 // current page.
120 std::unique_ptr<DownloadPageInfo> download_info_; 125 std::unique_ptr<DownloadPageInfo> download_info_;
121 126
122 // If empty, the tab does not have AndroidId and can not capture pages. 127 // If empty, the tab does not have AndroidId and can not capture pages.
123 std::string tab_id_; 128 std::string tab_id_;
124 129
125 // The URL of the page that is currently being snapshotted. Used to check, 130 // The URL of the page that is currently being snapshotted. Used to check,
126 // during async operations, that WebContents still contains the same page. 131 // during async operations, that WebContents still contains the same page.
127 GURL snapshot_url_; 132 GURL snapshot_url_;
128 // This starts out null and used as a flag for EnsureInitialized() to do the 133 // This starts out null and used as a flag for EnsureInitialized() to do the
129 // initialization only once. 134 // initialization only once.
130 std::unique_ptr<SnapshotController> snapshot_controller_; 135 std::unique_ptr<SnapshotController> snapshot_controller_;
131 136
132 std::unique_ptr<Delegate> delegate_; 137 std::unique_ptr<Delegate> delegate_;
133 138
139 // Per navigation state set if last_n should listed to the tab being hidden to
140 // save a snapshot. Only used if using user interaction events as triggers.
141 bool last_n_listen_to_tab_hidden_ = false;
142
143 // Members to track page quality status for a current save being executed and
144 // the last saved page. Only used if using user interaction events as
145 // triggers.
146 PageQuality last_n_saved_quality_ = PageQuality::POOR;
147 PageQuality page_quality_on_save_start_ = PageQuality::POOR;
148
134 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; 149 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_;
135 150
136 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); 151 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper);
137 }; 152 };
138 153
139 } // namespace offline_pages 154 } // namespace offline_pages
140 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ 155 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698