Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 std::unique_ptr<RequestQueue> queue, | 43 std::unique_ptr<RequestQueue> queue, |
| 44 std::unique_ptr<Scheduler> scheduler); | 44 std::unique_ptr<Scheduler> scheduler); |
| 45 | 45 |
| 46 ~RequestCoordinator() override; | 46 ~RequestCoordinator() override; |
| 47 | 47 |
| 48 // Queues |request| to later load and save when system conditions allow. | 48 // Queues |request| to later load and save when system conditions allow. |
| 49 // Returns true if the page could be queued successfully. | 49 // Returns true if the page could be queued successfully. |
| 50 bool SavePageLater( | 50 bool SavePageLater( |
| 51 const GURL& url, const ClientId& client_id, bool user_reqeusted); | 51 const GURL& url, const ClientId& client_id, bool user_reqeusted); |
| 52 | 52 |
| 53 // Callback that receives the response for GetQueuedRequests. Client must | |
| 54 // copy the result right away, it goes out of scope at the end of the | |
| 55 // callback. | |
| 56 typedef base::Callback<void(const std::vector<ClientId>&)> | |
| 57 QueuedRequestCallback; | |
| 58 | |
| 59 // For a client namespace, get the client_id of all requests for that | |
|
dougarnett
2016/08/03 04:27:19
for comment probably better "client_id" => "client
Pete Williamson
2016/08/03 20:13:44
Done.
| |
| 60 // namespace. | |
| 61 void GetQueuedRequests(const std::string& client_namespace, | |
| 62 const QueuedRequestCallback& callback); | |
| 63 | |
| 53 // Starts processing of one or more queued save page later requests. | 64 // Starts processing of one or more queued save page later requests. |
| 54 // Returns whether processing was started and that caller should expect | 65 // Returns whether processing was started and that caller should expect |
| 55 // a callback. If processing was already active, returns false. | 66 // a callback. If processing was already active, returns false. |
| 56 bool StartProcessing(const DeviceConditions& device_conditions, | 67 bool StartProcessing(const DeviceConditions& device_conditions, |
| 57 const base::Callback<void(bool)>& callback); | 68 const base::Callback<void(bool)>& callback); |
| 58 | 69 |
| 59 // Stops the current request processing if active. This is a way for | 70 // Stops the current request processing if active. This is a way for |
| 60 // caller to abort processing; otherwise, processing will complete on | 71 // caller to abort processing; otherwise, processing will complete on |
| 61 // its own. In either case, the callback will be called when processing | 72 // its own. In either case, the callback will be called when processing |
| 62 // is stopped or complete. | 73 // is stopped or complete. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 88 // the next StartProcessing() call. | 99 // the next StartProcessing() call. |
| 89 bool is_canceled() { | 100 bool is_canceled() { |
| 90 return is_canceled_; | 101 return is_canceled_; |
| 91 } | 102 } |
| 92 | 103 |
| 93 OfflineEventLogger* GetLogger() { | 104 OfflineEventLogger* GetLogger() { |
| 94 return &event_logger_; | 105 return &event_logger_; |
| 95 } | 106 } |
| 96 | 107 |
| 97 private: | 108 private: |
| 109 // Receives the results of a get from the request queue, and turns that into | |
| 110 // ClientId objects for the caller of GetQueuedRequests. | |
| 111 void GetQueuedRequestsCallback(const std::string& client_namespace, | |
| 112 QueuedRequestCallback callback, | |
|
fgorski
2016/08/03 03:13:15
const &
Pete Williamson
2016/08/03 20:13:44
Done.
| |
| 113 RequestQueue::GetRequestsResult result, | |
| 114 const std::vector<SavePageRequest>& requests); | |
| 115 | |
| 116 // Receives the result of add requests to the request queue. | |
| 98 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 117 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 99 const SavePageRequest& request); | 118 const SavePageRequest& request); |
| 100 | 119 |
| 120 // Receives the result of update and delete requests to the request queue. | |
| 101 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); | 121 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); |
| 102 | 122 |
| 103 // Callback from the request picker when it has chosen our next request. | 123 // Callback from the request picker when it has chosen our next request. |
| 104 void RequestPicked(const SavePageRequest& request); | 124 void RequestPicked(const SavePageRequest& request); |
| 105 | 125 |
| 106 // Callback from the request picker when no more requests are in the queue. | 126 // Callback from the request picker when no more requests are in the queue. |
| 107 void RequestQueueEmpty(); | 127 void RequestQueueEmpty(); |
| 108 | 128 |
| 109 void SendRequestToOffliner(const SavePageRequest& request); | 129 void SendRequestToOffliner(const SavePageRequest& request); |
| 110 | 130 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 base::TimeDelta offliner_timeout_; | 182 base::TimeDelta offliner_timeout_; |
| 163 // Allows us to pass a weak pointer to callbacks. | 183 // Allows us to pass a weak pointer to callbacks. |
| 164 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 184 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 165 | 185 |
| 166 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 186 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 167 }; | 187 }; |
| 168 | 188 |
| 169 } // namespace offline_pages | 189 } // namespace offline_pages |
| 170 | 190 |
| 171 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 191 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |