| 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_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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // Nested observer class. To make sure that no events are missed, the client | 42 // Nested observer class. To make sure that no events are missed, the client |
| 43 // code should first register for notifications, then |GetAllRequests|, and | 43 // code should first register for notifications, then |GetAllRequests|, and |
| 44 // ignore all events before the return from |GetAllRequests|, and consume | 44 // ignore all events before the return from |GetAllRequests|, and consume |
| 45 // events after the return callback from |GetAllRequests|. | 45 // events after the return callback from |GetAllRequests|. |
| 46 class Observer { | 46 class Observer { |
| 47 public: | 47 public: |
| 48 virtual ~Observer() = default; | 48 virtual ~Observer() = default; |
| 49 | 49 |
| 50 virtual void OnAdded(const SavePageRequest& request) = 0; | 50 virtual void OnAdded(const SavePageRequest& request) = 0; |
| 51 virtual void OnCompleted(const SavePageRequest& request, | 51 virtual void OnCompleted( |
| 52 RequestNotifier::SavePageStatus status) = 0; | 52 const SavePageRequest& request, |
| 53 RequestNotifier::BackgroundSavePageResult status) = 0; |
| 53 virtual void OnChanged(const SavePageRequest& request) = 0; | 54 virtual void OnChanged(const SavePageRequest& request) = 0; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 // Callback to report when a request was available. | 57 // Callback to report when a request was available. |
| 57 typedef base::Callback<void(const SavePageRequest& request)> | 58 typedef base::Callback<void(const SavePageRequest& request)> |
| 58 RequestPickedCallback; | 59 RequestPickedCallback; |
| 59 // Callback to report when no request was available. | 60 // Callback to report when no request was available. |
| 60 typedef base::Callback<void(bool)> RequestNotPickedCallback; | 61 typedef base::Callback<void(bool)> RequestNotPickedCallback; |
| 61 | 62 |
| 62 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 63 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Observers implementing the RequestCoordinator::Observer interface can | 123 // Observers implementing the RequestCoordinator::Observer interface can |
| 123 // register here to get notifications of changes to request state. This | 124 // register here to get notifications of changes to request state. This |
| 124 // pointer is not owned, and it is the callers responsibility to remove the | 125 // pointer is not owned, and it is the callers responsibility to remove the |
| 125 // observer before the observer is deleted. | 126 // observer before the observer is deleted. |
| 126 void AddObserver(RequestCoordinator::Observer* observer); | 127 void AddObserver(RequestCoordinator::Observer* observer); |
| 127 | 128 |
| 128 void RemoveObserver(RequestCoordinator::Observer* observer); | 129 void RemoveObserver(RequestCoordinator::Observer* observer); |
| 129 | 130 |
| 130 // Implement RequestNotifier | 131 // Implement RequestNotifier |
| 131 void NotifyAdded(const SavePageRequest& request) override; | 132 void NotifyAdded(const SavePageRequest& request) override; |
| 132 void NotifyCompleted(const SavePageRequest& request, | 133 void NotifyCompleted( |
| 133 RequestNotifier::SavePageStatus status) override; | 134 const SavePageRequest& request, |
| 135 RequestNotifier::BackgroundSavePageResult status) override; |
| 134 void NotifyChanged(const SavePageRequest& request) override; | 136 void NotifyChanged(const SavePageRequest& request) override; |
| 135 | 137 |
| 136 // Returns the request queue used for requests. Coordinator keeps ownership. | 138 // Returns the request queue used for requests. Coordinator keeps ownership. |
| 137 RequestQueue* queue() { return queue_.get(); } | 139 RequestQueue* queue() { return queue_.get(); } |
| 138 | 140 |
| 139 // Return an unowned pointer to the Scheduler. | 141 // Return an unowned pointer to the Scheduler. |
| 140 Scheduler* scheduler() { return scheduler_.get(); } | 142 Scheduler* scheduler() { return scheduler_.get(); } |
| 141 | 143 |
| 142 OfflinerPolicy* policy() { return policy_.get(); } | 144 OfflinerPolicy* policy() { return policy_.get(); } |
| 143 | 145 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // Receives the result of update and delete requests to the request queue. | 182 // Receives the result of update and delete requests to the request queue. |
| 181 void UpdateRequestCallback(const ClientId& client_id, | 183 void UpdateRequestCallback(const ClientId& client_id, |
| 182 RequestQueue::UpdateRequestResult result); | 184 RequestQueue::UpdateRequestResult result); |
| 183 | 185 |
| 184 void UpdateMultipleRequestsCallback( | 186 void UpdateMultipleRequestsCallback( |
| 185 const RequestQueue::UpdateMultipleRequestResults& result, | 187 const RequestQueue::UpdateMultipleRequestResults& result, |
| 186 const std::vector<SavePageRequest>& requests); | 188 const std::vector<SavePageRequest>& requests); |
| 187 | 189 |
| 188 void HandleRemovedRequestsAndCallback( | 190 void HandleRemovedRequestsAndCallback( |
| 189 const RemoveRequestsCallback& callback, | 191 const RemoveRequestsCallback& callback, |
| 190 SavePageStatus status, | 192 BackgroundSavePageResult status, |
| 191 const RequestQueue::UpdateMultipleRequestResults& results, | 193 const RequestQueue::UpdateMultipleRequestResults& results, |
| 192 const std::vector<SavePageRequest>& requests); | 194 const std::vector<SavePageRequest>& requests); |
| 193 | 195 |
| 194 void HandleRemovedRequests( | 196 void HandleRemovedRequests( |
| 195 SavePageStatus status, | 197 BackgroundSavePageResult status, |
| 196 const RequestQueue::UpdateMultipleRequestResults& results, | 198 const RequestQueue::UpdateMultipleRequestResults& results, |
| 197 const std::vector<SavePageRequest>& requests); | 199 const std::vector<SavePageRequest>& requests); |
| 198 | 200 |
| 199 // Start processing now if connected (but with conservative assumption | 201 // Start processing now if connected (but with conservative assumption |
| 200 // as to other device conditions). | 202 // as to other device conditions). |
| 201 void StartProcessingIfConnected(); | 203 void StartProcessingIfConnected(); |
| 202 | 204 |
| 203 // Check the request queue, and schedule a task corresponding | 205 // Check the request queue, and schedule a task corresponding |
| 204 // to the least restrictive type of request in the queue. | 206 // to the least restrictive type of request in the queue. |
| 205 void ScheduleAsNeeded(); | 207 void ScheduleAsNeeded(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 227 // If there is an active request in the list, cancel that request. | 229 // If there is an active request in the list, cancel that request. |
| 228 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids); | 230 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids); |
| 229 | 231 |
| 230 // Records an aborted attempt for the request and update it in the queue | 232 // Records an aborted attempt for the request and update it in the queue |
| 231 // (possibly removing it). Returns the updated copy. | 233 // (possibly removing it). Returns the updated copy. |
| 232 void AbortRequestAttempt(SavePageRequest* request); | 234 void AbortRequestAttempt(SavePageRequest* request); |
| 233 | 235 |
| 234 // Remove the attempted request from the queue with status to pass through to | 236 // Remove the attempted request from the queue with status to pass through to |
| 235 // any observers and UMA histogram. | 237 // any observers and UMA histogram. |
| 236 void RemoveAttemptedRequest(const SavePageRequest& request, | 238 void RemoveAttemptedRequest(const SavePageRequest& request, |
| 237 SavePageStatus status); | 239 BackgroundSavePageResult status); |
| 238 | 240 |
| 239 // Returns the appropriate offliner to use, getting a new one from the factory | 241 // Returns the appropriate offliner to use, getting a new one from the factory |
| 240 // if needed. | 242 // if needed. |
| 241 void GetOffliner(); | 243 void GetOffliner(); |
| 242 | 244 |
| 243 // Method to wrap calls to getting the connection type so it can be | 245 // Method to wrap calls to getting the connection type so it can be |
| 244 // changed for tests. | 246 // changed for tests. |
| 245 net::NetworkChangeNotifier::ConnectionType GetConnectionType(); | 247 net::NetworkChangeNotifier::ConnectionType GetConnectionType(); |
| 246 | 248 |
| 247 void SetNetworkConditionsForTest( | 249 void SetNetworkConditionsForTest( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 base::TimeDelta offliner_timeout_; | 303 base::TimeDelta offliner_timeout_; |
| 302 // Allows us to pass a weak pointer to callbacks. | 304 // Allows us to pass a weak pointer to callbacks. |
| 303 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 305 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 304 | 306 |
| 305 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 307 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 306 }; | 308 }; |
| 307 | 309 |
| 308 } // namespace offline_pages | 310 } // namespace offline_pages |
| 309 | 311 |
| 310 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 312 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |