| 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 #include "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "components/offline_pages/background/offliner_factory.h" | 14 #include "components/offline_pages/background/offliner_factory.h" |
| 14 #include "components/offline_pages/background/offliner_policy.h" | 15 #include "components/offline_pages/background/offliner_policy.h" |
| 15 #include "components/offline_pages/background/request_picker.h" | 16 #include "components/offline_pages/background/request_picker.h" |
| 16 #include "components/offline_pages/background/save_page_request.h" | 17 #include "components/offline_pages/background/save_page_request.h" |
| 17 #include "components/offline_pages/offline_page_item.h" | 18 #include "components/offline_pages/offline_page_item.h" |
| 18 | 19 |
| 19 namespace offline_pages { | 20 namespace offline_pages { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 23 |
| 24 // Records the final request status UMA for an offlining request. This should |
| 25 // only be called once per Offliner::LoadAndSave request. |
| 26 void RecordOfflinerResultUMA(Offliner::RequestStatus request_status) { |
| 27 UMA_HISTOGRAM_ENUMERATION("OfflinePages.Background.OfflinerRequestStatus", |
| 28 request_status, |
| 29 Offliner::RequestStatus::STATUS_COUNT); |
| 30 } |
| 31 |
| 22 // TODO(dougarnett/petewil): Move to Policy object. Also consider lower minimum | 32 // TODO(dougarnett/petewil): Move to Policy object. Also consider lower minimum |
| 23 // battery percentage once there is some processing time limits in place. | 33 // battery percentage once there is some processing time limits in place. |
| 24 const Scheduler::TriggerConditions kUserRequestTriggerConditions( | 34 const Scheduler::TriggerConditions kUserRequestTriggerConditions( |
| 25 false /* require_power_connected */, | 35 false /* require_power_connected */, |
| 26 50 /* minimum_battery_percentage */, | 36 50 /* minimum_battery_percentage */, |
| 27 false /* require_unmetered_network */); | 37 false /* require_unmetered_network */); |
| 28 | 38 |
| 29 // Timeout is 2.5 minutes based on the size of Marshmallow doze mode | 39 // Timeout is 2.5 minutes based on the size of Marshmallow doze mode |
| 30 // maintenance window (3 minutes) | 40 // maintenance window (3 minutes) |
| 31 // TODO(petewil): Find the optimal timeout based on data for 2G connections and | 41 // TODO(petewil): Find the optimal timeout based on data for 2G connections and |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // TODO(petewil): Determine trigger conditions from policy. | 92 // TODO(petewil): Determine trigger conditions from policy. |
| 83 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); | 93 scheduler_->Schedule(GetTriggerConditionsForUserRequest()); |
| 84 } | 94 } |
| 85 | 95 |
| 86 // Called in response to updating a request in the request queue. | 96 // Called in response to updating a request in the request queue. |
| 87 void RequestCoordinator::UpdateRequestCallback( | 97 void RequestCoordinator::UpdateRequestCallback( |
| 88 RequestQueue::UpdateRequestResult result) {} | 98 RequestQueue::UpdateRequestResult result) {} |
| 89 | 99 |
| 90 void RequestCoordinator::StopProcessing() { | 100 void RequestCoordinator::StopProcessing() { |
| 91 is_canceled_ = true; | 101 is_canceled_ = true; |
| 92 if (offliner_ && is_busy_) | 102 if (offliner_ && is_busy_) { |
| 93 offliner_->Cancel(); | 103 offliner_->Cancel(); |
| 104 RecordOfflinerResultUMA( |
| 105 Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED); |
| 106 } |
| 94 | 107 |
| 95 // Let the scheduler know we are done processing. | 108 // Let the scheduler know we are done processing. |
| 96 scheduler_callback_.Run(true); | 109 scheduler_callback_.Run(true); |
| 97 } | 110 } |
| 98 | 111 |
| 99 // Returns true if the caller should expect a callback, false otherwise. For | 112 // Returns true if the caller should expect a callback, false otherwise. For |
| 100 // instance, this would return false if a request is already in progress. | 113 // instance, this would return false if a request is already in progress. |
| 101 bool RequestCoordinator::StartProcessing( | 114 bool RequestCoordinator::StartProcessing( |
| 102 const DeviceConditions& device_conditions, | 115 const DeviceConditions& device_conditions, |
| 103 const base::Callback<void(bool)>& callback) { | 116 const base::Callback<void(bool)>& callback) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 177 |
| 165 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, | 178 void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| 166 Offliner::RequestStatus status) { | 179 Offliner::RequestStatus status) { |
| 167 DVLOG(2) << "offliner finished, saved: " | 180 DVLOG(2) << "offliner finished, saved: " |
| 168 << (status == Offliner::RequestStatus::SAVED) << ", status: " | 181 << (status == Offliner::RequestStatus::SAVED) << ", status: " |
| 169 << (int) status << ", " << __FUNCTION__; | 182 << (int) status << ", " << __FUNCTION__; |
| 170 event_logger_.RecordSavePageRequestUpdated( | 183 event_logger_.RecordSavePageRequestUpdated( |
| 171 request.client_id().name_space, | 184 request.client_id().name_space, |
| 172 "Saved", | 185 "Saved", |
| 173 request.request_id()); | 186 request.request_id()); |
| 187 RecordOfflinerResultUMA(status); |
| 174 last_offlining_status_ = status; | 188 last_offlining_status_ = status; |
| 175 watchdog_timer_.Stop(); | 189 watchdog_timer_.Stop(); |
| 176 | 190 |
| 177 is_busy_ = false; | 191 is_busy_ = false; |
| 178 | 192 |
| 179 // If the request succeeded, remove it from the Queue and maybe schedule | 193 // If the request succeeded, remove it from the Queue and maybe schedule |
| 180 // another one. | 194 // another one. |
| 181 if (status == Offliner::RequestStatus::SAVED) { | 195 if (status == Offliner::RequestStatus::SAVED) { |
| 182 queue_->RemoveRequest(request.request_id(), | 196 queue_->RemoveRequest(request.request_id(), |
| 183 base::Bind(&RequestCoordinator::UpdateRequestCallback, | 197 base::Bind(&RequestCoordinator::UpdateRequestCallback, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 195 return kUserRequestTriggerConditions; | 209 return kUserRequestTriggerConditions; |
| 196 } | 210 } |
| 197 | 211 |
| 198 void RequestCoordinator::GetOffliner() { | 212 void RequestCoordinator::GetOffliner() { |
| 199 if (!offliner_) { | 213 if (!offliner_) { |
| 200 offliner_ = factory_->GetOffliner(policy_.get()); | 214 offliner_ = factory_->GetOffliner(policy_.get()); |
| 201 } | 215 } |
| 202 } | 216 } |
| 203 | 217 |
| 204 } // namespace offline_pages | 218 } // namespace offline_pages |
| OLD | NEW |