| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Remove a list of requests by |client_id|. This removes requests from the | 53 // Remove a list of requests by |client_id|. This removes requests from the |
| 54 // request queue, but does not cancel an in-progress pre-render. | 54 // request queue, but does not cancel an in-progress pre-render. |
| 55 // TODO(petewil): Add code to cancel an in-progress pre-render. | 55 // TODO(petewil): Add code to cancel an in-progress pre-render. |
| 56 void RemoveRequests(const std::vector<ClientId>& client_ids); | 56 void RemoveRequests(const std::vector<ClientId>& client_ids); |
| 57 | 57 |
| 58 // Callback that receives the response for GetQueuedRequests. Client must |
| 59 // copy the result right away, it goes out of scope at the end of the |
| 60 // callback. |
| 61 typedef base::Callback<void(const std::vector<ClientId>&)> |
| 62 QueuedRequestCallback; |
| 63 |
| 64 // For a client namespace, get the ClientId of all requests for that |
| 65 // namespace. |
| 66 void GetQueuedRequests(const std::string& client_namespace, |
| 67 const QueuedRequestCallback& callback); |
| 68 |
| 58 // Starts processing of one or more queued save page later requests. | 69 // Starts processing of one or more queued save page later requests. |
| 59 // Returns whether processing was started and that caller should expect | 70 // Returns whether processing was started and that caller should expect |
| 60 // a callback. If processing was already active, returns false. | 71 // a callback. If processing was already active, returns false. |
| 61 bool StartProcessing(const DeviceConditions& device_conditions, | 72 bool StartProcessing(const DeviceConditions& device_conditions, |
| 62 const base::Callback<void(bool)>& callback); | 73 const base::Callback<void(bool)>& callback); |
| 63 | 74 |
| 64 // Stops the current request processing if active. This is a way for | 75 // Stops the current request processing if active. This is a way for |
| 65 // caller to abort processing; otherwise, processing will complete on | 76 // caller to abort processing; otherwise, processing will complete on |
| 66 // its own. In either case, the callback will be called when processing | 77 // its own. In either case, the callback will be called when processing |
| 67 // is stopped or complete. | 78 // is stopped or complete. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 93 // the next StartProcessing() call. | 104 // the next StartProcessing() call. |
| 94 bool is_canceled() { | 105 bool is_canceled() { |
| 95 return is_canceled_; | 106 return is_canceled_; |
| 96 } | 107 } |
| 97 | 108 |
| 98 OfflineEventLogger* GetLogger() { | 109 OfflineEventLogger* GetLogger() { |
| 99 return &event_logger_; | 110 return &event_logger_; |
| 100 } | 111 } |
| 101 | 112 |
| 102 private: | 113 private: |
| 114 // Receives the results of a get from the request queue, and turns that into |
| 115 // ClientId objects for the caller of GetQueuedRequests. |
| 116 void GetQueuedRequestsCallback(const std::string& client_namespace, |
| 117 const QueuedRequestCallback& callback, |
| 118 RequestQueue::GetRequestsResult result, |
| 119 const std::vector<SavePageRequest>& requests); |
| 120 |
| 121 // Receives the result of add requests to the request queue. |
| 103 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 122 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 104 const SavePageRequest& request); | 123 const SavePageRequest& request); |
| 105 | 124 |
| 125 // Receives the result of update and delete requests to the request queue. |
| 106 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); | 126 void UpdateRequestCallback(RequestQueue::UpdateRequestResult result); |
| 107 | 127 |
| 108 // Callback from the request picker when it has chosen our next request. | 128 // Callback from the request picker when it has chosen our next request. |
| 109 void RequestPicked(const SavePageRequest& request); | 129 void RequestPicked(const SavePageRequest& request); |
| 110 | 130 |
| 111 // Callback from the request picker when no more requests are in the queue. | 131 // Callback from the request picker when no more requests are in the queue. |
| 112 void RequestQueueEmpty(); | 132 void RequestQueueEmpty(); |
| 113 | 133 |
| 114 void SendRequestToOffliner(const SavePageRequest& request); | 134 void SendRequestToOffliner(const SavePageRequest& request); |
| 115 | 135 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 base::TimeDelta offliner_timeout_; | 187 base::TimeDelta offliner_timeout_; |
| 168 // Allows us to pass a weak pointer to callbacks. | 188 // Allows us to pass a weak pointer to callbacks. |
| 169 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 189 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 170 | 190 |
| 171 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 191 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 172 }; | 192 }; |
| 173 | 193 |
| 174 } // namespace offline_pages | 194 } // namespace offline_pages |
| 175 | 195 |
| 176 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 196 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |