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

Unified Diff: components/offline_pages/background/request_coordinator.h

Issue 2219393004: Adds an observer for the request coordinator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resumeAPI
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3c6b96e280b6d04356dcd01bdb2ffaf7f401f157..e7f2215594fb1c8a36724fbf9f9896fedf71e899 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,21 @@ class Scheduler;
// Coordinates queueing and processing save page later requests.
class RequestCoordinator : public KeyedService {
public:
+
+ // Data struct for nested observer. Add more items as needed.
+ struct RequestInfo {
+ ClientId client_id;
+ };
+
+ // Nested observer class
+ class Observer {
+ public:
+ virtual void OnAvailable(RequestInfo info) = 0;
Dmitry Titov 2016/08/09 20:14:59 Since this is an internal, most generic interface
Pete Williamson 2016/08/10 01:36:23 OK, changed to OnAdded OnSucceeded(item, offline_
+ virtual void OnSucceeded(RequestInfo info) = 0;
+ virtual void OnFailed(RequestInfo info) = 0;
+ virtual void OnPaused(RequestInfo info) = 0;
+ };
+
// Callback to report when the processing of a triggered task is complete.
typedef base::Callback<void(const SavePageRequest& request)>
RequestPickedCallback;
@@ -93,6 +109,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 unowned, and it is the callers responsibility to remove the
+ // observer before the observer is deleted.
Dmitry Titov 2016/08/09 20:14:59 This comment should also mention what happens when
Pete Williamson 2016/08/10 01:36:23 Done.
+ 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(); }
@@ -151,6 +175,11 @@ class RequestCoordinator : public KeyedService {
void TryNextRequest();
+ void NotifyAvailable(ClientId client_id);
+ void NotifySucceeded(ClientId client_id);
+ void NotifyFailed(ClientId client_id);
+ void NotifyPaused(ClientId client_id);
+
// Returns the appropriate offliner to use, getting a new one from the factory
// if needed.
void GetOffliner();
@@ -174,6 +203,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
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698