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

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

Issue 922383003: Enable UMA log uploads for cellular networks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Callback to set connection type in the scheduler Created 5 years, 10 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
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); 304 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true);
305 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); 305 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1);
306 306
307 registry->RegisterListPref(prefs::kMetricsInitialLogs); 307 registry->RegisterListPref(prefs::kMetricsInitialLogs);
308 registry->RegisterListPref(prefs::kMetricsOngoingLogs); 308 registry->RegisterListPref(prefs::kMetricsOngoingLogs);
309 309
310 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); 310 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
311 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); 311 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
312 } 312 }
313 313
314 bool Test(){ return false;}
Alexei Svitkine (slow) 2015/02/17 20:50:04 Remove this. ;)
gayane -on leave until 09-2017 2015/02/18 00:30:35 Done.
315
314 MetricsService::MetricsService(MetricsStateManager* state_manager, 316 MetricsService::MetricsService(MetricsStateManager* state_manager,
315 MetricsServiceClient* client, 317 MetricsServiceClient* client,
316 PrefService* local_state) 318 PrefService* local_state)
317 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), 319 : log_manager_(local_state, kUploadLogAvoidRetransmitSize),
318 histogram_snapshot_manager_(this), 320 histogram_snapshot_manager_(this),
319 state_manager_(state_manager), 321 state_manager_(state_manager),
320 client_(client), 322 client_(client),
321 local_state_(local_state), 323 local_state_(local_state),
322 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), 324 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state),
323 recording_active_(false), 325 recording_active_(false),
(...skipping 19 matching lines...) Expand all
343 345
344 MetricsService::~MetricsService() { 346 MetricsService::~MetricsService() {
345 DisableRecording(); 347 DisableRecording();
346 } 348 }
347 349
348 void MetricsService::InitializeMetricsRecordingState() { 350 void MetricsService::InitializeMetricsRecordingState() {
349 InitializeMetricsState(); 351 InitializeMetricsState();
350 352
351 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, 353 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload,
352 self_ptr_factory_.GetWeakPtr()); 354 self_ptr_factory_.GetWeakPtr());
353 scheduler_.reset(new MetricsReportingScheduler(callback)); 355 base::Closure func =
356 base::Bind(&MetricsService::UpdateSchedulerConnectionType,
Alexei Svitkine (slow) 2015/02/17 20:50:04 Sorry, I don't like this structure. I suggest the
gayane -on leave until 09-2017 2015/02/18 00:30:35 Done.
357 self_ptr_factory_.GetWeakPtr());
358 scheduler_.reset(new MetricsReportingScheduler(callback, func));
354 } 359 }
355 360
356 void MetricsService::Start() { 361 void MetricsService::Start() {
357 HandleIdleSinceLastTransmission(false); 362 HandleIdleSinceLastTransmission(false);
358 EnableRecording(); 363 EnableRecording();
359 EnableReporting(); 364 EnableReporting();
360 } 365 }
361 366
362 bool MetricsService::StartIfMetricsReportingEnabled() { 367 bool MetricsService::StartIfMetricsReportingEnabled() {
363 const bool enabled = state_manager_->IsMetricsReportingEnabled(); 368 const bool enabled = state_manager_->IsMetricsReportingEnabled();
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 DCHECK(IsSingleThreaded()); 1261 DCHECK(IsSingleThreaded());
1257 local_state_->SetBoolean(path, value); 1262 local_state_->SetBoolean(path, value);
1258 RecordCurrentState(local_state_); 1263 RecordCurrentState(local_state_);
1259 } 1264 }
1260 1265
1261 void MetricsService::RecordCurrentState(PrefService* pref) { 1266 void MetricsService::RecordCurrentState(PrefService* pref) {
1262 pref->SetInt64(prefs::kStabilityLastTimestampSec, 1267 pref->SetInt64(prefs::kStabilityLastTimestampSec,
1263 base::Time::Now().ToTimeT()); 1268 base::Time::Now().ToTimeT());
1264 } 1269 }
1265 1270
1271 void MetricsService::SetNetworkMetricsProvider(
1272 metrics::NetworkMetricsProvider* network_metrics_provider) {
1273 RegisterMetricsProvider(
1274 scoped_ptr<metrics::MetricsProvider>(network_metrics_provider));
1275 network_metrics_provider_ = network_metrics_provider;
1276 }
1277
1278 bool MetricsService::IsCellularConnection() {
1279 SystemProfileProto::Network::ConnectionType connection_type =
1280 network_metrics_provider_->GetConnectionType();
1281
1282 switch (connection_type) {
1283 case SystemProfileProto_Network_ConnectionType_CONNECTION_2G:
1284 case SystemProfileProto_Network_ConnectionType_CONNECTION_3G:
1285 case SystemProfileProto_Network_ConnectionType_CONNECTION_4G:
1286 return true;
1287 default:
1288 return false;
1289 }
1290 }
1291
1292 void MetricsService::UpdateSchedulerConnectionType() {
1293 scheduler_->SetConnectionType(IsCellularConnection());
1294 }
1295
1266 } // namespace metrics 1296 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698