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

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

Issue 2466343003: [Offline Pages] Adds UMA for effective network connection on api calls. (Closed)
Patch Set: Removed a couple TODO comments and a log message Created 4 years, 1 month 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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
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
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 if (network_quality_estimator_) {
352 UMA_HISTOGRAM_ENUMERATION(
353 "OfflinePages.Background.EffectiveConnectionType.RemoveRequests",
354 network_quality_estimator_->GetEffectiveConnectionType(),
355 net::EFFECTIVE_CONNECTION_TYPE_LAST);
356 }
357
325 if (canceled) 358 if (canceled)
326 TryNextRequest(); 359 TryNextRequest();
327 } 360 }
328 361
329 void RequestCoordinator::PauseRequests( 362 void RequestCoordinator::PauseRequests(
330 const std::vector<int64_t>& request_ids) { 363 const std::vector<int64_t>& request_ids) {
331 bool canceled = CancelActiveRequestIfItMatches(request_ids); 364 bool canceled = CancelActiveRequestIfItMatches(request_ids);
332 queue_->ChangeRequestsState( 365 queue_->ChangeRequestsState(
333 request_ids, SavePageRequest::RequestState::PAUSED, 366 request_ids, SavePageRequest::RequestState::PAUSED,
334 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, 367 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback,
335 weak_ptr_factory_.GetWeakPtr())); 368 weak_ptr_factory_.GetWeakPtr()));
336 369
370 // Record the network quality when this request is made.
371 if (network_quality_estimator_) {
372 UMA_HISTOGRAM_ENUMERATION(
373 "OfflinePages.Background.EffectiveConnectionType.PauseRequests",
374 network_quality_estimator_->GetEffectiveConnectionType(),
375 net::EFFECTIVE_CONNECTION_TYPE_LAST);
376 }
377
337 if (canceled) 378 if (canceled)
338 TryNextRequest(); 379 TryNextRequest();
339 } 380 }
340 381
341 void RequestCoordinator::ResumeRequests( 382 void RequestCoordinator::ResumeRequests(
342 const std::vector<int64_t>& request_ids) { 383 const std::vector<int64_t>& request_ids) {
343 queue_->ChangeRequestsState( 384 queue_->ChangeRequestsState(
344 request_ids, SavePageRequest::RequestState::AVAILABLE, 385 request_ids, SavePageRequest::RequestState::AVAILABLE,
345 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback, 386 base::Bind(&RequestCoordinator::UpdateMultipleRequestsCallback,
346 weak_ptr_factory_.GetWeakPtr())); 387 weak_ptr_factory_.GetWeakPtr()));
388
389 // Record the network quality when this request is made.
390 if (network_quality_estimator_) {
391 UMA_HISTOGRAM_ENUMERATION(
392 "OfflinePages.Background.EffectiveConnectionType.ResumeRequests",
393 network_quality_estimator_->GetEffectiveConnectionType(),
394 net::EFFECTIVE_CONNECTION_TYPE_LAST);
395 }
396
347 // Schedule a task, in case there is not one scheduled. 397 // Schedule a task, in case there is not one scheduled.
348 ScheduleAsNeeded(); 398 ScheduleAsNeeded();
349 } 399 }
350 400
351 net::NetworkChangeNotifier::ConnectionType 401 net::NetworkChangeNotifier::ConnectionType
352 RequestCoordinator::GetConnectionType() { 402 RequestCoordinator::GetConnectionType() {
353 // If we have a connection type set for test, use that. 403 // If we have a connection type set for test, use that.
354 if (use_test_connection_type_) 404 if (use_test_connection_type_)
355 return test_connection_type_; 405 return test_connection_type_;
356 406
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 return OfflinerImmediateStartStatus::BUSY; 537 return OfflinerImmediateStartStatus::BUSY;
488 538
489 // Make sure we are not on svelte device to start immediately. 539 // Make sure we are not on svelte device to start immediately.
490 if (is_low_end_device_) { 540 if (is_low_end_device_) {
491 DVLOG(2) << "low end device, returning"; 541 DVLOG(2) << "low end device, returning";
492 // Let the scheduler know we are done processing and failed due to svelte. 542 // Let the scheduler know we are done processing and failed due to svelte.
493 immediate_schedule_callback_.Run(false); 543 immediate_schedule_callback_.Run(false);
494 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE; 544 return OfflinerImmediateStartStatus::NOT_STARTED_ON_SVELTE;
495 } 545 }
496 546
497 if (network_quality_estimator_) {
498 // TODO(dougarnett): Add UMA for quality type experienced.
499 net::EffectiveConnectionType quality =
500 network_quality_estimator_->GetEffectiveConnectionType();
501 VLOG(2) << "TryImmediateStart: Quality estimate "
502 << static_cast<int>(quality);
503 }
504
505 if (GetConnectionType() == 547 if (GetConnectionType() ==
506 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE) 548 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE)
507 return OfflinerImmediateStartStatus::NO_CONNECTION; 549 return OfflinerImmediateStartStatus::NO_CONNECTION;
508 550
509 // Start processing with manufactured conservative battery conditions 551 // Start processing with manufactured conservative battery conditions
510 // (i.e., assume no battery). 552 // (i.e., assume no battery).
511 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java). 553 // TODO(dougarnett): Obtain actual battery conditions (from Android/Java).
512 554
513 DeviceConditions device_conditions(false, 0, GetConnectionType()); 555 DeviceConditions device_conditions(false, 0, GetConnectionType());
514 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW, 556 if (StartProcessingInternal(ProcessingWindowState::IMMEDIATE_WINDOW,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 856
815 ClientPolicyController* RequestCoordinator::GetPolicyController() { 857 ClientPolicyController* RequestCoordinator::GetPolicyController() {
816 return policy_controller_.get(); 858 return policy_controller_.get();
817 } 859 }
818 860
819 void RequestCoordinator::Shutdown() { 861 void RequestCoordinator::Shutdown() {
820 network_quality_estimator_ = nullptr; 862 network_quality_estimator_ = nullptr;
821 } 863 }
822 864
823 } // namespace offline_pages 865 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698