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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 public: | 48 public: |
| 49 virtual ~Observer() = default; | 49 virtual ~Observer() = default; |
| 50 | 50 |
| 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 enum class RequestAvailability { | |
| 59 AVAILABLE_TO_OFFLINER, | |
| 60 DISABLED_TO_OFFLINER, | |
| 61 }; | |
| 62 | |
| 58 // Callback to report when a request was available. | 63 // Callback to report when a request was available. |
| 59 typedef base::Callback<void(const SavePageRequest& request)> | 64 typedef base::Callback<void(const SavePageRequest& request)> |
| 60 RequestPickedCallback; | 65 RequestPickedCallback; |
| 61 // Callback to report when no request was available. | 66 // Callback to report when no request was available. |
| 62 typedef base::Callback<void(bool)> RequestNotPickedCallback; | 67 typedef base::Callback<void(bool)> RequestNotPickedCallback; |
| 63 | 68 |
| 64 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 69 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| 65 std::unique_ptr<OfflinerFactory> factory, | 70 std::unique_ptr<OfflinerFactory> factory, |
| 66 std::unique_ptr<RequestQueue> queue, | 71 std::unique_ptr<RequestQueue> queue, |
| 67 std::unique_ptr<Scheduler> scheduler, | 72 std::unique_ptr<Scheduler> scheduler, |
| 68 net::NetworkQualityEstimator::NetworkQualityProvider* | 73 net::NetworkQualityEstimator::NetworkQualityProvider* |
| 69 network_quality_estimator); | 74 network_quality_estimator); |
| 70 | 75 |
| 71 ~RequestCoordinator() override; | 76 ~RequestCoordinator() override; |
| 72 | 77 |
| 73 // Queues |request| to later load and save when system conditions allow. | 78 // Queues |request| to later load and save when system conditions allow. |
| 74 // Returns true if the page could be queued successfully. | 79 // Returns an id if the page could be queued successfully, 0L otherwise. |
| 75 bool SavePageLater( | 80 int64_t SavePageLater(const GURL& url, |
| 76 const GURL& url, const ClientId& client_id, bool user_reqeusted); | 81 const ClientId& client_id, |
| 82 bool user_reqeusted, | |
|
Dmitry Titov
2016/10/05 22:28:19
typo: user_reqeusted -> user_requested
Pete Williamson
2016/10/05 22:57:46
Nice catch! Done.
| |
| 83 RequestAvailability availability); | |
|
Dmitry Titov
2016/10/05 22:28:19
I'd rather have a "bool do_not_process" or "bool b
Pete Williamson
2016/10/05 22:57:46
I think that FGorski had the opposite feedback in
| |
| 77 | 84 |
| 78 // Callback specifying which request IDs were actually removed. | 85 // Callback specifying which request IDs were actually removed. |
| 79 typedef base::Callback<void( | 86 typedef base::Callback<void( |
| 80 const RequestQueue::UpdateMultipleRequestResults&)> | 87 const RequestQueue::UpdateMultipleRequestResults&)> |
| 81 RemoveRequestsCallback; | 88 RemoveRequestsCallback; |
| 82 | 89 |
| 83 // Remove a list of requests by |request_id|. This removes requests from the | 90 // Remove a list of requests by |request_id|. This removes requests from the |
| 84 // request queue, and cancels an in-progress prerender. | 91 // request queue, and cancels an in-progress prerender. |
| 85 void RemoveRequests(const std::vector<int64_t>& request_ids, | 92 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 86 const RemoveRequestsCallback& callback); | 93 const RemoveRequestsCallback& callback); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 104 // a callback. If processing was already active, returns false. | 111 // a callback. If processing was already active, returns false. |
| 105 bool StartProcessing(const DeviceConditions& device_conditions, | 112 bool StartProcessing(const DeviceConditions& device_conditions, |
| 106 const base::Callback<void(bool)>& callback); | 113 const base::Callback<void(bool)>& callback); |
| 107 | 114 |
| 108 // Stops the current request processing if active. This is a way for | 115 // Stops the current request processing if active. This is a way for |
| 109 // caller to abort processing; otherwise, processing will complete on | 116 // caller to abort processing; otherwise, processing will complete on |
| 110 // its own. In either case, the callback will be called when processing | 117 // its own. In either case, the callback will be called when processing |
| 111 // is stopped or complete. | 118 // is stopped or complete. |
| 112 void StopProcessing(Offliner::RequestStatus stop_status); | 119 void StopProcessing(Offliner::RequestStatus stop_status); |
| 113 | 120 |
| 121 // Used to denote that the foreground thread is ready for the offliner | |
| 122 // to start work on a previously entered, but unavailable request. | |
| 123 void MakeAvailableToOffliner(int64_t request_id); | |
| 124 | |
| 125 // If a request that is unavailable to the offliner is finished elsewhere, | |
| 126 // (by the tab helper synchronous download), send a notificaiton that it | |
| 127 // succeeded through our notificaiton system. | |
| 128 void MarkRequestCompleted(int64_t request_id); | |
| 129 | |
| 114 const Scheduler::TriggerConditions GetTriggerConditions( | 130 const Scheduler::TriggerConditions GetTriggerConditions( |
| 115 const bool user_requested); | 131 const bool user_requested); |
| 116 | 132 |
| 117 // A way for tests to set the callback in use when an operation is over. | 133 // A way for tests to set the callback in use when an operation is over. |
| 118 void SetProcessingCallbackForTest(const base::Callback<void(bool)> callback) { | 134 void SetProcessingCallbackForTest(const base::Callback<void(bool)> callback) { |
| 119 scheduler_callback_ = callback; | 135 scheduler_callback_ = callback; |
| 120 } | 136 } |
| 121 | 137 |
| 122 // Observers implementing the RequestCoordinator::Observer interface can | 138 // Observers implementing the RequestCoordinator::Observer interface can |
| 123 // register here to get notifications of changes to request state. This | 139 // register here to get notifications of changes to request state. This |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 base::TimeDelta offliner_timeout_; | 333 base::TimeDelta offliner_timeout_; |
| 318 // Allows us to pass a weak pointer to callbacks. | 334 // Allows us to pass a weak pointer to callbacks. |
| 319 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 335 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 320 | 336 |
| 321 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 337 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 322 }; | 338 }; |
| 323 | 339 |
| 324 } // namespace offline_pages | 340 } // namespace offline_pages |
| 325 | 341 |
| 326 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 342 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |