OLD | NEW |
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_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/supports_user_data.h" | 17 #include "base/supports_user_data.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
21 #include "components/offline_pages/core/background/connection_notifier.h" | 21 #include "components/offline_pages/core/background/connection_notifier.h" |
22 #include "components/offline_pages/core/background/device_conditions.h" | 22 #include "components/offline_pages/core/background/device_conditions.h" |
23 #include "components/offline_pages/core/background/request_coordinator_event_log
ger.h" | 23 #include "components/offline_pages/core/background/request_coordinator_event_log
ger.h" |
24 #include "components/offline_pages/core/background/request_notifier.h" | 24 #include "components/offline_pages/core/background/request_notifier.h" |
25 #include "components/offline_pages/core/background/request_queue.h" | 25 #include "components/offline_pages/core/background/request_queue.h" |
| 26 #include "components/offline_pages/core/background/resource_data_type.h" |
| 27 #include "components/offline_pages/core/background/resource_tracker_observer.h" |
26 #include "components/offline_pages/core/background/scheduler.h" | 28 #include "components/offline_pages/core/background/scheduler.h" |
27 #include "net/nqe/network_quality_estimator.h" | 29 #include "net/nqe/network_quality_estimator.h" |
28 #include "url/gurl.h" | 30 #include "url/gurl.h" |
29 | 31 |
30 namespace offline_pages { | 32 namespace offline_pages { |
31 | 33 |
32 struct ClientId; | 34 struct ClientId; |
33 class OfflinerPolicy; | 35 class OfflinerPolicy; |
34 class Offliner; | 36 class Offliner; |
35 class SavePageRequest; | 37 class SavePageRequest; |
36 class ClientPolicyController; | 38 class ClientPolicyController; |
37 | 39 |
38 // Coordinates queueing and processing save page later requests. | 40 // Coordinates queueing and processing save page later requests. |
39 class RequestCoordinator : public KeyedService, | 41 class RequestCoordinator : public KeyedService, |
40 public RequestNotifier, | 42 public RequestNotifier, |
41 public base::SupportsUserData { | 43 public base::SupportsUserData, |
| 44 public ResourceTrackerObserver { |
42 public: | 45 public: |
43 // Nested observer class. To make sure that no events are missed, the client | 46 // Nested observer class. To make sure that no events are missed, the client |
44 // code should first register for notifications, then |GetAllRequests|, and | 47 // code should first register for notifications, then |GetAllRequests|, and |
45 // ignore all events before the return from |GetAllRequests|, and consume | 48 // ignore all events before the return from |GetAllRequests|, and consume |
46 // events after the return callback from |GetAllRequests|. | 49 // events after the return callback from |GetAllRequests|. |
47 class Observer { | 50 class Observer { |
48 public: | 51 public: |
49 virtual ~Observer() = default; | 52 virtual ~Observer() = default; |
50 | 53 |
51 virtual void OnAdded(const SavePageRequest& request) = 0; | 54 virtual void OnAdded(const SavePageRequest& request) = 0; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // A way to set the callback which would be called if processing will be | 177 // A way to set the callback which would be called if processing will be |
175 // triggered immediately internally by the coordinator. Used by testing | 178 // triggered immediately internally by the coordinator. Used by testing |
176 // harness to determine if a request has been processed. | 179 // harness to determine if a request has been processed. |
177 void SetInternalStartProcessingCallbackForTest( | 180 void SetInternalStartProcessingCallbackForTest( |
178 const base::Callback<void(bool)> callback) { | 181 const base::Callback<void(bool)> callback) { |
179 internal_start_processing_callback_ = callback; | 182 internal_start_processing_callback_ = callback; |
180 } | 183 } |
181 | 184 |
182 void StartImmediatelyForTest() { StartImmediatelyIfConnected(); } | 185 void StartImmediatelyForTest() { StartImmediatelyIfConnected(); } |
183 | 186 |
| 187 // Implementation of ResourceTrackerObserver interface |
| 188 // When we are notified of a resource load starting or ending, pass the |
| 189 // information along to the offliner. |
| 190 void ObserveResourceTracking(const ResourceDataType type, |
| 191 int64_t started_count, |
| 192 int64_t completed_count) override; |
| 193 |
184 // Observers implementing the RequestCoordinator::Observer interface can | 194 // Observers implementing the RequestCoordinator::Observer interface can |
185 // register here to get notifications of changes to request state. This | 195 // register here to get notifications of changes to request state. This |
186 // pointer is not owned, and it is the callers responsibility to remove the | 196 // pointer is not owned, and it is the callers responsibility to remove the |
187 // observer before the observer is deleted. | 197 // observer before the observer is deleted. |
188 void AddObserver(RequestCoordinator::Observer* observer); | 198 void AddObserver(RequestCoordinator::Observer* observer); |
189 | 199 |
190 void RemoveObserver(RequestCoordinator::Observer* observer); | 200 void RemoveObserver(RequestCoordinator::Observer* observer); |
191 | 201 |
192 // Implement RequestNotifier | 202 // Implement RequestNotifier |
193 void NotifyAdded(const SavePageRequest& request) override; | 203 void NotifyAdded(const SavePageRequest& request) override; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 std::deque<int64_t> prioritized_requests_; | 488 std::deque<int64_t> prioritized_requests_; |
479 // Allows us to pass a weak pointer to callbacks. | 489 // Allows us to pass a weak pointer to callbacks. |
480 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 490 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
481 | 491 |
482 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 492 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
483 }; | 493 }; |
484 | 494 |
485 } // namespace offline_pages | 495 } // namespace offline_pages |
486 | 496 |
487 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ | 497 #endif // COMPONENTS_OFFLINE_PAGES_CORE_BACKGROUND_REQUEST_COORDINATOR_H_ |
OLD | NEW |