Index: components/offline_pages/background/request_coordinator.cc |
diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc |
index 4f0bef7d3b876fac3701cf0f919f765d586f06ea..ef1dad159f02b7e305f3cbba6550efbe089aa299 100644 |
--- a/components/offline_pages/background/request_coordinator.cc |
+++ b/components/offline_pages/background/request_coordinator.cc |
@@ -51,6 +51,10 @@ int64_t GenerateOfflineId() { |
return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1; |
} |
+// In case we start processing from SavePageLater, we need a callback, but there |
+// is nothing for it to do. |
+void EmptySchedulerCallback(bool started) {} |
+ |
} // namespace |
RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
@@ -59,6 +63,8 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
std::unique_ptr<Scheduler> scheduler) |
: is_busy_(false), |
is_stopped_(false), |
+ use_test_connection_type_(false), |
+ test_connection_type_(), |
offliner_(nullptr), |
policy_(std::move(policy)), |
factory_(std::move(factory)), |
@@ -183,12 +189,37 @@ void RequestCoordinator::ResumeRequests( |
// TODO: Should we also schedule a task, in case there is not one scheduled? |
} |
+net::NetworkChangeNotifier::ConnectionType |
+RequestCoordinator::GetConnectionType() { |
dougarnett
2016/08/25 21:03:11
indentation?
|
+ // If we have a connection type set for test, use that. |
+ if (use_test_connection_type_) |
+ return test_connection_type_; |
+ |
+ return net::NetworkChangeNotifier::GetConnectionType(); |
+} |
+ |
void RequestCoordinator::AddRequestResultCallback( |
RequestQueue::AddRequestResult result, |
const SavePageRequest& request) { |
NotifyAdded(request); |
// Inform the scheduler that we have an outstanding task.. |
scheduler_->Schedule(GetTriggerConditionsForUserRequest()); |
+ |
+ // If it makes sense, start processing now. |
+ if (is_busy_) return; |
+ |
+ // Check for network |
+ net::NetworkChangeNotifier::ConnectionType connection = GetConnectionType(); |
+ |
+ if ((connection != |
+ net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) && |
+ request.user_requested()) { |
+ // Create device conditions. |
+ DeviceConditions device_conditions(false, 0, connection); |
+ |
+ // Start processing if it makes sense. (net, user requested) |
+ StartProcessing(device_conditions, base::Bind(&EmptySchedulerCallback)); |
+ } |
} |
// Called in response to updating a request in the request queue. |