OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 10 // A MetricsService instance is typically created at application startup. It |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 void MetricsService::Stop() { | 472 void MetricsService::Stop() { |
473 HandleIdleSinceLastTransmission(false); | 473 HandleIdleSinceLastTransmission(false); |
474 SetReporting(false); | 474 SetReporting(false); |
475 SetRecording(false); | 475 SetRecording(false); |
476 } | 476 } |
477 | 477 |
478 std::string MetricsService::GetClientId() { | 478 std::string MetricsService::GetClientId() { |
479 return client_id_; | 479 return client_id_; |
480 } | 480 } |
481 | 481 |
| 482 std::string MetricsService::GetClientIdNonEmpty() { |
| 483 PrefService* pref = g_browser_process->local_state(); |
| 484 DCHECK(pref); |
| 485 std::string client_id = pref->GetString(prefs::kMetricsClientID); |
| 486 if (client_id.empty()) { |
| 487 client_id = GenerateClientID(); |
| 488 pref->SetString(prefs::kMetricsClientID, client_id); |
| 489 |
| 490 // Might as well make a note of how long this ID has existed |
| 491 pref->SetString(prefs::kMetricsClientIDTimestamp, |
| 492 base::Int64ToString(Time::Now().ToTimeT())); |
| 493 } |
| 494 return client_id; |
| 495 } |
| 496 |
482 void MetricsService::SetRecording(bool enabled) { | 497 void MetricsService::SetRecording(bool enabled) { |
483 DCHECK(IsSingleThreaded()); | 498 DCHECK(IsSingleThreaded()); |
484 | 499 |
485 if (enabled == recording_active_) | 500 if (enabled == recording_active_) |
486 return; | 501 return; |
487 | 502 |
488 if (enabled) { | 503 if (enabled) { |
489 if (client_id_.empty()) { | 504 if (client_id_.empty()) { |
490 PrefService* pref = g_browser_process->local_state(); | 505 client_id_ = GetClientIdNonEmpty(); |
491 DCHECK(pref); | |
492 client_id_ = pref->GetString(prefs::kMetricsClientID); | |
493 if (client_id_.empty()) { | |
494 client_id_ = GenerateClientID(); | |
495 pref->SetString(prefs::kMetricsClientID, client_id_); | |
496 | |
497 // Might as well make a note of how long this ID has existed | |
498 pref->SetString(prefs::kMetricsClientIDTimestamp, | |
499 base::Int64ToString(Time::Now().ToTimeT())); | |
500 } | |
501 } | 506 } |
502 child_process_logging::SetClientId(client_id_); | 507 child_process_logging::SetClientId(client_id_); |
503 StartRecording(); | 508 StartRecording(); |
504 | 509 |
505 SetUpNotifications(®istrar_, this); | 510 SetUpNotifications(®istrar_, this); |
506 } else { | 511 } else { |
507 registrar_.RemoveAll(); | 512 registrar_.RemoveAll(); |
508 PushPendingLogsToUnsentLists(); | 513 PushPendingLogsToUnsentLists(); |
509 DCHECK(!pending_log()); | 514 DCHECK(!pending_log()); |
510 if (state_ > INITIAL_LOG_READY && unsent_logs()) | 515 if (state_ > INITIAL_LOG_READY && unsent_logs()) |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 thread_id = base::PlatformThread::CurrentId(); | 1696 thread_id = base::PlatformThread::CurrentId(); |
1692 return base::PlatformThread::CurrentId() == thread_id; | 1697 return base::PlatformThread::CurrentId() == thread_id; |
1693 } | 1698 } |
1694 | 1699 |
1695 #if defined(OS_CHROMEOS) | 1700 #if defined(OS_CHROMEOS) |
1696 void MetricsService::StartExternalMetrics() { | 1701 void MetricsService::StartExternalMetrics() { |
1697 external_metrics_ = new chromeos::ExternalMetrics; | 1702 external_metrics_ = new chromeos::ExternalMetrics; |
1698 external_metrics_->Start(); | 1703 external_metrics_->Start(); |
1699 } | 1704 } |
1700 #endif | 1705 #endif |
OLD | NEW |