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

Side by Side Diff: components/offline_pages/background/request_coordinator.h

Issue 2249303002: Simplify Observer callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR nits - fix TODOs 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/offline_pages/background/request_coordinator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TODO(petewil): Can we find a better name for this enum?
dougarnett 2016/08/19 20:59:24 BackgroundSavePageResult or SavePageLaterResult ?
38 enum class SavePageStatus { 39 enum class SavePageStatus {
39 SUCCESS, 40 SUCCESS,
40 PRERENDER_FAILURE, 41 PRERENDER_FAILURE,
41 FOREGROUND_CANCELED, 42 FOREGROUND_CANCELED,
42 SAVE_FAILED, 43 SAVE_FAILED,
43 EXPIRED, 44 EXPIRED,
44 RETRY_COUNT_EXCEEDED, 45 RETRY_COUNT_EXCEEDED,
45 REMOVED_BY_CLIENT, 46 REMOVED,
46 }; 47 };
47 48
48 // Nested observer class. To make sure that no events are missed, the client 49 // Nested observer class. To make sure that no events are missed, the client
49 // code should first register for notifications, then |GetAllRequests|, and 50 // code should first register for notifications, then |GetAllRequests|, and
50 // ignore all events before the return from |GetAllRequests|, and consume 51 // ignore all events before the return from |GetAllRequests|, and consume
51 // events after the return callback from |GetAllRequests|. 52 // events after the return callback from |GetAllRequests|.
52 class Observer { 53 class Observer {
53 public: 54 public:
54 virtual void OnAdded(const SavePageRequest& request) = 0; 55 virtual void OnAdded(const SavePageRequest& request) = 0;
55 virtual void OnSucceeded(const SavePageRequest& request) = 0; 56 virtual void OnCompleted(const SavePageRequest& request,
56 virtual void OnFailed(const SavePageRequest& request, 57 SavePageStatus status) = 0;
57 SavePageStatus status) = 0;
58 virtual void OnChanged(const SavePageRequest& request) = 0; 58 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
62 // call.
63 }; 59 };
64 60
65 // Callback to report when the processing of a triggered task is complete. 61 // Callback to report when the processing of a triggered task is complete.
66 typedef base::Callback<void(const SavePageRequest& request)> 62 typedef base::Callback<void(const SavePageRequest& request)>
67 RequestPickedCallback; 63 RequestPickedCallback;
68 typedef base::Callback<void()> RequestQueueEmptyCallback; 64 typedef base::Callback<void()> RequestQueueEmptyCallback;
69 65
70 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 66 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
71 std::unique_ptr<OfflinerFactory> factory, 67 std::unique_ptr<OfflinerFactory> factory,
72 std::unique_ptr<RequestQueue> queue, 68 std::unique_ptr<RequestQueue> queue,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void SendRequestToOffliner(const SavePageRequest& request); 181 void SendRequestToOffliner(const SavePageRequest& request);
186 182
187 // Called by the offliner when an offlining request is completed. (and by 183 // Called by the offliner when an offlining request is completed. (and by
188 // tests). 184 // tests).
189 void OfflinerDoneCallback(const SavePageRequest& request, 185 void OfflinerDoneCallback(const SavePageRequest& request,
190 Offliner::RequestStatus status); 186 Offliner::RequestStatus status);
191 187
192 void TryNextRequest(); 188 void TryNextRequest();
193 189
194 void NotifyAdded(const SavePageRequest& request); 190 void NotifyAdded(const SavePageRequest& request);
195 void NotifySucceeded(const SavePageRequest& request); 191 void NotifyCompleted(const SavePageRequest& request, SavePageStatus status);
196 void NotifyFailed(const SavePageRequest& request, SavePageStatus status);
197 void NotifyChanged(const SavePageRequest& request); 192 void NotifyChanged(const SavePageRequest& request);
198 void NotifyRemoved(const SavePageRequest& request);
199 193
200 // Returns the appropriate offliner to use, getting a new one from the factory 194 // Returns the appropriate offliner to use, getting a new one from the factory
201 // if needed. 195 // if needed.
202 void GetOffliner(); 196 void GetOffliner();
203 197
204 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { 198 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) {
205 offliner_timeout_ = timeout; 199 offliner_timeout_ = timeout;
206 } 200 }
207 201
208 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { 202 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 base::TimeDelta offliner_timeout_; 242 base::TimeDelta offliner_timeout_;
249 // Allows us to pass a weak pointer to callbacks. 243 // Allows us to pass a weak pointer to callbacks.
250 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 244 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
251 245
252 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 246 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
253 }; 247 };
254 248
255 } // namespace offline_pages 249 } // namespace offline_pages
256 250
257 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 251 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW
« 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