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 // Remove a list of requests by |client_id|. This removes requests from the | 53 // Remove a list of requests by |request_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<int64_t>& request_ids); |
| 57 | 57 |
| 58 // Callback that receives the response for GetQueuedRequests. Client must | 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 | 59 // copy the result right away, it goes out of scope at the end of the |
| 60 // callback. | 60 // callback. |
| 61 typedef base::Callback<void(const std::vector<ClientId>&)> | 61 typedef base::Callback<void(const std::vector<SavePageRequest>&)> |
|
Dmitry Titov
2016/08/10 02:52:14
this is a strange type. A reference to a vector of
Pete Williamson
2016/08/10 21:15:25
We copy the SavePageRequest items into the vector,
Pete Williamson
2016/08/12 00:00:40
As we dicussed, we'll leave this behavior in for n
| |
| 62 QueuedRequestCallback; | 62 QueuedRequestCallback; |
| 63 | 63 |
| 64 // For a client namespace, get the ClientId of all requests for that | 64 // Get all save page request items in the callback. |
| 65 // namespace. | 65 void GetQueuedRequests(const QueuedRequestCallback& callback); |
|
Dmitry Titov
2016/08/10 02:52:14
Can we rename it to GetAllRequests? It does return
Pete Williamson
2016/08/10 21:15:25
Done.
| |
| 66 void GetQueuedRequests(const std::string& client_namespace, | |
| 67 const QueuedRequestCallback& callback); | |
| 68 | 66 |
| 69 // Starts processing of one or more queued save page later requests. | 67 // Starts processing of one or more queued save page later requests. |
| 70 // Returns whether processing was started and that caller should expect | 68 // Returns whether processing was started and that caller should expect |
| 71 // a callback. If processing was already active, returns false. | 69 // a callback. If processing was already active, returns false. |
| 72 bool StartProcessing(const DeviceConditions& device_conditions, | 70 bool StartProcessing(const DeviceConditions& device_conditions, |
| 73 const base::Callback<void(bool)>& callback); | 71 const base::Callback<void(bool)>& callback); |
| 74 | 72 |
| 75 // Stops the current request processing if active. This is a way for | 73 // Stops the current request processing if active. This is a way for |
| 76 // caller to abort processing; otherwise, processing will complete on | 74 // caller to abort processing; otherwise, processing will complete on |
| 77 // its own. In either case, the callback will be called when processing | 75 // its own. In either case, the callback will be called when processing |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 106 return is_canceled_; | 104 return is_canceled_; |
| 107 } | 105 } |
| 108 | 106 |
| 109 OfflineEventLogger* GetLogger() { | 107 OfflineEventLogger* GetLogger() { |
| 110 return &event_logger_; | 108 return &event_logger_; |
| 111 } | 109 } |
| 112 | 110 |
| 113 private: | 111 private: |
| 114 // Receives the results of a get from the request queue, and turns that into | 112 // Receives the results of a get from the request queue, and turns that into |
| 115 // ClientId objects for the caller of GetQueuedRequests. | 113 // ClientId objects for the caller of GetQueuedRequests. |
| 116 void GetQueuedRequestsCallback(const std::string& client_namespace, | 114 void GetQueuedRequestsCallback(const QueuedRequestCallback& callback, |
| 117 const QueuedRequestCallback& callback, | |
| 118 RequestQueue::GetRequestsResult result, | 115 RequestQueue::GetRequestsResult result, |
| 119 const std::vector<SavePageRequest>& requests); | 116 const std::vector<SavePageRequest>& requests); |
| 120 | 117 |
| 121 // Receives the result of add requests to the request queue. | 118 // Receives the result of add requests to the request queue. |
| 122 void AddRequestResultCallback(RequestQueue::AddRequestResult result, | 119 void AddRequestResultCallback(RequestQueue::AddRequestResult result, |
| 123 const SavePageRequest& request); | 120 const SavePageRequest& request); |
| 124 | 121 |
| 125 // Receives the result of update and delete requests to the request queue. | 122 // Receives the result of update and delete requests to the request queue. |
| 126 void UpdateRequestCallback(const ClientId& client_id, | 123 void UpdateRequestCallback(const ClientId& client_id, |
| 127 RequestQueue::UpdateRequestResult result); | 124 RequestQueue::UpdateRequestResult result); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 base::TimeDelta offliner_timeout_; | 189 base::TimeDelta offliner_timeout_; |
| 193 // Allows us to pass a weak pointer to callbacks. | 190 // Allows us to pass a weak pointer to callbacks. |
| 194 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 191 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 195 | 192 |
| 196 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 193 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 197 }; | 194 }; |
| 198 | 195 |
| 199 } // namespace offline_pages | 196 } // namespace offline_pages |
| 200 | 197 |
| 201 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 198 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |