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

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

Issue 28315: The MetricsService are not initialized unless the user have opted in... (Closed) Base URL: http://src.chromium.org/svn/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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 SetRecording(false); 416 SetRecording(false);
417 } 417 }
418 418
419 void MetricsService::SetRecording(bool enabled) { 419 void MetricsService::SetRecording(bool enabled) {
420 DCHECK(IsSingleThreaded()); 420 DCHECK(IsSingleThreaded());
421 421
422 if (enabled == recording_active_) 422 if (enabled == recording_active_)
423 return; 423 return;
424 424
425 if (enabled) { 425 if (enabled) {
426 if (client_id_.empty()) {
427 PrefService* pref = g_browser_process->local_state();
428 DCHECK(pref);
429 client_id_ = WideToUTF8(pref->GetString(prefs::kMetricsClientID));
430 if (client_id_.empty()) {
431 client_id_ = GenerateClientID();
432 pref->SetString(prefs::kMetricsClientID, UTF8ToWide(client_id_));
433
434 // Might as well make a note of how long this ID has existed
435 pref->SetString(prefs::kMetricsClientIDTimestamp,
436 Int64ToWString(Time::Now().ToTimeT()));
437 }
438 }
426 StartRecording(); 439 StartRecording();
427 ListenerRegistration(true); 440 ListenerRegistration(true);
428 } else { 441 } else {
429 // Turn off all observers. 442 // Turn off all observers.
430 ListenerRegistration(false); 443 ListenerRegistration(false);
431 PushPendingLogsToUnsentLists(); 444 PushPendingLogsToUnsentLists();
432 DCHECK(!pending_log()); 445 DCHECK(!pending_log());
433 if (state_ > INITIAL_LOG_READY && unsent_logs()) 446 if (state_ > INITIAL_LOG_READY && unsent_logs())
434 state_ = SEND_OLD_INITIAL_LOGS; 447 state_ = SEND_OLD_INITIAL_LOGS;
435 } 448 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 591
579 if (WideToUTF8(pref->GetString(prefs::kStabilityStatsVersion)) != 592 if (WideToUTF8(pref->GetString(prefs::kStabilityStatsVersion)) !=
580 MetricsLog::GetVersionString()) { 593 MetricsLog::GetVersionString()) {
581 // This is a new version, so we don't want to confuse the stats about the 594 // This is a new version, so we don't want to confuse the stats about the
582 // old version with info that we upload. 595 // old version with info that we upload.
583 DiscardOldStabilityStats(pref); 596 DiscardOldStabilityStats(pref);
584 pref->SetString(prefs::kStabilityStatsVersion, 597 pref->SetString(prefs::kStabilityStatsVersion,
585 UTF8ToWide(MetricsLog::GetVersionString())); 598 UTF8ToWide(MetricsLog::GetVersionString()));
586 } 599 }
587 600
588 client_id_ = WideToUTF8(pref->GetString(prefs::kMetricsClientID));
589 if (client_id_.empty()) {
590 client_id_ = GenerateClientID();
591 pref->SetString(prefs::kMetricsClientID, UTF8ToWide(client_id_));
592
593 // Might as well make a note of how long this ID has existed
594 pref->SetString(prefs::kMetricsClientIDTimestamp,
595 Int64ToWString(Time::Now().ToTimeT()));
596 }
597
598 // Update session ID 601 // Update session ID
599 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); 602 session_id_ = pref->GetInteger(prefs::kMetricsSessionID);
600 ++session_id_; 603 ++session_id_;
601 pref->SetInteger(prefs::kMetricsSessionID, session_id_); 604 pref->SetInteger(prefs::kMetricsSessionID, session_id_);
602 605
603 // Stability bookkeeping 606 // Stability bookkeeping
604 IncrementPrefValue(prefs::kStabilityLaunchCount); 607 IncrementPrefValue(prefs::kStabilityLaunchCount);
605 608
606 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { 609 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) {
607 IncrementPrefValue(prefs::kStabilityCrashCount); 610 IncrementPrefValue(prefs::kStabilityCrashCount);
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 L"." + key; 1839 L"." + key;
1837 prof_prefs->SetInteger(pref_key.c_str(), value); 1840 prof_prefs->SetInteger(pref_key.c_str(), value);
1838 } 1841 }
1839 1842
1840 static bool IsSingleThreaded() { 1843 static bool IsSingleThreaded() {
1841 static PlatformThreadId thread_id = 0; 1844 static PlatformThreadId thread_id = 0;
1842 if (!thread_id) 1845 if (!thread_id)
1843 thread_id = PlatformThread::CurrentId(); 1846 thread_id = PlatformThread::CurrentId();
1844 return PlatformThread::CurrentId() == thread_id; 1847 return PlatformThread::CurrentId() == thread_id;
1845 } 1848 }
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