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

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

Issue 2655673005: RecentTabHelper won't accept overlapping requests from Downloads anymore. (Closed)
Patch Set: Minor changes from addressing dewittj@ comments. Created 3 years, 10 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/recent_tab_helper.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_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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 public: 50 public:
51 virtual ~Delegate() {} 51 virtual ~Delegate() {}
52 virtual std::unique_ptr<OfflinePageArchiver> CreatePageArchiver( 52 virtual std::unique_ptr<OfflinePageArchiver> CreatePageArchiver(
53 content::WebContents* web_contents) = 0; 53 content::WebContents* web_contents) = 0;
54 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; 54 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0;
55 // There is no expectations that tab_id is always present. 55 // There is no expectations that tab_id is always present.
56 virtual bool GetTabId(content::WebContents* web_contents, int* tab_id) = 0; 56 virtual bool GetTabId(content::WebContents* web_contents, int* tab_id) = 0;
57 }; 57 };
58 void SetDelegate(std::unique_ptr<RecentTabHelper::Delegate> delegate); 58 void SetDelegate(std::unique_ptr<RecentTabHelper::Delegate> delegate);
59 59
60 // Support for Download Page feature. The Download Page button does this: 60 // Creates a request to download the current page with a properly filled
61 // 1. Creates suspended request for Background Offliner. 61 // |client_id| and valid |request_id| issued by RequestCoordinator from a
62 // 2. Calls this method with properly filled ClientId. 62 // suspended request. This method might be called multiple times for the same
63 // 3. This tab helper observes the page load and captures the page 63 // page at any point after its navigation commits. There are some important
64 // if the load progresses far enough, as indicated by SnapshotController. 64 // points about how requests are handled:
65 // 4. If capture is successful, this tab helper removes the suspended request. 65 // a) While there is an ongoing request, new requests are ignored (no
66 // Otherwise (navigation to other page, close tab) tab helper un-suspends 66 // overlapping snapshots).
67 // the request so the Background Offliner starts working on it. 67 // b) The page has to be sufficiently loaded to be considerer of minimum
68 // 5. If Chrome is killed at any point, next time Background Offliner loads 68 // quality for the request to be started immediately.
69 // it converts all suspended requests from last session into active. 69 // c) Any calls made before the page is considered to have minimal quality
70 // will be scheduled to be executed once that happens. The scheduled
71 // request is considered "ongoing" for a) purposes.
72 // d) If the save operation is successful the dormant request with
73 // RequestCoordinator is canceled; otherwise it is resumed. This logic is
74 // robust to crashes.
75 // e) At the moment the page reaches high quality, if there was a successful
76 // snapshot saved at a lower quality then a new snapshot is automatically
77 // requested to replace it.
78 // Note #1: Page quality is determined by SnapshotController and is based on
79 // its assessment of "how much loaded" it is.
80 // Note #2: Currently this method only accepts download requests from the
81 // downloads namespace.
70 void ObserveAndDownloadCurrentPage(const ClientId& client_id, 82 void ObserveAndDownloadCurrentPage(const ClientId& client_id,
71 int64_t request_id); 83 int64_t request_id);
72 84
73 private: 85 private:
74 // Keeps client_id/request_id that will be used for the offline snapshot. 86 struct SnapshotProgressInfo;
75 struct SnapshotProgressInfo {
76 public:
77 // For a downloads snapshot request, where the |request_id| is defined.
78 SnapshotProgressInfo(const ClientId& client_id, int64_t request_id)
79 : client_id(client_id), request_id(request_id) {}
80
81 // For a last_n snapshot request.
82 explicit SnapshotProgressInfo(const ClientId& client_id)
83 : client_id(client_id) {}
84
85 bool IsForLastN();
86
87 // The ClientID to go with the offline page.
88 ClientId client_id;
89
90 // Id of the suspended request in Background Offliner. Used to un-suspend
91 // the request if the capture of the current page was not possible (e.g.
92 // the user navigated to another page before current one was loaded).
93 // 0 if this is a "last_n" info.
94 int64_t request_id = OfflinePageModel::kInvalidOfflineId;
95
96 // True if there was at least one snapshot successfully completed.
97 bool page_snapshot_completed = false;
98
99 // Expected snapshot quality should the saving succeed. This value is only
100 // valid if |page_snapshot_completed| is true.
101 SnapshotController::PageQuality expected_page_quality =
102 SnapshotController::PageQuality::POOR;
103 };
104 87
105 explicit RecentTabHelper(content::WebContents* web_contents); 88 explicit RecentTabHelper(content::WebContents* web_contents);
106 friend class content::WebContentsUserData<RecentTabHelper>; 89 friend class content::WebContentsUserData<RecentTabHelper>;
107 90
108 bool EnsureInitialized(); 91 bool EnsureInitialized();
109 void ContinueSnapshotWithIdsToPurge(SnapshotProgressInfo* snapshot_info, 92 void ContinueSnapshotWithIdsToPurge(SnapshotProgressInfo* snapshot_info,
110 const std::vector<int64_t>& page_ids); 93 const std::vector<int64_t>& page_ids);
111 void ContinueSnapshotAfterPurge(SnapshotProgressInfo* snapshot_info, 94 void ContinueSnapshotAfterPurge(SnapshotProgressInfo* snapshot_info,
112 OfflinePageModel::DeletePageResult result); 95 OfflinePageModel::DeletePageResult result);
113 void SavePageCallback(SnapshotProgressInfo* snapshot_info, 96 void SavePageCallback(SnapshotProgressInfo* snapshot_info,
114 OfflinePageModel::SavePageResult result, 97 OfflinePageModel::SavePageResult result,
115 int64_t offline_id); 98 int64_t offline_id);
116 void ReportSnapshotCompleted(SnapshotProgressInfo* snapshot_info); 99 void ReportSnapshotCompleted(SnapshotProgressInfo* snapshot_info,
100 bool success);
117 void ReportDownloadStatusToRequestCoordinator( 101 void ReportDownloadStatusToRequestCoordinator(
118 SnapshotProgressInfo* snapshot_info); 102 SnapshotProgressInfo* snapshot_info,
103 bool cancel_background_request);
119 ClientId GetRecentPagesClientId() const; 104 ClientId GetRecentPagesClientId() const;
120 void SaveSnapshotForDownloads(); 105 void SaveSnapshotForDownloads(bool replace_latest);
106 void CancelInFlightSnapshots();
121 107
122 // Page model is a service, no ownership. Can be null - for example, in 108 // Page model is a service, no ownership. Can be null - for example, in
123 // case when tab is in incognito profile. 109 // case when tab is in incognito profile.
124 OfflinePageModel* page_model_ = nullptr; 110 OfflinePageModel* page_model_ = nullptr;
125 111
126 // If false, never make snapshots off the attached WebContents. 112 // If false, never make snapshots off the attached WebContents.
127 // Not page-specific. 113 // Not page-specific.
128 bool snapshots_enabled_ = false; 114 bool snapshots_enabled_ = false;
129 115
130 // Snapshot progress information for a downloads triggered request. Null if 116 // Snapshot progress information for an ongoing snapshot requested by
131 // downloads is not capturing or hasn't captured the current page. 117 // downloads. Null if there's no ongoing request.
132 std::unique_ptr<SnapshotProgressInfo> downloads_latest_snapshot_info_; 118 std::unique_ptr<SnapshotProgressInfo> downloads_ongoing_snapshot_info_;
119
120 // This is set to true if the ongoing snapshot for downloads is waiting on the
121 // page to reach a minimal quality level to start.
122 bool downloads_snapshot_on_hold_ = false;
123
124 // Snapshot information for the last successful snapshot requested by
125 // downloads. Null if no successful one has ever completed.
126 std::unique_ptr<SnapshotProgressInfo> downloads_latest_saved_snapshot_info_;
133 127
134 // Snapshot progress information for a last_n triggered request. Null if 128 // Snapshot progress information for a last_n triggered request. Null if
135 // last_n is not currently capturing the current page. 129 // last_n is not currently capturing the current page.
136 std::unique_ptr<SnapshotProgressInfo> last_n_ongoing_snapshot_info_; 130 std::unique_ptr<SnapshotProgressInfo> last_n_ongoing_snapshot_info_;
137 131
138 // If empty, the tab does not have AndroidId and can not capture pages. 132 // If empty, the tab does not have AndroidId and can not capture pages.
139 std::string tab_id_; 133 std::string tab_id_;
140 134
141 // The URL of the page that is currently being snapshotted. Used to check, 135 // The URL of the page that is currently being snapshotted. Used to check,
142 // during async operations, that WebContents still contains the same page. 136 // during async operations, that WebContents still contains the same page.
(...skipping 16 matching lines...) Expand all
159 SnapshotController::PageQuality::POOR; 153 SnapshotController::PageQuality::POOR;
160 154
161 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_; 155 base::WeakPtrFactory<RecentTabHelper> weak_ptr_factory_;
162 156
163 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper); 157 DISALLOW_COPY_AND_ASSIGN(RecentTabHelper);
164 }; 158 };
165 159
166 } // namespace offline_pages 160 } // namespace offline_pages
167 161
168 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_ 162 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_RECENT_TAB_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/recent_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698