| 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 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, | 41 RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| 42 std::unique_ptr<OfflinerFactory> factory, | 42 std::unique_ptr<OfflinerFactory> factory, |
| 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(const GURL& url, const ClientId& client_id); | 50 bool SavePageLater( |
| 51 const GURL& url, const ClientId& client_id, bool was_user_reqeusted); |
| 51 | 52 |
| 52 // Starts processing of one or more queued save page later requests. | 53 // Starts processing of one or more queued save page later requests. |
| 53 // Returns whether processing was started and that caller should expect | 54 // Returns whether processing was started and that caller should expect |
| 54 // a callback. If processing was already active, returns false. | 55 // a callback. If processing was already active, returns false. |
| 55 bool StartProcessing(const DeviceConditions& device_conditions, | 56 bool StartProcessing(const DeviceConditions& device_conditions, |
| 56 const base::Callback<void(bool)>& callback); | 57 const base::Callback<void(bool)>& callback); |
| 57 | 58 |
| 58 // Stops the current request processing if active. This is a way for | 59 // Stops the current request processing if active. This is a way for |
| 59 // caller to abort processing; otherwise, processing will complete on | 60 // caller to abort processing; otherwise, processing will complete on |
| 60 // its own. In either case, the callback will be called when processing | 61 // its own. In either case, the callback will be called when processing |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void TryNextRequest(); | 117 void TryNextRequest(); |
| 117 | 118 |
| 118 // Returns the appropriate offliner to use, getting a new one from the factory | 119 // Returns the appropriate offliner to use, getting a new one from the factory |
| 119 // if needed. | 120 // if needed. |
| 120 void GetOffliner(); | 121 void GetOffliner(); |
| 121 | 122 |
| 122 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { | 123 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { |
| 123 offliner_timeout_ = timeout; | 124 offliner_timeout_ = timeout; |
| 124 } | 125 } |
| 125 | 126 |
| 127 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { |
| 128 current_conditions_.reset(new DeviceConditions(current_conditions)); |
| 129 } |
| 130 |
| 126 friend class RequestCoordinatorTest; | 131 friend class RequestCoordinatorTest; |
| 127 | 132 |
| 128 // The offliner can only handle one request at a time - if the offliner is | 133 // The offliner can only handle one request at a time - if the offliner is |
| 129 // busy, prevent other requests. This flag marks whether the offliner is in | 134 // busy, prevent other requests. This flag marks whether the offliner is in |
| 130 // use. | 135 // use. |
| 131 bool is_busy_; | 136 bool is_busy_; |
| 132 // True if the current request has been canceled. | 137 // True if the current request has been canceled. |
| 133 bool is_canceled_; | 138 bool is_canceled_; |
| 134 // How long to wait for an offliner request before giving up. | 139 // How long to wait for an offliner request before giving up. |
| 135 base::TimeDelta offliner_timeout_; | 140 base::TimeDelta offliner_timeout_; |
| 136 // Unowned pointer to the current offliner, if any. | 141 // Unowned pointer to the current offliner, if any. |
| 137 Offliner* offliner_; | 142 Offliner* offliner_; |
| 143 // Last known conditions for network, battery |
| 144 std::unique_ptr<DeviceConditions> current_conditions_; |
| 138 // RequestCoordinator takes over ownership of the policy | 145 // RequestCoordinator takes over ownership of the policy |
| 139 std::unique_ptr<OfflinerPolicy> policy_; | 146 std::unique_ptr<OfflinerPolicy> policy_; |
| 140 // OfflinerFactory. Used to create offline pages. Owned. | 147 // OfflinerFactory. Used to create offline pages. Owned. |
| 141 std::unique_ptr<OfflinerFactory> factory_; | 148 std::unique_ptr<OfflinerFactory> factory_; |
| 142 // RequestQueue. Used to store incoming requests. Owned. | 149 // RequestQueue. Used to store incoming requests. Owned. |
| 143 std::unique_ptr<RequestQueue> queue_; | 150 std::unique_ptr<RequestQueue> queue_; |
| 144 // Scheduler. Used to request a callback when network is available. Owned. | 151 // Scheduler. Used to request a callback when network is available. Owned. |
| 145 std::unique_ptr<Scheduler> scheduler_; | 152 std::unique_ptr<Scheduler> scheduler_; |
| 146 // Status of the most recent offlining. | 153 // Status of the most recent offlining. |
| 147 Offliner::RequestStatus last_offlining_status_; | 154 Offliner::RequestStatus last_offlining_status_; |
| 148 // Class to choose which request to schedule next | 155 // Class to choose which request to schedule next |
| 149 std::unique_ptr<RequestPicker> picker_; | 156 std::unique_ptr<RequestPicker> picker_; |
| 150 // Calling this returns to the scheduler across the JNI bridge. | 157 // Calling this returns to the scheduler across the JNI bridge. |
| 151 base::Callback<void(bool)> scheduler_callback_; | 158 base::Callback<void(bool)> scheduler_callback_; |
| 152 // Logger to record events. | 159 // Logger to record events. |
| 153 RequestCoordinatorEventLogger event_logger_; | 160 RequestCoordinatorEventLogger event_logger_; |
| 154 // Timer to watch for pre-render attempts running too long. | 161 // Timer to watch for pre-render attempts running too long. |
| 155 base::OneShotTimer watchdog_timer_; | 162 base::OneShotTimer watchdog_timer_; |
| 156 // Allows us to pass a weak pointer to callbacks. | 163 // Allows us to pass a weak pointer to callbacks. |
| 157 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; | 164 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; |
| 158 | 165 |
| 159 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); | 166 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); |
| 160 }; | 167 }; |
| 161 | 168 |
| 162 } // namespace offline_pages | 169 } // namespace offline_pages |
| 163 | 170 |
| 164 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ | 171 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ |
| OLD | NEW |