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