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 #include "components/offline_pages/background/request_coordinator.h" | 5 #include "components/offline_pages/background/request_coordinator.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 UMA_HISTOGRAM_CUSTOM_COUNTS( | 113 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 114 "OfflinePages.Background.RequestSuccess.StartedAttemptCount", | 114 "OfflinePages.Background.RequestSuccess.StartedAttemptCount", |
| 115 request.started_attempt_count(), 1, 10, 11); | 115 request.started_attempt_count(), 1, 10, 11); |
| 116 } else { | 116 } else { |
| 117 UMA_HISTOGRAM_CUSTOM_COUNTS( | 117 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 118 "OfflinePages.Background.RequestFailure.StartedAttemptCount", | 118 "OfflinePages.Background.RequestFailure.StartedAttemptCount", |
| 119 request.started_attempt_count(), 1, 10, 11); | 119 request.started_attempt_count(), 1, 10, 11); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Record the network quality at request creation time per namespace. | |
| 124 void RecordSavePageLaterNetworkQuality( | |
| 125 const ClientId& client_id, | |
| 126 const net::EffectiveConnectionType effective_connection) { | |
| 127 // The histogram below is an expansion of the UMA_HISTOGRAM_ENUMERATION | |
| 128 // macro adapted to allow for a dynamically suffixed histogram name. | |
| 129 // Note: The factory creates and owns the histogram. | |
| 130 base::HistogramBase* histogram = base::LinearHistogram::FactoryGet( | |
| 131 AddHistogramSuffix( | |
| 132 client_id, | |
| 133 "OfflinePages.Background.EffectiveConnectionType.SavePageLater"), | |
| 134 1, net::EFFECTIVE_CONNECTION_TYPE_LAST - 1, | |
| 135 net::EFFECTIVE_CONNECTION_TYPE_LAST, | |
| 136 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 137 histogram->Add(effective_connection); | |
| 138 } | |
| 139 | |
| 123 // This should use the same algorithm as we use for OfflinePageItem, so the IDs | 140 // This should use the same algorithm as we use for OfflinePageItem, so the IDs |
| 124 // are similar. | 141 // are similar. |
| 125 int64_t GenerateOfflineId() { | 142 int64_t GenerateOfflineId() { |
| 126 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1; | 143 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1; |
| 127 } | 144 } |
| 128 | 145 |
| 129 // In case we start processing from SavePageLater, we need a callback, but there | 146 // In case we start processing from SavePageLater, we need a callback, but there |
| 130 // is nothing for it to do. | 147 // is nothing for it to do. |
| 131 void EmptySchedulerCallback(bool started) {} | 148 void EmptySchedulerCallback(bool started) {} |
| 132 | 149 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 200 |
| 184 // If the download manager is not done with the request, put it on the | 201 // If the download manager is not done with the request, put it on the |
| 185 // disabled list. | 202 // disabled list. |
| 186 if (availability == RequestAvailability::DISABLED_FOR_OFFLINER) | 203 if (availability == RequestAvailability::DISABLED_FOR_OFFLINER) |
| 187 disabled_requests_.insert(id); | 204 disabled_requests_.insert(id); |
| 188 | 205 |
| 189 // Put the request on the request queue. | 206 // Put the request on the request queue. |
| 190 queue_->AddRequest(request, | 207 queue_->AddRequest(request, |
| 191 base::Bind(&RequestCoordinator::AddRequestResultCallback, | 208 base::Bind(&RequestCoordinator::AddRequestResultCallback, |
| 192 weak_ptr_factory_.GetWeakPtr())); | 209 weak_ptr_factory_.GetWeakPtr())); |
| 210 | |
| 211 // Record the network quality when this request is made. | |
| 212 if (network_quality_estimator_) { | |
| 213 RecordSavePageLaterNetworkQuality( | |
| 214 client_id, network_quality_estimator_->GetEffectiveConnectionType()); | |
| 215 } | |
| 216 | |
| 193 return id; | 217 return id; |
| 194 } | 218 } |
| 195 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { | 219 void RequestCoordinator::GetAllRequests(const GetRequestsCallback& callback) { |
| 196 // Get all matching requests from the request queue, send them to our | 220 // Get all matching requests from the request queue, send them to our |
| 197 // callback. We bind the namespace and callback to the front of the callback | 221 // callback. We bind the namespace and callback to the front of the callback |
| 198 // param set. | 222 // param set. |
| 199 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback, | 223 queue_->GetRequests(base::Bind(&RequestCoordinator::GetQueuedRequestsCallback, |
| 200 weak_ptr_factory_.GetWeakPtr(), callback)); | 224 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 201 } | 225 } |
| 202 | 226 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 | 339 |
| 316 void RequestCoordinator::RemoveRequests( | 340 void RequestCoordinator::RemoveRequests( |
| 317 const std::vector<int64_t>& request_ids, | 341 const std::vector<int64_t>& request_ids, |
| 318 const RemoveRequestsCallback& callback) { | 342 const RemoveRequestsCallback& callback) { |
| 319 bool canceled = CancelActiveRequestIfItMatches(request_ids); | 343 bool canceled = CancelActiveRequestIfItMatches(request_ids); |
| 320 queue_->RemoveRequests( | 344 queue_->RemoveRequests( |
| 321 request_ids, | 345 request_ids, |
| 322 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback, | 346 base::Bind(&RequestCoordinator::HandleRemovedRequestsAndCallback, |
| 323 weak_ptr_factory_.GetWeakPtr(), callback, | 347 weak_ptr_factory_.GetWeakPtr(), callback, |
| 324 BackgroundSavePageResult::REMOVED)); | 348 BackgroundSavePageResult::REMOVED)); |
| 349 | |
| 350 // Record the network quality when this request is made. | |
| 351 // TODO(dougarnett): Should we update api to pass namespace so we | |
| 352 // can record per namespace? | |
| 353 if (network_quality_estimator_) { | |
|
Pete Williamson
2016/11/01 19:58:47
These three added sections are very similar - can
dewittj
2016/11/01 21:52:41
I suspect there won't be much to gain from that, s
| |
| 354 UMA_HISTOGRAM_ENUMERATION( | |
| 355 "OfflinePages.Background.EffectiveConnectionType.RemoveRequests", | |
| 356 network_quality_estimator_->GetEffectiveConnectionType(), | |
| 357 net::EFFECTIVE_CONNECTION_TYPE_LAST); | |
| 358 } | |
| 359 | |
| 325 if (canceled) | 360 if (canceled) |
| 326 TryNextRequest(); | 361 TryNextRequest(); |
| 327 } | 362 } |
| 328 | 363 |
| 329 void RequestCoordinator::PauseRequests( | 364 void RequestCoordinator::PauseRequests( |
| 330 const std::vector<int64_t>& request_ids) { | 365 const std::vector<int64_t>& request_ids) { |
| 331 bool canceled = CancelActiveRequestIfItMatches(request_ids); | 366 bool canceled = CancelActiveRequestIfItMatches(request_ids); |
| 332 queue_->ChangeRequestsState( | 367 queue_->ChangeRequestsState( |
| 333 request_ids, SavePageRequest::RequestState::PAUSED, | 368 request_ids, SavePageRequest::RequestState::PAUSED, |
| 334 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, | 369 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, |
| 335 weak_ptr_factory_.GetWeakPtr())); | 370 weak_ptr_factory_.GetWeakPtr())); |
| 336 | 371 |
| 372 // Record the network quality when this request is made. | |
| 373 if (network_quality_estimator_) { | |
| 374 UMA_HISTOGRAM_ENUMERATION( | |
| 375 "OfflinePages.Background.EffectiveConnectionType.PauseRequests", | |
| 376 network_quality_estimator_->GetEffectiveConnectionType(), | |
| 377 net::EFFECTIVE_CONNECTION_TYPE_LAST); | |
| 378 } | |
| 379 | |
| 337 if (canceled) | 380 if (canceled) |
| 338 TryNextRequest(); | 381 TryNextRequest(); |
| 339 } | 382 } |
| 340 | 383 |
| 341 void RequestCoordinator::ResumeRequests( | 384 void RequestCoordinator::ResumeRequests( |
| 342 const std::vector<int64_t>& request_ids) { | 385 const std::vector<int64_t>& request_ids) { |
| 343 queue_->ChangeRequestsState( | 386 queue_->ChangeRequestsState( |
| 344 request_ids, SavePageRequest::RequestState::AVAILABLE, | 387 request_ids, SavePageRequest::RequestState::AVAILABLE, |
| 345 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, | 388 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, |
| 346 weak_ptr_factory_.GetWeakPtr())); | 389 weak_ptr_factory_.GetWeakPtr())); |
| 390 | |
| 391 // Record the network quality when this request is made. | |
| 392 if (network_quality_estimator_) { | |
| 393 UMA_HISTOGRAM_ENUMERATION( | |
| 394 "OfflinePages.Background.EffectiveConnectionType.ResumeRequests", | |
| 395 network_quality_estimator_->GetEffectiveConnectionType(), | |
| 396 net::EFFECTIVE_CONNECTION_TYPE_LAST); | |
| 397 } | |
| 398 | |
| 347 // Schedule a task, in case there is not one scheduled. | 399 // Schedule a task, in case there is not one scheduled. |
| 348 ScheduleAsNeeded(); | 400 ScheduleAsNeeded(); |
| 349 } | 401 } |
| 350 | 402 |
| 351 net::NetworkChangeNotifier::ConnectionType | 403 net::NetworkChangeNotifier::ConnectionType |
| 352 RequestCoordinator::GetConnectionType() { | 404 RequestCoordinator::GetConnectionType() { |
| 353 // If we have a connection type set for test, use that. | 405 // If we have a connection type set for test, use that. |
| 354 if (use_test_connection_type_) | 406 if (use_test_connection_type_) |
| 355 return test_connection_type_; | 407 return test_connection_type_; |
| 356 | 408 |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 | 866 |
| 815 ClientPolicyController* RequestCoordinator::GetPolicyController() { | 867 ClientPolicyController* RequestCoordinator::GetPolicyController() { |
| 816 return policy_controller_.get(); | 868 return policy_controller_.get(); |
| 817 } | 869 } |
| 818 | 870 |
| 819 void RequestCoordinator::Shutdown() { | 871 void RequestCoordinator::Shutdown() { |
| 820 network_quality_estimator_ = nullptr; | 872 network_quality_estimator_ = nullptr; |
| 821 } | 873 } |
| 822 | 874 |
| 823 } // namespace offline_pages | 875 } // namespace offline_pages |
| OLD | NEW |