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

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

Issue 2373933003: [Offline pages] Updating RequestQueue::RemoveRequests to use a TaskQueue (Closed)
Patch Set: Addressing final feedback Created 4 years, 2 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 virtual void OnAdded(const SavePageRequest& request) = 0; 51 virtual void OnAdded(const SavePageRequest& request) = 0;
52 virtual void OnCompleted( 52 virtual void OnCompleted(
53 const SavePageRequest& request, 53 const SavePageRequest& request,
54 RequestNotifier::BackgroundSavePageResult status) = 0; 54 RequestNotifier::BackgroundSavePageResult status) = 0;
55 virtual void OnChanged(const SavePageRequest& request) = 0; 55 virtual void OnChanged(const SavePageRequest& request) = 0;
56 }; 56 };
57 57
58 // Callback to report when a request was available. 58 // Callback to report when a request was available.
59 typedef base::Callback<void(const SavePageRequest& request)> 59 typedef base::Callback<void(const SavePageRequest& request)>
60 RequestPickedCallback; 60 RequestPickedCallback;
61
61 // Callback to report when no request was available. 62 // Callback to report when no request was available.
62 typedef base::Callback<void(bool)> RequestNotPickedCallback; 63 typedef base::Callback<void(bool)> RequestNotPickedCallback;
63 64
65 // Callback specifying which request IDs were actually removed.
66 typedef base::Callback<void(const MultipleItemStatuses&)>
67 RemoveRequestsCallback;
68
69 // Callback that receives the response for GetAllRequests.
70 typedef base::Callback<void(std::vector<std::unique_ptr<SavePageRequest>>)>
71 GetRequestsCallback;
72
64 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, 73 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
65 std::unique_ptr<OfflinerFactory> factory, 74 std::unique_ptr<OfflinerFactory> factory,
66 std::unique_ptr<RequestQueue> queue, 75 std::unique_ptr<RequestQueue> queue,
67 std::unique_ptr<Scheduler> scheduler, 76 std::unique_ptr<Scheduler> scheduler,
68 net::NetworkQualityEstimator::NetworkQualityProvider* 77 net::NetworkQualityEstimator::NetworkQualityProvider*
69 network_quality_estimator); 78 network_quality_estimator);
70 79
71 ~RequestCoordinator() override; 80 ~RequestCoordinator() override;
72 81
73 // Queues |request| to later load and save when system conditions allow. 82 // Queues |request| to later load and save when system conditions allow.
74 // Returns true if the page could be queued successfully. 83 // Returns true if the page could be queued successfully.
75 bool SavePageLater( 84 bool SavePageLater(
76 const GURL& url, const ClientId& client_id, bool user_reqeusted); 85 const GURL& url, const ClientId& client_id, bool user_reqeusted);
77 86
78 // Callback specifying which request IDs were actually removed.
79 typedef base::Callback<void(
80 const RequestQueue::UpdateMultipleRequestResults&)>
81 RemoveRequestsCallback;
82
83 // Remove a list of requests by |request_id|. This removes requests from the 87 // Remove a list of requests by |request_id|. This removes requests from the
84 // request queue, and cancels an in-progress prerender. 88 // request queue, and cancels an in-progress prerender.
85 void RemoveRequests(const std::vector<int64_t>& request_ids, 89 void RemoveRequests(const std::vector<int64_t>& request_ids,
86 const RemoveRequestsCallback& callback); 90 const RemoveRequestsCallback& callback);
87 91
88 // Pause a list of requests by |request_id|. This will change the state 92 // Pause a list of requests by |request_id|. This will change the state
89 // in the request queue so the request cannot be started. 93 // in the request queue so the request cannot be started.
90 void PauseRequests(const std::vector<int64_t>& request_ids); 94 void PauseRequests(const std::vector<int64_t>& request_ids);
91 95
92 // Resume a list of previously paused requests, making them available. 96 // Resume a list of previously paused requests, making them available.
93 void ResumeRequests(const std::vector<int64_t>& request_ids); 97 void ResumeRequests(const std::vector<int64_t>& request_ids);
94 98
95 // Callback that receives the response for GetAllRequests.
96 typedef base::Callback<void(std::vector<std::unique_ptr<SavePageRequest>>)>
97 GetRequestsCallback;
98
99 // Get all save page request items in the callback. 99 // Get all save page request items in the callback.
100 void GetAllRequests(const GetRequestsCallback& callback); 100 void GetAllRequests(const GetRequestsCallback& callback);
101 101
102 // Starts processing of one or more queued save page later requests. 102 // Starts processing of one or more queued save page later requests.
103 // Returns whether processing was started and that caller should expect 103 // Returns whether processing was started and that caller should expect
104 // a callback. If processing was already active, returns false. 104 // a callback. If processing was already active, returns false.
105 bool StartProcessing(const DeviceConditions& device_conditions, 105 bool StartProcessing(const DeviceConditions& device_conditions,
106 const base::Callback<void(bool)>& callback); 106 const base::Callback<void(bool)>& callback);
107 107
108 // Stops the current request processing if active. This is a way for 108 // Stops the current request processing if active. This is a way for
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Receives the result of update and delete requests to the request queue. 186 // Receives the result of update and delete requests to the request queue.
187 void UpdateRequestCallback(const ClientId& client_id, 187 void UpdateRequestCallback(const ClientId& client_id,
188 RequestQueue::UpdateRequestResult result); 188 RequestQueue::UpdateRequestResult result);
189 189
190 void UpdateMultipleRequestsCallback( 190 void UpdateMultipleRequestsCallback(
191 std::unique_ptr<UpdateRequestsResult> result); 191 std::unique_ptr<UpdateRequestsResult> result);
192 192
193 void HandleRemovedRequestsAndCallback( 193 void HandleRemovedRequestsAndCallback(
194 const RemoveRequestsCallback& callback, 194 const RemoveRequestsCallback& callback,
195 BackgroundSavePageResult status, 195 BackgroundSavePageResult status,
196 const RequestQueue::UpdateMultipleRequestResults& results, 196 std::unique_ptr<UpdateRequestsResult> result);
197 std::vector<std::unique_ptr<SavePageRequest>> requests);
198 197
199 void HandleRemovedRequests( 198 void HandleRemovedRequests(BackgroundSavePageResult status,
200 BackgroundSavePageResult status, 199 std::unique_ptr<UpdateRequestsResult> result);
201 const RequestQueue::UpdateMultipleRequestResults& results,
202 std::vector<std::unique_ptr<SavePageRequest>> requests);
203 200
204 // Start processing now if connected (but with conservative assumption 201 // Start processing now if connected (but with conservative assumption
205 // as to other device conditions). 202 // as to other device conditions).
206 void StartProcessingIfConnected(); 203 void StartProcessingIfConnected();
207 204
208 // Check the request queue, and schedule a task corresponding 205 // Check the request queue, and schedule a task corresponding
209 // to the least restrictive type of request in the queue. 206 // to the least restrictive type of request in the queue.
210 void ScheduleAsNeeded(); 207 void ScheduleAsNeeded();
211 208
212 // Callback from the request picker when it has chosen our next request. 209 // Callback from the request picker when it has chosen our next request.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 base::TimeDelta offliner_timeout_; 314 base::TimeDelta offliner_timeout_;
318 // Allows us to pass a weak pointer to callbacks. 315 // Allows us to pass a weak pointer to callbacks.
319 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 316 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
320 317
321 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 318 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
322 }; 319 };
323 320
324 } // namespace offline_pages 321 } // namespace offline_pages
325 322
326 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 323 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698