Chromium Code Reviews| Index: components/offline_pages/background/request_coordinator.h |
| diff --git a/components/offline_pages/background/request_coordinator.h b/components/offline_pages/background/request_coordinator.h |
| index 3e52021e3597ca352a12cc6d2fdacad9c25b6db8..ad05ec8fece37dcd9fef6e2aa3e8ab95835ceb0a 100644 |
| --- a/components/offline_pages/background/request_coordinator.h |
| +++ b/components/offline_pages/background/request_coordinator.h |
| @@ -10,6 +10,7 @@ |
| #include "base/callback.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/observer_list.h" |
| #include "base/time/time.h" |
| #include "base/timer/timer.h" |
| #include "components/keyed_service/core/keyed_service.h" |
| @@ -33,6 +34,30 @@ class Scheduler; |
| // Coordinates queueing and processing save page later requests. |
| class RequestCoordinator : public KeyedService { |
| public: |
| + // Status to return for failed notifications. |
| + enum class SavePageStatus { |
| + SUCCESS, |
| + PRERENDER_FAILURE, |
| + FOREGROUND_CANCELED, |
| + SAVE_FAILED, |
| + EXPIRED, |
| + RETRY_COUNT_EXCEEDED, |
| + }; |
| + |
| + // Nested observer class. To make sure that no events are missed, the client |
| + // code should first register for notifications, then GetAllRequests, and |
| + // ignore all events before the return from GetAllRequests, and consume events |
| + // after the return callback from GetAlLRequests. |
|
fgorski
2016/08/11 17:03:58
AlL -> All
nit: I believe we use |GetAllRequests|
Pete Williamson
2016/08/13 03:20:34
Done.
|
| + class Observer { |
| + public: |
| + virtual void OnAdded(const SavePageRequest& request) = 0; |
| + virtual void OnSucceeded(const SavePageRequest& request, |
| + int64_t offline_id) = 0; |
|
Dmitry Titov
2016/08/11 03:41:55
Once we agreed the id is inherited from request to
Pete Williamson
2016/08/13 03:20:34
Done.
|
| + virtual void OnFailed(const SavePageRequest& request, |
| + SavePageStatus status) = 0; |
| + virtual void OnChanged(const SavePageRequest& request) = 0; |
| + }; |
| + |
| // Callback to report when the processing of a triggered task is complete. |
| typedef base::Callback<void(const SavePageRequest& request)> |
| RequestPickedCallback; |
| @@ -93,6 +118,14 @@ class RequestCoordinator : public KeyedService { |
| scheduler_callback_ = callback; |
| } |
| + // Observers implementing the RequestCoordinator::Observer interface can |
| + // register here to get notifications of changes to request state. This |
| + // pointer is not owned, and it is the callers responsibility to remove the |
| + // observer before the observer is deleted. |
| + void AddObserver(RequestCoordinator::Observer* observer); |
| + |
| + void RemoveObserver(RequestCoordinator::Observer* observer); |
| + |
| // Returns the request queue used for requests. Coordinator keeps ownership. |
| RequestQueue* queue() { return queue_.get(); } |
| @@ -134,7 +167,12 @@ class RequestCoordinator : public KeyedService { |
| void UpdateRequestCallback(const ClientId& client_id, |
| RequestQueue::UpdateRequestResult result); |
| - void UpdateMultipleRequestCallback(RequestQueue::UpdateRequestResult result); |
| + void UpdateMultipleRequestCallback(const std::vector<int64_t>& request_ids, |
| + RequestQueue::UpdateRequestResult result); |
| + |
| + void NotifyChangedListCallback(const std::vector<int64_t>& request_ids, |
| + RequestQueue::GetRequestsResult result, |
| + const std::vector<SavePageRequest>& requests); |
| // Callback from the request picker when it has chosen our next request. |
| void RequestPicked(const SavePageRequest& request); |
| @@ -151,6 +189,14 @@ class RequestCoordinator : public KeyedService { |
| void TryNextRequest(); |
| + void NotifyAdded(const SavePageRequest& request); |
| + void NotifySucceeded(const SavePageRequest& request, int64_t offline_id); |
| + void NotifyFailed(const SavePageRequest& request, SavePageStatus status); |
| + void NotifyChanged(const SavePageRequest& request); |
| + |
| + // Sends a changed notification for each request_id in the list. |
| + void SendNotifyChangeForRequestIdList(std::vector<int64_t> request_ids); |
| + |
| // Returns the appropriate offliner to use, getting a new one from the factory |
| // if needed. |
| void GetOffliner(); |
| @@ -174,6 +220,8 @@ class RequestCoordinator : public KeyedService { |
| // Unowned pointer to the current offliner, if any. |
| Offliner* offliner_; |
| base::Time operation_start_time_; |
| + // The observers. |
| + base::ObserverList<Observer> observers_; |
| // Last known conditions for network, battery |
| std::unique_ptr<DeviceConditions> current_conditions_; |
| // RequestCoordinator takes over ownership of the policy |