Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 class OfflinerFactory; | 28 class OfflinerFactory; |
| 29 class Offliner; | 29 class Offliner; |
| 30 class RequestPicker; | 30 class RequestPicker; |
| 31 class SavePageRequest; | 31 class SavePageRequest; |
| 32 class Scheduler; | 32 class Scheduler; |
| 33 | 33 |
| 34 // Coordinates queueing and processing save page later requests. | 34 // Coordinates queueing and processing save page later requests. |
| 35 class RequestCoordinator : public KeyedService { | 35 class RequestCoordinator : public KeyedService { |
| 36 public: | 36 public: |
| 37 // Status to return for failed notifications. | 37 // Status to return for failed notifications. |
| 38 enum class SavePageStatus { | 38 enum class SavePageStatus { |
|
fgorski
2016/08/16 22:13:25
nit: SavePageStatus might no longer be the best na
Pete Williamson
2016/08/16 23:08:52
Done.
| |
| 39 SUCCESS, | 39 SUCCESS, |
| 40 PRERENDER_FAILURE, | 40 PRERENDER_FAILURE, |
| 41 FOREGROUND_CANCELED, | 41 FOREGROUND_CANCELED, |
| 42 SAVE_FAILED, | 42 SAVE_FAILED, |
| 43 EXPIRED, | 43 EXPIRED, |
| 44 RETRY_COUNT_EXCEEDED, | 44 RETRY_COUNT_EXCEEDED, |
| 45 REMOVED_BY_CLIENT, | 45 REMOVED, |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Nested observer class. To make sure that no events are missed, the client | 48 // Nested observer class. To make sure that no events are missed, the client |
| 49 // code should first register for notifications, then |GetAllRequests|, and | 49 // code should first register for notifications, then |GetAllRequests|, and |
| 50 // ignore all events before the return from |GetAllRequests|, and consume | 50 // ignore all events before the return from |GetAllRequests|, and consume |
| 51 // events after the return callback from |GetAllRequests|. | 51 // events after the return callback from |GetAllRequests|. |
| 52 class Observer { | 52 class Observer { |
| 53 public: | 53 public: |
| 54 virtual void OnAdded(const SavePageRequest& request) = 0; | 54 virtual void OnAdded(const SavePageRequest& request) = 0; |
| 55 virtual void OnSucceeded(const SavePageRequest& request) = 0; | 55 virtual void OnCompleted(const SavePageRequest& request, |
| 56 virtual void OnFailed(const SavePageRequest& request, | 56 SavePageStatus status) = 0; |
| 57 SavePageStatus status) = 0; | |
| 58 virtual void OnChanged(const SavePageRequest& request) = 0; | 57 virtual void OnChanged(const SavePageRequest& request) = 0; |
| 59 virtual void OnRemoved(const SavePageRequest& request, | |
| 60 SavePageStatus status) = 0; | |
| 61 // TODO(petewil): Merge OnSucceeded, OnFailed, and OnRemoved into a single | 58 // TODO(petewil): Merge OnSucceeded, OnFailed, and OnRemoved into a single |
|
fgorski
2016/08/16 22:13:25
remove todo
Pete Williamson
2016/08/16 23:08:52
Done.
| |
| 62 // call. | 59 // call. |
| 63 }; | 60 }; |
| 64 | 61 |
| 65 // Callback to report when the processing of a triggered task is complete. | 62 // Callback to report when the processing of a triggered task is complete. |
| 66 typedef base::Callback<void(const SavePageRequest& request)> | 63 typedef base::Callback<void(const SavePageRequest& request)> |
| 67 RequestPickedCallback; | 64 RequestPickedCallback; |
| 68 typedef base::Callback<void()> RequestQueueEmptyCallback; | 65 typedef base::Callback<void()> RequestQueueEmptyCallback; |
| 69 | 66 |
| 70 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 67 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| 71 std::unique_ptr<OfflinerFactory> factory, | 68 std::unique_ptr<OfflinerFactory> factory, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 void SendRequestToOffliner(const SavePageRequest& request); | 182 void SendRequestToOffliner(const SavePageRequest& request); |
| 186 | 183 |
| 187 // Called by the offliner when an offlining request is completed. (and by | 184 // Called by the offliner when an offlining request is completed. (and by |
| 188 // tests). | 185 // tests). |
| 189 void OfflinerDoneCallback(const SavePageRequest& request, | 186 void OfflinerDoneCallback(const SavePageRequest& request, |
| 190 Offliner::RequestStatus status); | 187 Offliner::RequestStatus status); |
| 191 | 188 |
| 192 void TryNextRequest(); | 189 void TryNextRequest(); |
| 193 | 190 |
| 194 void NotifyAdded(const SavePageRequest& request); | 191 void NotifyAdded(const SavePageRequest& request); |
| 195 void NotifySucceeded(const SavePageRequest& request); | 192 void NotifyCompleted(const SavePageRequest& request, SavePageStatus status); |
| 196 void NotifyFailed(const SavePageRequest& request, SavePageStatus status); | |
| 197 void NotifyChanged(const SavePageRequest& request); | 193 void NotifyChanged(const SavePageRequest& request); |
| 198 void NotifyRemoved(const SavePageRequest& request); | |
| 199 | 194 |
| 200 // Returns the appropriate offliner to use, getting a new one from the factory | 195 // Returns the appropriate offliner to use, getting a new one from the factory |
| 201 // if needed. | 196 // if needed. |
| 202 void GetOffliner(); | 197 void GetOffliner(); |
| 203 | 198 |
| 204 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { | 199 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { |
| 205 offliner_timeout_ = timeout; | 200 offliner_timeout_ = timeout; |
| 206 } | 201 } |
| 207 | 202 |
| 208 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { | 203 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 base::TimeDelta offliner_timeout_; | 243 base::TimeDelta offliner_timeout_; |
| 249 // Allows us to pass a weak pointer to callbacks. | 244 // Allows us to pass a weak pointer to callbacks. |
| 250 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 245 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 251 | 246 |
| 252 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 247 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 253 }; | 248 }; |
| 254 | 249 |
| 255 } // namespace offline_pages | 250 } // namespace offline_pages |
| 256 | 251 |
| 257 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 252 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |