Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: components/offline_pages/background/request_coordinator.h

Issue 2279913002: Start processing immediately if there is network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 202
203 void TryNextRequest(); 203 void TryNextRequest();
204 204
205 // If there is an active request in the list, cancel that request. 205 // If there is an active request in the list, cancel that request.
206 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids); 206 bool CancelActiveRequestIfItMatches(const std::vector<int64_t>& request_ids);
207 207
208 // Returns the appropriate offliner to use, getting a new one from the factory 208 // Returns the appropriate offliner to use, getting a new one from the factory
209 // if needed. 209 // if needed.
210 void GetOffliner(); 210 void GetOffliner();
211 211
212 // Method to wrap calls to getting the connection type so it can be
213 // changed for tests.
214 net::NetworkChangeNotifier::ConnectionType GetConnectionType();
215
216 void SetNetworkConditionsForTest(
217 net::NetworkChangeNotifier::ConnectionType connection) {
218 use_test_connection_type_ = true;
219 test_connection_type_ = connection;
220 }
221
212 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { 222 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) {
213 offliner_timeout_ = timeout; 223 offliner_timeout_ = timeout;
214 } 224 }
215 225
216 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) { 226 void SetDeviceConditionsForTest(DeviceConditions& current_conditions) {
217 current_conditions_.reset(new DeviceConditions(current_conditions)); 227 current_conditions_.reset(new DeviceConditions(current_conditions));
218 } 228 }
219 229
220 friend class RequestCoordinatorTest; 230 friend class RequestCoordinatorTest;
221 231
222 // The offliner can only handle one request at a time - if the offliner is 232 // The offliner can only handle one request at a time - if the offliner is
223 // busy, prevent other requests. This flag marks whether the offliner is in 233 // busy, prevent other requests. This flag marks whether the offliner is in
224 // use. 234 // use.
225 bool is_busy_; 235 bool is_busy_;
226 // True if the current request has been canceled. 236 // True if the current request has been canceled.
227 bool is_stopped_; 237 bool is_stopped_;
238 // True if we should use the test connection type instead of the actual type.
239 bool use_test_connection_type_;
240 // For use by tests, a fake network connection type
241 net::NetworkChangeNotifier::ConnectionType test_connection_type_;
228 // Unowned pointer to the current offliner, if any. 242 // Unowned pointer to the current offliner, if any.
229 Offliner* offliner_; 243 Offliner* offliner_;
230 base::Time operation_start_time_; 244 base::Time operation_start_time_;
231 // The observers. 245 // The observers.
232 base::ObserverList<Observer> observers_; 246 base::ObserverList<Observer> observers_;
233 // Last known conditions for network, battery 247 // Last known conditions for network, battery
234 std::unique_ptr<DeviceConditions> current_conditions_; 248 std::unique_ptr<DeviceConditions> current_conditions_;
235 // RequestCoordinator takes over ownership of the policy 249 // RequestCoordinator takes over ownership of the policy
236 std::unique_ptr<OfflinerPolicy> policy_; 250 std::unique_ptr<OfflinerPolicy> policy_;
237 // OfflinerFactory. Used to create offline pages. Owned. 251 // OfflinerFactory. Used to create offline pages. Owned.
(...skipping 18 matching lines...) Expand all
256 base::TimeDelta offliner_timeout_; 270 base::TimeDelta offliner_timeout_;
257 // Allows us to pass a weak pointer to callbacks. 271 // Allows us to pass a weak pointer to callbacks.
258 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_; 272 base::WeakPtrFactory<RequestCoordinator> weak_ptr_factory_;
259 273
260 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator); 274 DISALLOW_COPY_AND_ASSIGN(RequestCoordinator);
261 }; 275 };
262 276
263 } // namespace offline_pages 277 } // namespace offline_pages
264 278
265 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_ 279 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_COORDINATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698