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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 2812083002: Skip collection and upload of metrics if offline.
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 #include "components/metrics/metrics_log_uploader.h" 150 #include "components/metrics/metrics_log_uploader.h"
151 #include "components/metrics/metrics_pref_names.h" 151 #include "components/metrics/metrics_pref_names.h"
152 #include "components/metrics/metrics_rotation_scheduler.h" 152 #include "components/metrics/metrics_rotation_scheduler.h"
153 #include "components/metrics/metrics_service_client.h" 153 #include "components/metrics/metrics_service_client.h"
154 #include "components/metrics/metrics_state_manager.h" 154 #include "components/metrics/metrics_state_manager.h"
155 #include "components/metrics/stability_metrics_provider.h" 155 #include "components/metrics/stability_metrics_provider.h"
156 #include "components/metrics/url_constants.h" 156 #include "components/metrics/url_constants.h"
157 #include "components/prefs/pref_registry_simple.h" 157 #include "components/prefs/pref_registry_simple.h"
158 #include "components/prefs/pref_service.h" 158 #include "components/prefs/pref_service.h"
159 #include "components/variations/entropy_provider.h" 159 #include "components/variations/entropy_provider.h"
160 #include "net/base/network_change_notifier.h"
Steven Holte 2017/04/12 23:26:23 I don't think net/ is allowed here, so this probab
160 161
161 namespace metrics { 162 namespace metrics {
162 163
163 namespace { 164 namespace {
164 165
165 // This drops records if the number of events (user action and omnibox) exceeds 166 // This drops records if the number of events (user action and omnibox) exceeds
166 // the kEventLimit. 167 // the kEventLimit.
167 const base::Feature kUMAThrottleEvents{"UMAThrottleEvents", 168 const base::Feature kUMAThrottleEvents{"UMAThrottleEvents",
168 base::FEATURE_ENABLED_BY_DEFAULT}; 169 base::FEATURE_ENABLED_BY_DEFAULT};
169 170
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 // TODO(stuartmorgan): Call Stop() on the scheduler when reporting and/or 721 // TODO(stuartmorgan): Call Stop() on the scheduler when reporting and/or
721 // recording are turned off instead of letting it fire and then aborting. 722 // recording are turned off instead of letting it fire and then aborting.
722 if (idle_since_last_transmission_ || 723 if (idle_since_last_transmission_ ||
723 !recording_active() || 724 !recording_active() ||
724 (!reporting_active() && state_ >= SENDING_LOGS)) { 725 (!reporting_active() && state_ >= SENDING_LOGS)) {
725 rotation_scheduler_->Stop(); 726 rotation_scheduler_->Stop();
726 rotation_scheduler_->RotationFinished(); 727 rotation_scheduler_->RotationFinished();
727 return; 728 return;
728 } 729 }
729 730
731 // Don't try to send existing logs or to collecting something new if there is
732 // no network connection. A cumulative log will be created at the next (or
733 // future) upload time when a network connection is available.
734 if (net::NetworkChangeNotifier::IsOffline())
Steven Holte 2017/04/12 23:11:37 You should call (or schedule a call to) rotation_s
Steven Holte 2017/04/12 23:26:23 Actually after rereading the code, this will also
bcwhite 2017/04/18 14:56:44 Sounds like it's not worth it, then. One (or even
735 return;
736
730 // If there are unsent logs, send the next one. If not, start the asynchronous 737 // If there are unsent logs, send the next one. If not, start the asynchronous
731 // process of finalizing the current log for upload. 738 // process of finalizing the current log for upload.
732 if (state_ == SENDING_LOGS && has_unsent_logs()) { 739 if (state_ == SENDING_LOGS && has_unsent_logs()) {
733 reporting_service_.Start(); 740 reporting_service_.Start();
734 rotation_scheduler_->RotationFinished(); 741 rotation_scheduler_->RotationFinished();
735 } else { 742 } else {
736 // There are no logs left to send, so start creating a new one. 743 // There are no logs left to send, so start creating a new one.
737 client_->CollectFinalMetricsForLog( 744 client_->CollectFinalMetricsForLog(
738 base::Bind(&MetricsService::OnFinalLogInfoCollectionDone, 745 base::Bind(&MetricsService::OnFinalLogInfoCollectionDone,
739 self_ptr_factory_.GetWeakPtr())); 746 self_ptr_factory_.GetWeakPtr()));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 // Redundant setting to assure that we always reset this value at shutdown 1000 // Redundant setting to assure that we always reset this value at shutdown
994 // (and that we don't use some alternate path, and not call LogCleanShutdown). 1001 // (and that we don't use some alternate path, and not call LogCleanShutdown).
995 clean_shutdown_status_ = CLEANLY_SHUTDOWN; 1002 clean_shutdown_status_ = CLEANLY_SHUTDOWN;
996 client_->OnLogCleanShutdown(); 1003 client_->OnLogCleanShutdown();
997 clean_exit_beacon_.WriteBeaconValue(true); 1004 clean_exit_beacon_.WriteBeaconValue(true);
998 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); 1005 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_);
999 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); 1006 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed);
1000 } 1007 }
1001 1008
1002 } // namespace metrics 1009 } // namespace metrics
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698