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

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 40274: The MetricsService are not initialized unless the user have opted in... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 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 | Annotate | Revision Log
« 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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 6
7 //------------------------------------------------------------------------------ 7 //------------------------------------------------------------------------------
8 // Description of the life cycle of a instance of MetricsService. 8 // Description of the life cycle of a instance of MetricsService.
9 // 9 //
10 // OVERVIEW 10 // OVERVIEW
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 SetRecording(false); 423 SetRecording(false);
424 } 424 }
425 425
426 void MetricsService::SetRecording(bool enabled) { 426 void MetricsService::SetRecording(bool enabled) {
427 DCHECK(IsSingleThreaded()); 427 DCHECK(IsSingleThreaded());
428 428
429 if (enabled == recording_active_) 429 if (enabled == recording_active_)
430 return; 430 return;
431 431
432 if (enabled) { 432 if (enabled) {
433 if (client_id_.empty()) {
434 PrefService* pref = g_browser_process->local_state();
435 DCHECK(pref);
436 client_id_ = WideToUTF8(pref->GetString(prefs::kMetricsClientID));
437 if (client_id_.empty()) {
438 client_id_ = GenerateClientID();
439 pref->SetString(prefs::kMetricsClientID, UTF8ToWide(client_id_));
440
441 // Might as well make a note of how long this ID has existed
442 pref->SetString(prefs::kMetricsClientIDTimestamp,
443 Int64ToWString(Time::Now().ToTimeT()));
444 }
445 }
433 StartRecording(); 446 StartRecording();
434 ListenerRegistration(true); 447 ListenerRegistration(true);
435 } else { 448 } else {
436 // Turn off all observers. 449 // Turn off all observers.
437 ListenerRegistration(false); 450 ListenerRegistration(false);
438 PushPendingLogsToUnsentLists(); 451 PushPendingLogsToUnsentLists();
439 DCHECK(!pending_log()); 452 DCHECK(!pending_log());
440 if (state_ > INITIAL_LOG_READY && unsent_logs()) 453 if (state_ > INITIAL_LOG_READY && unsent_logs())
441 state_ = SEND_OLD_INITIAL_LOGS; 454 state_ = SEND_OLD_INITIAL_LOGS;
442 } 455 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 598
586 if (WideToUTF8(pref->GetString(prefs::kStabilityStatsVersion)) != 599 if (WideToUTF8(pref->GetString(prefs::kStabilityStatsVersion)) !=
587 MetricsLog::GetVersionString()) { 600 MetricsLog::GetVersionString()) {
588 // This is a new version, so we don't want to confuse the stats about the 601 // This is a new version, so we don't want to confuse the stats about the
589 // old version with info that we upload. 602 // old version with info that we upload.
590 DiscardOldStabilityStats(pref); 603 DiscardOldStabilityStats(pref);
591 pref->SetString(prefs::kStabilityStatsVersion, 604 pref->SetString(prefs::kStabilityStatsVersion,
592 UTF8ToWide(MetricsLog::GetVersionString())); 605 UTF8ToWide(MetricsLog::GetVersionString()));
593 } 606 }
594 607
595 client_id_ = WideToUTF8(pref->GetString(prefs::kMetricsClientID));
596 if (client_id_.empty()) {
597 client_id_ = GenerateClientID();
598 pref->SetString(prefs::kMetricsClientID, UTF8ToWide(client_id_));
599
600 // Might as well make a note of how long this ID has existed
601 pref->SetInt64(prefs::kMetricsClientIDTimestamp, Time::Now().ToTimeT());
602 }
603
604 // Update session ID 608 // Update session ID
605 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); 609 session_id_ = pref->GetInteger(prefs::kMetricsSessionID);
606 ++session_id_; 610 ++session_id_;
607 pref->SetInteger(prefs::kMetricsSessionID, session_id_); 611 pref->SetInteger(prefs::kMetricsSessionID, session_id_);
608 612
609 // Stability bookkeeping 613 // Stability bookkeeping
610 IncrementPrefValue(prefs::kStabilityLaunchCount); 614 IncrementPrefValue(prefs::kStabilityLaunchCount);
611 615
612 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { 616 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) {
613 IncrementPrefValue(prefs::kStabilityCrashCount); 617 IncrementPrefValue(prefs::kStabilityCrashCount);
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 L"." + key; 1862 L"." + key;
1859 prof_prefs->SetInteger(pref_key.c_str(), value); 1863 prof_prefs->SetInteger(pref_key.c_str(), value);
1860 } 1864 }
1861 1865
1862 static bool IsSingleThreaded() { 1866 static bool IsSingleThreaded() {
1863 static PlatformThreadId thread_id = 0; 1867 static PlatformThreadId thread_id = 0;
1864 if (!thread_id) 1868 if (!thread_id)
1865 thread_id = PlatformThread::CurrentId(); 1869 thread_id = PlatformThread::CurrentId();
1866 return PlatformThread::CurrentId() == thread_id; 1870 return PlatformThread::CurrentId() == thread_id;
1867 } 1871 }
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