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

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

Issue 2420503002: [Offline Pages] Define separate watchdog timeout for concurrent bg loads (Closed)
Patch Set: Merge Created 4 years, 2 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 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 #include <set> 9 #include <set>
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return is_busy_; 171 return is_busy_;
172 } 172 }
173 173
174 // Returns whether processing is starting (before it is decided to actually 174 // Returns whether processing is starting (before it is decided to actually
175 // process a request (is_busy()) at this time or not. 175 // process a request (is_busy()) at this time or not.
176 bool is_starting() { return is_starting_; } 176 bool is_starting() { return is_starting_; }
177 177
178 // Tracks whether the last offlining attempt got canceled. This is reset by 178 // Tracks whether the last offlining attempt got canceled. This is reset by
179 // the next StartProcessing() call. 179 // the next StartProcessing() call.
180 bool is_canceled() { 180 bool is_canceled() {
181 return is_stopped_; 181 return processing_state_ == ProcessingWindowState::STOPPED;
182 } 182 }
183 183
184 OfflineEventLogger* GetLogger() { 184 OfflineEventLogger* GetLogger() {
185 return &event_logger_; 185 return &event_logger_;
186 } 186 }
187 187
188 private: 188 private:
189 // Immediate start attempt status code for UMA. 189 // Immediate start attempt status code for UMA.
190 // These values are written to logs. New enum values can be added, but 190 // These values are written to logs. New enum values can be added, but
191 // existing enums must never be renumbered or deleted and reused. 191 // existing enums must never be renumbered or deleted and reused.
192 // For any additions, also update corresponding histogram in histograms.xml. 192 // For any additions, also update corresponding histogram in histograms.xml.
193 enum OfflinerImmediateStartStatus { 193 enum OfflinerImmediateStartStatus {
194 // Did start processing request. 194 // Did start processing request.
195 STARTED = 0, 195 STARTED = 0,
196 // Already busy processing a request. 196 // Already busy processing a request.
197 BUSY = 1, 197 BUSY = 1,
198 // The Offliner did not accept processing the request. 198 // The Offliner did not accept processing the request.
199 NOT_ACCEPTED = 2, 199 NOT_ACCEPTED = 2,
200 // No current network connection. 200 // No current network connection.
201 NO_CONNECTION = 3, 201 NO_CONNECTION = 3,
202 // Weak network connection (worse than 2G speed) 202 // Weak network connection (worse than 2G speed)
203 // according to network quality estimator. 203 // according to network quality estimator.
204 WEAK_CONNECTION = 4, 204 WEAK_CONNECTION = 4,
205 // Did not start because this is svelte device. 205 // Did not start because this is svelte device.
206 NOT_STARTED_ON_SVELTE = 5, 206 NOT_STARTED_ON_SVELTE = 5,
207 // NOTE: insert new values above this line and update histogram enum too. 207 // NOTE: insert new values above this line and update histogram enum too.
208 STATUS_COUNT = 6, 208 STATUS_COUNT = 6,
209 }; 209 };
210 210
211 enum class ProcessingWindowState {
212 STOPPED,
213 SCHEDULED_WINDOW,
214 IMMEDIATE_WINDOW,
215 };
216
211 // Receives the results of a get from the request queue, and turns that into 217 // Receives the results of a get from the request queue, and turns that into
212 // SavePageRequest objects for the caller of GetQueuedRequests. 218 // SavePageRequest objects for the caller of GetQueuedRequests.
213 void GetQueuedRequestsCallback( 219 void GetQueuedRequestsCallback(
214 const GetRequestsCallback& callback, 220 const GetRequestsCallback& callback,
215 RequestQueue::GetRequestsResult result, 221 RequestQueue::GetRequestsResult result,
216 std::vector<std::unique_ptr<SavePageRequest>> requests); 222 std::vector<std::unique_ptr<SavePageRequest>> requests);
217 223
218 // Receives the results of a get from the request queue, and turns that into 224 // Receives the results of a get from the request queue, and turns that into
219 // SavePageRequest objects for the caller of GetQueuedRequests. 225 // SavePageRequest objects for the caller of GetQueuedRequests.
220 void GetRequestsForSchedulingCallback( 226 void GetRequestsForSchedulingCallback(
(...skipping 14 matching lines...) Expand all
235 void CompletedRequestCallback(const MultipleItemStatuses& status); 241 void CompletedRequestCallback(const MultipleItemStatuses& status);
236 242
237 void HandleRemovedRequestsAndCallback( 243 void HandleRemovedRequestsAndCallback(
238 const RemoveRequestsCallback& callback, 244 const RemoveRequestsCallback& callback,
239 BackgroundSavePageResult status, 245 BackgroundSavePageResult status,
240 std::unique_ptr<UpdateRequestsResult> result); 246 std::unique_ptr<UpdateRequestsResult> result);
241 247
242 void HandleRemovedRequests(BackgroundSavePageResult status, 248 void HandleRemovedRequests(BackgroundSavePageResult status,
243 std::unique_ptr<UpdateRequestsResult> result); 249 std::unique_ptr<UpdateRequestsResult> result);
244 250
251 bool StartProcessingInternal(const ProcessingWindowState processing_state,
252 const DeviceConditions& device_conditions,
253 const base::Callback<void(bool)>& callback);
254
245 // Start processing now if connected (but with conservative assumption 255 // Start processing now if connected (but with conservative assumption
246 // as to other device conditions). 256 // as to other device conditions).
247 void StartProcessingIfConnected(); 257 void StartImmediatelyIfConnected();
248 258
249 OfflinerImmediateStartStatus TryImmediateStart(); 259 OfflinerImmediateStartStatus TryImmediateStart();
250 260
251 // Check the request queue, and schedule a task corresponding 261 // Check the request queue, and schedule a task corresponding
252 // to the least restrictive type of request in the queue. 262 // to the least restrictive type of request in the queue.
253 void ScheduleAsNeeded(); 263 void ScheduleAsNeeded();
254 264
255 // Callback from the request picker when it has chosen our next request. 265 // Callback from the request picker when it has chosen our next request.
256 void RequestPicked(const SavePageRequest& request); 266 void RequestPicked(const SavePageRequest& request);
257 267
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 323
314 friend class RequestCoordinatorTest; 324 friend class RequestCoordinatorTest;
315 325
316 // The offliner can only handle one request at a time - if the offliner is 326 // The offliner can only handle one request at a time - if the offliner is
317 // busy, prevent other requests. This flag marks whether the offliner is in 327 // busy, prevent other requests. This flag marks whether the offliner is in
318 // use. 328 // use.
319 bool is_busy_; 329 bool is_busy_;
320 // There is more than one path to start processing so this flag is used 330 // There is more than one path to start processing so this flag is used
321 // to avoid race conditions before is_busy_ is established. 331 // to avoid race conditions before is_busy_ is established.
322 bool is_starting_; 332 bool is_starting_;
323 // True if the current processing window has been canceled. 333 // Identifies the type of current processing window or if processing stopped.
324 bool is_stopped_; 334 ProcessingWindowState processing_state_;
Pete Williamson 2016/10/13 22:58:18 Good change, I like this a lot better.
dougarnett 2016/10/14 16:27:01 Done.
325 // True if we should use the test connection type instead of the actual type. 335 // True if we should use the test connection type instead of the actual type.
326 bool use_test_connection_type_; 336 bool use_test_connection_type_;
327 // For use by tests, a fake network connection type 337 // For use by tests, a fake network connection type
328 net::NetworkChangeNotifier::ConnectionType test_connection_type_; 338 net::NetworkChangeNotifier::ConnectionType test_connection_type_;
329 // Unowned pointer to the current offliner, if any. 339 // Unowned pointer to the current offliner, if any.
330 Offliner* offliner_; 340 Offliner* offliner_;
331 base::Time operation_start_time_; 341 base::Time operation_start_time_;
332 // The observers. 342 // The observers.
333 base::ObserverList<Observer> observers_; 343 base::ObserverList<Observer> observers_;
334 // Last known conditions for network, battery 344 // Last known conditions for network, battery
(...skipping 30 matching lines...) Expand all
365 base::TimeDelta offliner_timeout_; 375 base::TimeDelta offliner_timeout_;
366 // Allows us to pass a weak pointer to callbacks. 376 // Allows us to pass a weak pointer to callbacks.
367 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 377 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
368 378
369 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 379 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
370 }; 380 };
371 381
372 } // namespace offline_pages 382 } // namespace offline_pages
373 383
374 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 384 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698