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

Side by Side Diff: components/offline_pages/background/request_coordinator.h

Issue 2266323002: Cancel prerendering when a request is paused or removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename flag Created 4 years, 3 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 | components/offline_pages/background/request_coordinator.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 COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return last_offlining_status_; 131 return last_offlining_status_;
132 } 132 }
133 133
134 bool is_busy() { 134 bool is_busy() {
135 return is_busy_; 135 return is_busy_;
136 } 136 }
137 137
138 // Tracks whether the last offlining attempt got canceled. This is reset by 138 // Tracks whether the last offlining attempt got canceled. This is reset by
139 // the next StartProcessing() call. 139 // the next StartProcessing() call.
140 bool is_canceled() { 140 bool is_canceled() {
141 return is_canceled_; 141 return is_stopped_;
142 } 142 }
143 143
144 OfflineEventLogger* GetLogger() { 144 OfflineEventLogger* GetLogger() {
145 return &event_logger_; 145 return &event_logger_;
146 } 146 }
147 147
148 private: 148 private:
149 // Receives the results of a get from the request queue, and turns that into 149 // Receives the results of a get from the request queue, and turns that into
150 // SavePageRequest objects for the caller of GetQueuedRequests. 150 // SavePageRequest objects for the caller of GetQueuedRequests.
151 void GetQueuedRequestsCallback(const GetRequestsCallback& callback, 151 void GetQueuedRequestsCallback(const GetRequestsCallback& callback,
(...skipping 15 matching lines...) Expand all
167 void RemoveRequestsCallback( 167 void RemoveRequestsCallback(
168 const RequestQueue::UpdateMultipleRequestResults& results, 168 const RequestQueue::UpdateMultipleRequestResults& results,
169 const std::vector<SavePageRequest>& requests); 169 const std::vector<SavePageRequest>& requests);
170 170
171 // Callback from the request picker when it has chosen our next request. 171 // Callback from the request picker when it has chosen our next request.
172 void RequestPicked(const SavePageRequest& request); 172 void RequestPicked(const SavePageRequest& request);
173 173
174 // Callback from the request picker when no more requests are in the queue. 174 // Callback from the request picker when no more requests are in the queue.
175 void RequestQueueEmpty(); 175 void RequestQueueEmpty();
176 176
177 // Cancels an in progress pre-rendering, and updates state appropriately.
178 void StopPrerendering();
179
177 void SendRequestToOffliner(const SavePageRequest& request); 180 void SendRequestToOffliner(const SavePageRequest& request);
178 181
179 // Called by the offliner when an offlining request is completed. (and by 182 // Called by the offliner when an offlining request is completed. (and by
180 // tests). 183 // tests).
181 void OfflinerDoneCallback(const SavePageRequest& request, 184 void OfflinerDoneCallback(const SavePageRequest& request,
182 Offliner::RequestStatus status); 185 Offliner::RequestStatus status);
183 186
184 void TryNextRequest(); 187 void TryNextRequest();
185 188
189 // If there is an active request in the list, cancel that request.
190 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids);
191
186 // Returns the appropriate offliner to use, getting a new one from the factory 192 // Returns the appropriate offliner to use, getting a new one from the factory
187 // if needed. 193 // if needed.
188 void GetOffliner(); 194 void GetOffliner();
189 195
190 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { 196 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) {
191 offliner_timeout_ = timeout; 197 offliner_timeout_ = timeout;
192 } 198 }
193 199
194 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { 200 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) {
195 current_conditions_.reset(new DeviceConditions(current_conditions)); 201 current_conditions_.reset(new DeviceConditions(current_conditions));
196 } 202 }
197 203
198 friend class RequestCoordinatorTest; 204 friend class RequestCoordinatorTest;
199 205
200 // The offliner can only handle one request at a time - if the offliner is 206 // The offliner can only handle one request at a time - if the offliner is
201 // busy, prevent other requests. This flag marks whether the offliner is in 207 // busy, prevent other requests. This flag marks whether the offliner is in
202 // use. 208 // use.
203 bool is_busy_; 209 bool is_busy_;
204 // True if the current request has been canceled. 210 // True if the current request has been canceled.
205 bool is_canceled_; 211 bool is_stopped_;
206 // Unowned pointer to the current offliner, if any. 212 // Unowned pointer to the current offliner, if any.
207 Offliner* offliner_; 213 Offliner* offliner_;
208 base::Time operation_start_time_; 214 base::Time operation_start_time_;
209 // The observers. 215 // The observers.
210 base::ObserverList<Observer> observers_; 216 base::ObserverList<Observer> observers_;
211 // Last known conditions for network, battery 217 // Last known conditions for network, battery
212 std::unique_ptr<DeviceConditions> current_conditions_; 218 std::unique_ptr<DeviceConditions> current_conditions_;
213 // RequestCoordinator takes over ownership of the policy 219 // RequestCoordinator takes over ownership of the policy
214 std::unique_ptr<OfflinerPolicy> policy_; 220 std::unique_ptr<OfflinerPolicy> policy_;
215 // OfflinerFactory. Used to create offline pages. Owned. 221 // OfflinerFactory. Used to create offline pages. Owned.
(...skipping 18 matching lines...) Expand all
234 base::TimeDelta offliner_timeout_; 240 base::TimeDelta offliner_timeout_;
235 // Allows us to pass a weak pointer to callbacks. 241 // Allows us to pass a weak pointer to callbacks.
236 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 242 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
237 243
238 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 244 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
239 }; 245 };
240 246
241 } // namespace offline_pages 247 } // namespace offline_pages
242 248
243 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 249 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698