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

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

Issue 2269173003: Adjust scheduling for non-user requested items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 unified diff | Download patch
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 public: 44 public:
45 virtual void OnAdded(const SavePageRequest& request) = 0; 45 virtual void OnAdded(const SavePageRequest& request) = 0;
46 virtual void OnCompleted(const SavePageRequest& request, 46 virtual void OnCompleted(const SavePageRequest& request,
47 RequestNotifier::SavePageStatus status) = 0; 47 RequestNotifier::SavePageStatus status) = 0;
48 virtual void OnChanged(const SavePageRequest& request) = 0; 48 virtual void OnChanged(const SavePageRequest& request) = 0;
49 }; 49 };
50 50
51 // Callback to report when the processing of a triggered task is complete. 51 // Callback to report when the processing of a triggered task is complete.
52 typedef base::Callback<void(const SavePageRequest& request)> 52 typedef base::Callback<void(const SavePageRequest& request)>
53 RequestPickedCallback; 53 RequestPickedCallback;
54 typedef base::Callback<void()> RequestQueueEmptyCallback; 54 typedef base::Callback<void(bool)> RequestQueueEmptyCallback;
55 55
56 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 56 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
57 std::unique_ptr<OfflinerFactory> factory, 57 std::unique_ptr<OfflinerFactory> factory,
58 std::unique_ptr<RequestQueue> queue, 58 std::unique_ptr<RequestQueue> queue,
59 std::unique_ptr<Scheduler> scheduler); 59 std::unique_ptr<Scheduler> scheduler);
60 60
61 ~RequestCoordinator() override; 61 ~RequestCoordinator() override;
62 62
63 // Queues |request| to later load and save when system conditions allow. 63 // Queues |request| to later load and save when system conditions allow.
64 // Returns true if the page could be queued successfully. 64 // Returns true if the page could be queued successfully.
(...skipping 27 matching lines...) Expand all
92 // a callback. If processing was already active, returns false. 92 // a callback. If processing was already active, returns false.
93 bool StartProcessing(const DeviceConditions& device_conditions, 93 bool StartProcessing(const DeviceConditions& device_conditions,
94 const base::Callback<void(bool)>& callback); 94 const base::Callback<void(bool)>& callback);
95 95
96 // Stops the current request processing if active. This is a way for 96 // Stops the current request processing if active. This is a way for
97 // caller to abort processing; otherwise, processing will complete on 97 // caller to abort processing; otherwise, processing will complete on
98 // its own. In either case, the callback will be called when processing 98 // its own. In either case, the callback will be called when processing
99 // is stopped or complete. 99 // is stopped or complete.
100 void StopProcessing(); 100 void StopProcessing();
101 101
102 const Scheduler::TriggerConditions GetTriggerConditionsForUserRequest(); 102 const Scheduler::TriggerConditions GetTriggerConditions(
103 const bool user_requested);
103 104
104 // A way for tests to set the callback in use when an operation is over. 105 // A way for tests to set the callback in use when an operation is over.
105 void SetProcessingCallbackForTest(const base::Callback<void(bool)> callback) { 106 void SetProcessingCallbackForTest(const base::Callback<void(bool)> callback) {
106 scheduler_callback_ = callback; 107 scheduler_callback_ = callback;
107 } 108 }
108 109
109 // Observers implementing the RequestCoordinator::Observer interface can 110 // Observers implementing the RequestCoordinator::Observer interface can
110 // register here to get notifications of changes to request state. This 111 // register here to get notifications of changes to request state. This
111 // pointer is not owned, and it is the callers responsibility to remove the 112 // pointer is not owned, and it is the callers responsibility to remove the
112 // observer before the observer is deleted. 113 // observer before the observer is deleted.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return &event_logger_; 146 return &event_logger_;
146 } 147 }
147 148
148 private: 149 private:
149 // Receives the results of a get from the request queue, and turns that into 150 // Receives the results of a get from the request queue, and turns that into
150 // SavePageRequest objects for the caller of GetQueuedRequests. 151 // SavePageRequest objects for the caller of GetQueuedRequests.
151 void GetQueuedRequestsCallback(const GetRequestsCallback& callback, 152 void GetQueuedRequestsCallback(const GetRequestsCallback& callback,
152 RequestQueue::GetRequestsResult result, 153 RequestQueue::GetRequestsResult result,
153 const std::vector<SavePageRequest>& requests); 154 const std::vector<SavePageRequest>& requests);
154 155
156 // Receives the results of a get from the request queue, and turns that into
157 // SavePageRequest objects for the caller of GetQueuedRequests.
158 void GetRequestsForSchedulingCallback(
159 RequestQueue::GetRequestsResult result,
160 const std::vector<SavePageRequest>& requests);
161
155 // Receives the result of add requests to the request queue. 162 // Receives the result of add requests to the request queue.
156 void AddRequestResultCallback(RequestQueue::AddRequestResult result, 163 void AddRequestResultCallback(RequestQueue::AddRequestResult result,
157 const SavePageRequest& request); 164 const SavePageRequest& request);
158 165
159 // Receives the result of update and delete requests to the request queue. 166 // Receives the result of update and delete requests to the request queue.
160 void UpdateRequestCallback(const ClientId& client_id, 167 void UpdateRequestCallback(const ClientId& client_id,
161 RequestQueue::UpdateRequestResult result); 168 RequestQueue::UpdateRequestResult result);
162 169
163 void UpdateMultipleRequestsCallback( 170 void UpdateMultipleRequestsCallback(
164 const RequestQueue::UpdateMultipleRequestResults& result, 171 const RequestQueue::UpdateMultipleRequestResults& result,
165 const std::vector<SavePageRequest>& requests); 172 const std::vector<SavePageRequest>& requests);
166 173
167 void RemoveRequestsCallback( 174 void RemoveRequestsCallback(
168 const RequestQueue::UpdateMultipleRequestResults& results, 175 const RequestQueue::UpdateMultipleRequestResults& results,
169 const std::vector<SavePageRequest>& requests); 176 const std::vector<SavePageRequest>& requests);
170 177
178
fgorski 2016/08/24 16:07:04 nit: empty line
Pete Williamson 2016/08/25 00:00:58 Done.
179 // Check the request queue, and schedule a task corresponding
180 // to the least restrictive type of request in the queue.
181 void ScheduleAsNeeded();
182
171 // Callback from the request picker when it has chosen our next request. 183 // Callback from the request picker when it has chosen our next request.
172 void RequestPicked(const SavePageRequest& request); 184 void RequestPicked(const SavePageRequest& request);
173 185
174 // Callback from the request picker when no more requests are in the queue. 186 // Callback from the request picker when no more requests are in the queue.
175 void RequestQueueEmpty(); 187 void RequestQueueEmpty(bool non_user_requested_tasks_remaining);
176 188
177 void SendRequestToOffliner(const SavePageRequest& request); 189 void SendRequestToOffliner(const SavePageRequest& request);
178 190
179 // Called by the offliner when an offlining request is completed. (and by 191 // Called by the offliner when an offlining request is completed. (and by
180 // tests). 192 // tests).
181 void OfflinerDoneCallback(const SavePageRequest& request, 193 void OfflinerDoneCallback(const SavePageRequest& request,
182 Offliner::RequestStatus status); 194 Offliner::RequestStatus status);
183 195
184 void TryNextRequest(); 196 void TryNextRequest();
185 197
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 base::TimeDelta offliner_timeout_; 246 base::TimeDelta offliner_timeout_;
235 // Allows us to pass a weak pointer to callbacks. 247 // Allows us to pass a weak pointer to callbacks.
236 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 248 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
237 249
238 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 250 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
239 }; 251 };
240 252
241 } // namespace offline_pages 253 } // namespace offline_pages
242 254
243 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 255 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698