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

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

Issue 2347783003: [OfflinePages, NetworkQualityEstimator] Use NetworkQualityEstimator to decide on triggering Backgro… (Closed)
Patch Set: Addressed feedback 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
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/supports_user_data.h" 14 #include "base/supports_user_data.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
18 #include "components/offline_pages/background/device_conditions.h" 18 #include "components/offline_pages/background/device_conditions.h"
19 #include "components/offline_pages/background/offliner.h" 19 #include "components/offline_pages/background/offliner.h"
20 #include "components/offline_pages/background/request_coordinator_event_logger.h " 20 #include "components/offline_pages/background/request_coordinator_event_logger.h "
21 #include "components/offline_pages/background/request_notifier.h" 21 #include "components/offline_pages/background/request_notifier.h"
22 #include "components/offline_pages/background/request_queue.h" 22 #include "components/offline_pages/background/request_queue.h"
23 #include "components/offline_pages/background/scheduler.h" 23 #include "components/offline_pages/background/scheduler.h"
24 #include "net/nqe/network_quality_estimator.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 namespace offline_pages { 27 namespace offline_pages {
27 28
28 struct ClientId; 29 struct ClientId;
29 class OfflinerPolicy; 30 class OfflinerPolicy;
30 class OfflinerFactory; 31 class OfflinerFactory;
31 class Offliner; 32 class Offliner;
32 class RequestPicker; 33 class RequestPicker;
33 class SavePageRequest; 34 class SavePageRequest;
(...skipping 22 matching lines...) Expand all
56 57
57 // Callback to report when a request was available. 58 // Callback to report when a request was available.
58 typedef base::Callback<void(const SavePageRequest& request)> 59 typedef base::Callback<void(const SavePageRequest& request)>
59 RequestPickedCallback; 60 RequestPickedCallback;
60 // Callback to report when no request was available. 61 // Callback to report when no request was available.
61 typedef base::Callback<void(bool)> RequestNotPickedCallback; 62 typedef base::Callback<void(bool)> RequestNotPickedCallback;
62 63
63 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 64 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
64 std::unique_ptr<OfflinerFactory> factory, 65 std::unique_ptr<OfflinerFactory> factory,
65 std::unique_ptr<RequestQueue> queue, 66 std::unique_ptr<RequestQueue> queue,
66 std::unique_ptr<Scheduler> scheduler); 67 std::unique_ptr<Scheduler> scheduler,
68 net::NetworkQualityEstimator::NetworkQualityProvider*
69 network_quality_estimator);
67 70
68 ~RequestCoordinator() override; 71 ~RequestCoordinator() override;
69 72
70 // Queues |request| to later load and save when system conditions allow. 73 // Queues |request| to later load and save when system conditions allow.
71 // Returns true if the page could be queued successfully. 74 // Returns true if the page could be queued successfully.
72 bool SavePageLater( 75 bool SavePageLater(
73 const GURL& url, const ClientId& client_id, bool user_reqeusted); 76 const GURL& url, const ClientId& client_id, bool user_reqeusted);
74 77
75 // Callback specifying which request IDs were actually removed. 78 // Callback specifying which request IDs were actually removed.
76 typedef base::Callback<void( 79 typedef base::Callback<void(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 257 }
255 258
256 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { 259 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) {
257 offliner_timeout_ = timeout; 260 offliner_timeout_ = timeout;
258 } 261 }
259 262
260 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { 263 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) {
261 current_conditions_.reset(new DeviceConditions(current_conditions)); 264 current_conditions_.reset(new DeviceConditions(current_conditions));
262 } 265 }
263 266
267 // KeyedService implementation:
268 void Shutdown() override;
269
264 friend class RequestCoordinatorTest; 270 friend class RequestCoordinatorTest;
265 271
266 // The offliner can only handle one request at a time - if the offliner is 272 // The offliner can only handle one request at a time - if the offliner is
267 // busy, prevent other requests. This flag marks whether the offliner is in 273 // busy, prevent other requests. This flag marks whether the offliner is in
268 // use. 274 // use.
269 bool is_busy_; 275 bool is_busy_;
270 // There is more than one path to start processing so this flag is used 276 // There is more than one path to start processing so this flag is used
271 // to avoid race conditions before is_busy_ is established. 277 // to avoid race conditions before is_busy_ is established.
272 bool is_starting_; 278 bool is_starting_;
273 // True if the current processing window has been canceled. 279 // True if the current processing window has been canceled.
(...skipping 10 matching lines...) Expand all
284 // Last known conditions for network, battery 290 // Last known conditions for network, battery
285 std::unique_ptr<DeviceConditions> current_conditions_; 291 std::unique_ptr<DeviceConditions> current_conditions_;
286 // RequestCoordinator takes over ownership of the policy 292 // RequestCoordinator takes over ownership of the policy
287 std::unique_ptr<OfflinerPolicy> policy_; 293 std::unique_ptr<OfflinerPolicy> policy_;
288 // OfflinerFactory. Used to create offline pages. Owned. 294 // OfflinerFactory. Used to create offline pages. Owned.
289 std::unique_ptr<OfflinerFactory> factory_; 295 std::unique_ptr<OfflinerFactory> factory_;
290 // RequestQueue. Used to store incoming requests. Owned. 296 // RequestQueue. Used to store incoming requests. Owned.
291 std::unique_ptr<RequestQueue> queue_; 297 std::unique_ptr<RequestQueue> queue_;
292 // Scheduler. Used to request a callback when network is available. Owned. 298 // Scheduler. Used to request a callback when network is available. Owned.
293 std::unique_ptr<Scheduler> scheduler_; 299 std::unique_ptr<Scheduler> scheduler_;
300 // Unowned pointer to the Network Quality Estimator.
301 net::NetworkQualityEstimator::NetworkQualityProvider*
302 network_quality_estimator_;
294 // Holds copy of the active request, if any. 303 // Holds copy of the active request, if any.
295 std::unique_ptr<SavePageRequest> active_request_; 304 std::unique_ptr<SavePageRequest> active_request_;
296 // Status of the most recent offlining. 305 // Status of the most recent offlining.
297 Offliner::RequestStatus last_offlining_status_; 306 Offliner::RequestStatus last_offlining_status_;
298 // Class to choose which request to schedule next 307 // Class to choose which request to schedule next
299 std::unique_ptr<RequestPicker> picker_; 308 std::unique_ptr<RequestPicker> picker_;
300 // Calling this returns to the scheduler across the JNI bridge. 309 // Calling this returns to the scheduler across the JNI bridge.
301 base::Callback<void(bool)> scheduler_callback_; 310 base::Callback<void(bool)> scheduler_callback_;
302 // Logger to record events. 311 // Logger to record events.
303 RequestCoordinatorEventLogger event_logger_; 312 RequestCoordinatorEventLogger event_logger_;
304 // Timer to watch for pre-render attempts running too long. 313 // Timer to watch for pre-render attempts running too long.
305 base::OneShotTimer watchdog_timer_; 314 base::OneShotTimer watchdog_timer_;
306 // How long to wait for an offliner request before giving up. 315 // How long to wait for an offliner request before giving up.
307 base::TimeDelta offliner_timeout_; 316 base::TimeDelta offliner_timeout_;
308 // Allows us to pass a weak pointer to callbacks. 317 // Allows us to pass a weak pointer to callbacks.
309 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 318 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
310 319
311 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 320 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
312 }; 321 };
313 322
314 } // namespace offline_pages 323 } // namespace offline_pages
315 324
316 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 325 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698