OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 // | 161 // |
162 //------------------------------------------------------------------------------ | 162 //------------------------------------------------------------------------------ |
163 | 163 |
164 #include "chrome/browser/metrics/metrics_service.h" | 164 #include "chrome/browser/metrics/metrics_service.h" |
165 | 165 |
166 #include <algorithm> | 166 #include <algorithm> |
167 | 167 |
168 #include "base/bind.h" | 168 #include "base/bind.h" |
169 #include "base/callback.h" | 169 #include "base/callback.h" |
170 #include "base/command_line.h" | 170 #include "base/command_line.h" |
171 #include "base/guid.h" | |
172 #include "base/metrics/histogram.h" | 171 #include "base/metrics/histogram.h" |
173 #include "base/metrics/sparse_histogram.h" | 172 #include "base/metrics/sparse_histogram.h" |
174 #include "base/metrics/statistics_recorder.h" | 173 #include "base/metrics/statistics_recorder.h" |
175 #include "base/prefs/pref_registry_simple.h" | 174 #include "base/prefs/pref_registry_simple.h" |
176 #include "base/prefs/pref_service.h" | 175 #include "base/prefs/pref_service.h" |
177 #include "base/prefs/scoped_user_pref_update.h" | 176 #include "base/prefs/scoped_user_pref_update.h" |
178 #include "base/rand_util.h" | |
179 #include "base/strings/string_number_conversions.h" | 177 #include "base/strings/string_number_conversions.h" |
180 #include "base/strings/utf_string_conversions.h" | 178 #include "base/strings/utf_string_conversions.h" |
181 #include "base/threading/platform_thread.h" | 179 #include "base/threading/platform_thread.h" |
182 #include "base/threading/thread.h" | 180 #include "base/threading/thread.h" |
183 #include "base/threading/thread_restrictions.h" | 181 #include "base/threading/thread_restrictions.h" |
184 #include "base/tracked_objects.h" | 182 #include "base/tracked_objects.h" |
185 #include "base/values.h" | 183 #include "base/values.h" |
186 #include "chrome/browser/browser_process.h" | 184 #include "chrome/browser/browser_process.h" |
187 #include "chrome/browser/chrome_notification_types.h" | 185 #include "chrome/browser/chrome_notification_types.h" |
188 #include "chrome/browser/io_thread.h" | 186 #include "chrome/browser/io_thread.h" |
189 #include "chrome/browser/memory_details.h" | 187 #include "chrome/browser/memory_details.h" |
190 #include "chrome/browser/metrics/cloned_install_detector.h" | |
191 #include "chrome/browser/metrics/compression_utils.h" | 188 #include "chrome/browser/metrics/compression_utils.h" |
192 #include "chrome/browser/metrics/machine_id_provider.h" | 189 #include "chrome/browser/metrics/machine_id_provider.h" |
Ilya Sherman
2014/05/02 05:12:38
nit: Still needed?
Alexei Svitkine (slow)
2014/05/02 15:21:46
Nope. Removed.
| |
193 #include "chrome/browser/metrics/metrics_log.h" | 190 #include "chrome/browser/metrics/metrics_log.h" |
194 #include "chrome/browser/metrics/metrics_log_serializer.h" | 191 #include "chrome/browser/metrics/metrics_log_serializer.h" |
195 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" | 192 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" |
193 #include "chrome/browser/metrics/metrics_state_manager.h" | |
196 #include "chrome/browser/metrics/time_ticks_experiment_win.h" | 194 #include "chrome/browser/metrics/time_ticks_experiment_win.h" |
197 #include "chrome/browser/metrics/tracking_synchronizer.h" | 195 #include "chrome/browser/metrics/tracking_synchronizer.h" |
198 #include "chrome/common/metrics/variations/variations_util.h" | 196 #include "chrome/common/metrics/variations/variations_util.h" |
199 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 197 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
200 #include "chrome/browser/net/network_stats.h" | 198 #include "chrome/browser/net/network_stats.h" |
201 #include "chrome/browser/omnibox/omnibox_log.h" | 199 #include "chrome/browser/omnibox/omnibox_log.h" |
202 #include "chrome/browser/ui/browser_list.h" | 200 #include "chrome/browser/ui/browser_list.h" |
203 #include "chrome/browser/ui/browser_otr_state.h" | 201 #include "chrome/browser/ui/browser_otr_state.h" |
204 #include "chrome/browser/ui/search/search_tab_helper.h" | 202 #include "chrome/browser/ui/search/search_tab_helper.h" |
205 #include "chrome/common/chrome_constants.h" | 203 #include "chrome/common/chrome_constants.h" |
206 #include "chrome/common/chrome_result_codes.h" | 204 #include "chrome/common/chrome_result_codes.h" |
207 #include "chrome/common/chrome_switches.h" | 205 #include "chrome/common/chrome_switches.h" |
208 #include "chrome/common/crash_keys.h" | 206 #include "chrome/common/crash_keys.h" |
209 #include "chrome/common/metrics/caching_permuted_entropy_provider.h" | |
210 #include "chrome/common/metrics/metrics_log_manager.h" | 207 #include "chrome/common/metrics/metrics_log_manager.h" |
211 #include "chrome/common/net/test_server_locations.h" | 208 #include "chrome/common/net/test_server_locations.h" |
212 #include "chrome/common/pref_names.h" | 209 #include "chrome/common/pref_names.h" |
213 #include "chrome/common/render_messages.h" | 210 #include "chrome/common/render_messages.h" |
214 #include "components/variations/entropy_provider.h" | 211 #include "components/variations/entropy_provider.h" |
215 #include "components/variations/metrics_util.h" | 212 #include "components/variations/metrics_util.h" |
216 #include "content/public/browser/child_process_data.h" | 213 #include "content/public/browser/child_process_data.h" |
217 #include "content/public/browser/histogram_fetcher.h" | 214 #include "content/public/browser/histogram_fetcher.h" |
218 #include "content/public/browser/load_notification_details.h" | 215 #include "content/public/browser/load_notification_details.h" |
219 #include "content/public/browser/notification_service.h" | 216 #include "content/public/browser/notification_service.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 return SUCCESS; | 302 return SUCCESS; |
306 case 400: | 303 case 400: |
307 return BAD_REQUEST; | 304 return BAD_REQUEST; |
308 case net::URLFetcher::RESPONSE_CODE_INVALID: | 305 case net::URLFetcher::RESPONSE_CODE_INVALID: |
309 return NO_RESPONSE; | 306 return NO_RESPONSE; |
310 default: | 307 default: |
311 return UNKNOWN_FAILURE; | 308 return UNKNOWN_FAILURE; |
312 } | 309 } |
313 } | 310 } |
314 | 311 |
315 // The argument used to generate a non-identifying entropy source. We want no | |
316 // more than 13 bits of entropy, so use this max to return a number in the range | |
317 // [0, 7999] as the entropy source (12.97 bits of entropy). | |
318 const int kMaxLowEntropySize = 8000; | |
319 | |
320 // Default prefs value for prefs::kMetricsLowEntropySource to indicate that the | |
321 // value has not yet been set. | |
322 const int kLowEntropySourceNotSet = -1; | |
323 | |
324 // Generates a new non-identifying entropy source used to seed persistent | |
325 // activities. | |
326 int GenerateLowEntropySource() { | |
327 return base::RandInt(0, kMaxLowEntropySize - 1); | |
328 } | |
329 | |
330 // Converts an exit code into something that can be inserted into our | 312 // Converts an exit code into something that can be inserted into our |
331 // histograms (which expect non-negative numbers less than MAX_INT). | 313 // histograms (which expect non-negative numbers less than MAX_INT). |
332 int MapCrashExitCodeForHistogram(int exit_code) { | 314 int MapCrashExitCodeForHistogram(int exit_code) { |
333 #if defined(OS_WIN) | 315 #if defined(OS_WIN) |
334 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in | 316 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in |
335 // histograms.cc. Solve this by remapping it to a smaller value, which | 317 // histograms.cc. Solve this by remapping it to a smaller value, which |
336 // hopefully doesn't conflict with other codes. | 318 // hopefully doesn't conflict with other codes. |
337 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) | 319 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) |
338 return 0x1FCF7EC3; // Randomly picked number. | 320 return 0x1FCF7EC3; // Randomly picked number. |
339 #endif | 321 #endif |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 private: | 404 private: |
423 virtual ~MetricsMemoryDetails() {} | 405 virtual ~MetricsMemoryDetails() {} |
424 | 406 |
425 base::Closure callback_; | 407 base::Closure callback_; |
426 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | 408 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
427 }; | 409 }; |
428 | 410 |
429 // static | 411 // static |
430 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { | 412 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { |
431 DCHECK(IsSingleThreaded()); | 413 DCHECK(IsSingleThreaded()); |
432 registry->RegisterBooleanPref(prefs::kMetricsResetIds, false); | 414 metrics::MetricsStateManager::RegisterPrefs(registry); |
433 registry->RegisterStringPref(prefs::kMetricsClientID, std::string()); | 415 |
434 registry->RegisterInt64Pref(prefs::kMetricsReportingEnabledTimestamp, 0); | |
435 registry->RegisterIntegerPref(prefs::kMetricsLowEntropySource, | |
436 kLowEntropySourceNotSet); | |
437 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); | 416 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); |
438 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); | 417 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); |
439 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); | 418 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); |
440 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); | 419 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); |
441 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); | 420 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); |
442 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, | 421 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, |
443 UNINITIALIZED_PHASE); | 422 UNINITIALIZED_PHASE); |
444 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); | 423 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); |
445 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); | 424 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); |
446 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); | 425 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
(...skipping 24 matching lines...) Expand all Loading... | |
471 registry->RegisterListPref(prefs::kMetricsInitialLogs); | 450 registry->RegisterListPref(prefs::kMetricsInitialLogs); |
472 registry->RegisterListPref(prefs::kMetricsOngoingLogs); | 451 registry->RegisterListPref(prefs::kMetricsOngoingLogs); |
473 | 452 |
474 registry->RegisterInt64Pref(prefs::kInstallDate, 0); | 453 registry->RegisterInt64Pref(prefs::kInstallDate, 0); |
475 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); | 454 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); |
476 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 455 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
477 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 456 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
478 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 457 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
479 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 458 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
480 | 459 |
481 // TODO(asvitkine): Remove these once a couple of releases have passed. | |
482 // http://crbug.com/357704 | |
483 registry->RegisterStringPref(prefs::kMetricsOldClientID, std::string()); | |
484 registry->RegisterIntegerPref(prefs::kMetricsOldLowEntropySource, 0); | |
485 | |
486 #if defined(OS_ANDROID) | 460 #if defined(OS_ANDROID) |
487 RegisterPrefsAndroid(registry); | 461 RegisterPrefsAndroid(registry); |
488 #endif // defined(OS_ANDROID) | 462 #endif // defined(OS_ANDROID) |
489 } | 463 } |
490 | 464 |
491 MetricsService::MetricsService() | 465 MetricsService::MetricsService() |
492 : metrics_ids_reset_check_performed_(false), | 466 : state_manager_(new metrics::MetricsStateManager( |
467 g_browser_process->local_state())), | |
Ilya Sherman
2014/05/02 05:12:38
nit: Can this be a direct class member, rather tha
Alexei Svitkine (slow)
2014/05/02 15:21:46
It could be if just this CL is taken into account.
Ilya Sherman
2014/05/02 19:35:06
Ok. Keep in mind that using a weak pointer will i
| |
493 recording_active_(false), | 468 recording_active_(false), |
494 reporting_active_(false), | 469 reporting_active_(false), |
495 test_mode_active_(false), | 470 test_mode_active_(false), |
496 state_(INITIALIZED), | 471 state_(INITIALIZED), |
497 has_initial_stability_log_(false), | 472 has_initial_stability_log_(false), |
498 low_entropy_source_(kLowEntropySourceNotSet), | |
499 idle_since_last_transmission_(false), | 473 idle_since_last_transmission_(false), |
500 session_id_(-1), | 474 session_id_(-1), |
501 next_window_id_(0), | 475 next_window_id_(0), |
502 self_ptr_factory_(this), | 476 self_ptr_factory_(this), |
503 state_saver_factory_(this), | 477 state_saver_factory_(this), |
504 waiting_for_asynchronous_reporting_step_(false), | 478 waiting_for_asynchronous_reporting_step_(false), |
505 num_async_histogram_fetches_in_progress_(0), | 479 num_async_histogram_fetches_in_progress_(0) { |
506 entropy_source_returned_(LAST_ENTROPY_NONE) { | |
507 DCHECK(IsSingleThreaded()); | 480 DCHECK(IsSingleThreaded()); |
508 | 481 |
509 log_manager_.set_log_serializer(new MetricsLogSerializer); | 482 log_manager_.set_log_serializer(new MetricsLogSerializer); |
510 log_manager_.set_max_ongoing_log_store_size(kUploadLogAvoidRetransmitSize); | 483 log_manager_.set_max_ongoing_log_store_size(kUploadLogAvoidRetransmitSize); |
511 | 484 |
512 BrowserChildProcessObserver::Add(this); | 485 BrowserChildProcessObserver::Add(this); |
513 } | 486 } |
514 | 487 |
515 MetricsService::~MetricsService() { | 488 MetricsService::~MetricsService() { |
516 DisableRecording(); | 489 DisableRecording(); |
517 | 490 |
518 BrowserChildProcessObserver::Remove(this); | 491 BrowserChildProcessObserver::Remove(this); |
519 } | 492 } |
520 | 493 |
521 void MetricsService::InitializeMetricsRecordingState( | 494 void MetricsService::InitializeMetricsRecordingState() { |
522 ReportingState reporting_state) { | 495 InitializeMetricsState(); |
523 InitializeMetricsState(reporting_state); | |
524 | 496 |
525 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, | 497 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
526 self_ptr_factory_.GetWeakPtr()); | 498 self_ptr_factory_.GetWeakPtr()); |
527 scheduler_.reset(new MetricsReportingScheduler(callback)); | 499 scheduler_.reset(new MetricsReportingScheduler(callback)); |
528 } | 500 } |
529 | 501 |
530 void MetricsService::Start() { | 502 void MetricsService::Start() { |
531 HandleIdleSinceLastTransmission(false); | 503 HandleIdleSinceLastTransmission(false); |
532 EnableRecording(); | 504 EnableRecording(); |
533 EnableReporting(); | 505 EnableReporting(); |
534 } | 506 } |
535 | 507 |
508 bool MetricsService::StartIfMetricsReportingEnabled() { | |
509 const bool enabled = state_manager_->IsMetricsReportingEnabled(); | |
510 if (enabled) | |
511 Start(); | |
512 return enabled; | |
513 } | |
514 | |
536 void MetricsService::StartRecordingForTests() { | 515 void MetricsService::StartRecordingForTests() { |
537 test_mode_active_ = true; | 516 test_mode_active_ = true; |
538 EnableRecording(); | 517 EnableRecording(); |
539 DisableReporting(); | 518 DisableReporting(); |
540 } | 519 } |
541 | 520 |
542 void MetricsService::Stop() { | 521 void MetricsService::Stop() { |
543 HandleIdleSinceLastTransmission(false); | 522 HandleIdleSinceLastTransmission(false); |
544 DisableReporting(); | 523 DisableReporting(); |
545 DisableRecording(); | 524 DisableRecording(); |
546 } | 525 } |
547 | 526 |
548 void MetricsService::EnableReporting() { | 527 void MetricsService::EnableReporting() { |
549 if (reporting_active_) | 528 if (reporting_active_) |
550 return; | 529 return; |
551 reporting_active_ = true; | 530 reporting_active_ = true; |
552 StartSchedulerIfNecessary(); | 531 StartSchedulerIfNecessary(); |
553 } | 532 } |
554 | 533 |
555 void MetricsService::DisableReporting() { | 534 void MetricsService::DisableReporting() { |
556 reporting_active_ = false; | 535 reporting_active_ = false; |
557 } | 536 } |
558 | 537 |
559 std::string MetricsService::GetClientId() { | 538 std::string MetricsService::GetClientId() { |
560 return client_id_; | 539 return state_manager_->client_id(); |
561 } | 540 } |
562 | 541 |
563 scoped_ptr<const base::FieldTrial::EntropyProvider> | 542 scoped_ptr<const base::FieldTrial::EntropyProvider> |
564 MetricsService::CreateEntropyProvider(ReportingState reporting_state) { | 543 MetricsService::CreateEntropyProvider() { |
565 // For metrics reporting-enabled users, we combine the client ID and low | 544 // TODO(asvitkine): Refactor the code so that MetricsService does not expose |
566 // entropy source to get the final entropy source. Otherwise, only use the low | 545 // this method. |
567 // entropy source. | 546 return state_manager_->CreateEntropyProvider(); |
568 // This has two useful properties: | |
569 // 1) It makes the entropy source less identifiable for parties that do not | |
570 // know the low entropy source. | |
571 // 2) It makes the final entropy source resettable. | |
572 const int low_entropy_source_value = GetLowEntropySource(); | |
573 UMA_HISTOGRAM_SPARSE_SLOWLY("UMA.LowEntropySourceValue", | |
574 low_entropy_source_value); | |
575 if (reporting_state == REPORTING_ENABLED) { | |
576 if (entropy_source_returned_ == LAST_ENTROPY_NONE) | |
577 entropy_source_returned_ = LAST_ENTROPY_HIGH; | |
578 DCHECK_EQ(LAST_ENTROPY_HIGH, entropy_source_returned_); | |
579 const std::string high_entropy_source = | |
580 client_id_ + base::IntToString(low_entropy_source_value); | |
581 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | |
582 new metrics::SHA1EntropyProvider(high_entropy_source)); | |
583 } | |
584 | |
585 if (entropy_source_returned_ == LAST_ENTROPY_NONE) | |
586 entropy_source_returned_ = LAST_ENTROPY_LOW; | |
587 DCHECK_EQ(LAST_ENTROPY_LOW, entropy_source_returned_); | |
588 | |
589 #if defined(OS_ANDROID) || defined(OS_IOS) | |
590 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | |
591 new metrics::CachingPermutedEntropyProvider( | |
592 g_browser_process->local_state(), | |
593 low_entropy_source_value, | |
594 kMaxLowEntropySize)); | |
595 #else | |
596 return scoped_ptr<const base::FieldTrial::EntropyProvider>( | |
597 new metrics::PermutedEntropyProvider(low_entropy_source_value, | |
598 kMaxLowEntropySize)); | |
599 #endif | |
600 } | |
601 | |
602 void MetricsService::ForceClientIdCreation() { | |
603 if (!client_id_.empty()) | |
604 return; | |
605 | |
606 ResetMetricsIDsIfNecessary(); | |
607 | |
608 PrefService* pref = g_browser_process->local_state(); | |
609 client_id_ = pref->GetString(prefs::kMetricsClientID); | |
610 if (!client_id_.empty()) | |
611 return; | |
612 | |
613 client_id_ = GenerateClientID(); | |
614 pref->SetString(prefs::kMetricsClientID, client_id_); | |
615 | |
616 if (pref->GetString(prefs::kMetricsOldClientID).empty()) { | |
617 // Record the timestamp of when the user opted in to UMA. | |
618 pref->SetInt64(prefs::kMetricsReportingEnabledTimestamp, | |
619 Time::Now().ToTimeT()); | |
620 } else { | |
621 UMA_HISTOGRAM_BOOLEAN("UMA.ClientIdMigrated", true); | |
622 } | |
623 pref->ClearPref(prefs::kMetricsOldClientID); | |
624 } | 547 } |
625 | 548 |
626 void MetricsService::EnableRecording() { | 549 void MetricsService::EnableRecording() { |
627 DCHECK(IsSingleThreaded()); | 550 DCHECK(IsSingleThreaded()); |
628 | 551 |
629 if (recording_active_) | 552 if (recording_active_) |
630 return; | 553 return; |
631 recording_active_ = true; | 554 recording_active_ = true; |
632 | 555 |
633 ForceClientIdCreation(); | 556 state_manager_->ForceClientIdCreation(); |
634 crash_keys::SetClientID(client_id_); | 557 crash_keys::SetClientID(state_manager_->client_id()); |
635 if (!log_manager_.current_log()) | 558 if (!log_manager_.current_log()) |
636 OpenNewLog(); | 559 OpenNewLog(); |
637 | 560 |
638 SetUpNotifications(®istrar_, this); | 561 SetUpNotifications(®istrar_, this); |
639 base::RemoveActionCallback(action_callback_); | 562 base::RemoveActionCallback(action_callback_); |
640 action_callback_ = base::Bind(&MetricsService::OnUserAction, | 563 action_callback_ = base::Bind(&MetricsService::OnUserAction, |
641 base::Unretained(this)); | 564 base::Unretained(this)); |
642 base::AddActionCallback(action_callback_); | 565 base::AddActionCallback(action_callback_); |
643 } | 566 } |
644 | 567 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
910 #endif // defined(OS_WIN) | 833 #endif // defined(OS_WIN) |
911 | 834 |
912 //------------------------------------------------------------------------------ | 835 //------------------------------------------------------------------------------ |
913 // private methods | 836 // private methods |
914 //------------------------------------------------------------------------------ | 837 //------------------------------------------------------------------------------ |
915 | 838 |
916 | 839 |
917 //------------------------------------------------------------------------------ | 840 //------------------------------------------------------------------------------ |
918 // Initialization methods | 841 // Initialization methods |
919 | 842 |
920 void MetricsService::InitializeMetricsState(ReportingState reporting_state) { | 843 void MetricsService::InitializeMetricsState() { |
921 #if defined(OS_POSIX) | 844 #if defined(OS_POSIX) |
922 network_stats_server_ = chrome_common_net::kEchoTestServerLocation; | 845 network_stats_server_ = chrome_common_net::kEchoTestServerLocation; |
923 http_pipelining_test_server_ = chrome_common_net::kPipelineTestServerBaseUrl; | 846 http_pipelining_test_server_ = chrome_common_net::kPipelineTestServerBaseUrl; |
924 #else | 847 #else |
925 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 848 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
926 network_stats_server_ = dist->GetNetworkStatsServer(); | 849 network_stats_server_ = dist->GetNetworkStatsServer(); |
927 http_pipelining_test_server_ = dist->GetHttpPipeliningTestServer(); | 850 http_pipelining_test_server_ = dist->GetHttpPipeliningTestServer(); |
928 #endif | 851 #endif |
929 | 852 |
930 PrefService* pref = g_browser_process->local_state(); | 853 PrefService* pref = g_browser_process->local_state(); |
(...skipping 16 matching lines...) Expand all Loading... | |
947 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 870 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); |
948 | 871 |
949 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 872 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
950 // the registry. | 873 // the registry. |
951 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); | 874 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); |
952 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 875 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
953 execution_phase); | 876 execution_phase); |
954 | 877 |
955 // If the previous session didn't exit cleanly, then prepare an initial | 878 // If the previous session didn't exit cleanly, then prepare an initial |
956 // stability log if UMA is enabled. | 879 // stability log if UMA is enabled. |
957 if (reporting_state == REPORTING_ENABLED) | 880 if (state_manager_->IsMetricsReportingEnabled()) |
958 PrepareInitialStabilityLog(); | 881 PrepareInitialStabilityLog(); |
959 } | 882 } |
960 | 883 |
961 // Update session ID. | 884 // Update session ID. |
962 ++session_id_; | 885 ++session_id_; |
963 pref->SetInteger(prefs::kMetricsSessionID, session_id_); | 886 pref->SetInteger(prefs::kMetricsSessionID, session_id_); |
964 | 887 |
965 // Stability bookkeeping | 888 // Stability bookkeeping |
966 IncrementPrefValue(prefs::kStabilityLaunchCount); | 889 IncrementPrefValue(prefs::kStabilityLaunchCount); |
967 | 890 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 | 1034 |
1112 void MetricsService::ReceivedProfilerData( | 1035 void MetricsService::ReceivedProfilerData( |
1113 const tracked_objects::ProcessDataSnapshot& process_data, | 1036 const tracked_objects::ProcessDataSnapshot& process_data, |
1114 int process_type) { | 1037 int process_type) { |
1115 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1038 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1116 | 1039 |
1117 // Upon the first callback, create the initial log so that we can immediately | 1040 // Upon the first callback, create the initial log so that we can immediately |
1118 // save the profiler data. | 1041 // save the profiler data. |
1119 if (!initial_metrics_log_.get()) { | 1042 if (!initial_metrics_log_.get()) { |
1120 initial_metrics_log_.reset( | 1043 initial_metrics_log_.reset( |
1121 new MetricsLog(client_id_, session_id_, MetricsLog::ONGOING_LOG)); | 1044 new MetricsLog(state_manager_->client_id(), session_id_, |
1045 MetricsLog::ONGOING_LOG)); | |
1122 } | 1046 } |
1123 | 1047 |
1124 initial_metrics_log_->RecordProfilerData(process_data, process_type); | 1048 initial_metrics_log_->RecordProfilerData(process_data, process_type); |
1125 } | 1049 } |
1126 | 1050 |
1127 void MetricsService::FinishedReceivingProfilerData() { | 1051 void MetricsService::FinishedReceivingProfilerData() { |
1128 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1052 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1129 state_ = INIT_TASK_DONE; | 1053 state_ = INIT_TASK_DONE; |
1130 scheduler_->InitTaskComplete(); | 1054 scheduler_->InitTaskComplete(); |
1131 } | 1055 } |
(...skipping 13 matching lines...) Expand all Loading... | |
1145 last_updated_time_ = now; | 1069 last_updated_time_ = now; |
1146 | 1070 |
1147 const int64 incremental_time_secs = incremental_uptime->InSeconds(); | 1071 const int64 incremental_time_secs = incremental_uptime->InSeconds(); |
1148 if (incremental_time_secs > 0) { | 1072 if (incremental_time_secs > 0) { |
1149 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); | 1073 int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
1150 metrics_uptime += incremental_time_secs; | 1074 metrics_uptime += incremental_time_secs; |
1151 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); | 1075 pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
1152 } | 1076 } |
1153 } | 1077 } |
1154 | 1078 |
1155 void MetricsService::ResetMetricsIDsIfNecessary() { | |
1156 if (metrics_ids_reset_check_performed_) | |
1157 return; | |
1158 | |
1159 metrics_ids_reset_check_performed_ = true; | |
1160 | |
1161 PrefService* local_state = g_browser_process->local_state(); | |
1162 if (!local_state->GetBoolean(prefs::kMetricsResetIds)) | |
1163 return; | |
1164 | |
1165 UMA_HISTOGRAM_BOOLEAN("UMA.MetricsIDsReset", true); | |
1166 | |
1167 DCHECK(client_id_.empty()); | |
1168 DCHECK_EQ(kLowEntropySourceNotSet, low_entropy_source_); | |
1169 | |
1170 local_state->ClearPref(prefs::kMetricsClientID); | |
1171 local_state->ClearPref(prefs::kMetricsLowEntropySource); | |
1172 local_state->ClearPref(prefs::kMetricsResetIds); | |
1173 } | |
1174 | |
1175 int MetricsService::GetLowEntropySource() { | |
1176 // Note that the default value for the low entropy source and the default pref | |
1177 // value are both kLowEntropySourceNotSet, which is used to identify if the | |
1178 // value has been set or not. | |
1179 if (low_entropy_source_ != kLowEntropySourceNotSet) | |
1180 return low_entropy_source_; | |
1181 | |
1182 ResetMetricsIDsIfNecessary(); | |
1183 | |
1184 PrefService* local_state = g_browser_process->local_state(); | |
1185 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | |
1186 // Only try to load the value from prefs if the user did not request a reset. | |
1187 // Otherwise, skip to generating a new value. | |
1188 if (!command_line->HasSwitch(switches::kResetVariationState)) { | |
1189 int value = local_state->GetInteger(prefs::kMetricsLowEntropySource); | |
1190 // If the value is outside the [0, kMaxLowEntropySize) range, re-generate | |
1191 // it below. | |
1192 if (value >= 0 && value < kMaxLowEntropySize) { | |
1193 low_entropy_source_ = value; | |
1194 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", false); | |
1195 return low_entropy_source_; | |
1196 } | |
1197 } | |
1198 | |
1199 UMA_HISTOGRAM_BOOLEAN("UMA.GeneratedLowEntropySource", true); | |
1200 low_entropy_source_ = GenerateLowEntropySource(); | |
1201 local_state->SetInteger(prefs::kMetricsLowEntropySource, low_entropy_source_); | |
1202 local_state->ClearPref(prefs::kMetricsOldLowEntropySource); | |
1203 metrics::CachingPermutedEntropyProvider::ClearCache(local_state); | |
1204 | |
1205 return low_entropy_source_; | |
1206 } | |
1207 | |
1208 // static | |
1209 std::string MetricsService::GenerateClientID() { | |
1210 return base::GenerateGUID(); | |
1211 } | |
1212 | |
1213 //------------------------------------------------------------------------------ | 1079 //------------------------------------------------------------------------------ |
1214 // State save methods | 1080 // State save methods |
1215 | 1081 |
1216 void MetricsService::ScheduleNextStateSave() { | 1082 void MetricsService::ScheduleNextStateSave() { |
1217 state_saver_factory_.InvalidateWeakPtrs(); | 1083 state_saver_factory_.InvalidateWeakPtrs(); |
1218 | 1084 |
1219 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1085 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1220 base::Bind(&MetricsService::SaveLocalState, | 1086 base::Bind(&MetricsService::SaveLocalState, |
1221 state_saver_factory_.GetWeakPtr()), | 1087 state_saver_factory_.GetWeakPtr()), |
1222 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); | 1088 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); |
(...skipping 13 matching lines...) Expand all Loading... | |
1236 } | 1102 } |
1237 | 1103 |
1238 | 1104 |
1239 //------------------------------------------------------------------------------ | 1105 //------------------------------------------------------------------------------ |
1240 // Recording control methods | 1106 // Recording control methods |
1241 | 1107 |
1242 void MetricsService::OpenNewLog() { | 1108 void MetricsService::OpenNewLog() { |
1243 DCHECK(!log_manager_.current_log()); | 1109 DCHECK(!log_manager_.current_log()); |
1244 | 1110 |
1245 log_manager_.BeginLoggingWithLog( | 1111 log_manager_.BeginLoggingWithLog( |
1246 new MetricsLog(client_id_, session_id_, MetricsLog::ONGOING_LOG)); | 1112 new MetricsLog(state_manager_->client_id(), session_id_, |
1113 MetricsLog::ONGOING_LOG)); | |
1247 if (state_ == INITIALIZED) { | 1114 if (state_ == INITIALIZED) { |
1248 // We only need to schedule that run once. | 1115 // We only need to schedule that run once. |
1249 state_ = INIT_TASK_SCHEDULED; | 1116 state_ = INIT_TASK_SCHEDULED; |
1250 | 1117 |
1251 // Schedules a task on the file thread for execution of slower | 1118 // Schedules a task on the file thread for execution of slower |
1252 // initialization steps (such as plugin list generation) necessary | 1119 // initialization steps (such as plugin list generation) necessary |
1253 // for sending the initial log. This avoids blocking the main UI | 1120 // for sending the initial log. This avoids blocking the main UI |
1254 // thread. | 1121 // thread. |
1255 BrowserThread::PostDelayedTask( | 1122 BrowserThread::PostDelayedTask( |
1256 BrowserThread::FILE, | 1123 BrowserThread::FILE, |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1532 | 1399 |
1533 DCHECK(log_manager_.has_staged_log()); | 1400 DCHECK(log_manager_.has_staged_log()); |
1534 } | 1401 } |
1535 | 1402 |
1536 void MetricsService::PrepareInitialStabilityLog() { | 1403 void MetricsService::PrepareInitialStabilityLog() { |
1537 DCHECK_EQ(INITIALIZED, state_); | 1404 DCHECK_EQ(INITIALIZED, state_); |
1538 PrefService* pref = g_browser_process->local_state(); | 1405 PrefService* pref = g_browser_process->local_state(); |
1539 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); | 1406 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); |
1540 | 1407 |
1541 scoped_ptr<MetricsLog> initial_stability_log( | 1408 scoped_ptr<MetricsLog> initial_stability_log( |
1542 new MetricsLog(client_id_, session_id_, | 1409 new MetricsLog(state_manager_->client_id(), session_id_, |
1543 MetricsLog::INITIAL_STABILITY_LOG)); | 1410 MetricsLog::INITIAL_STABILITY_LOG)); |
1544 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 1411 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
1545 return; | 1412 return; |
1546 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), | 1413 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), |
1547 base::TimeDelta()); | 1414 base::TimeDelta()); |
1548 log_manager_.LoadPersistedUnsentLogs(); | 1415 log_manager_.LoadPersistedUnsentLogs(); |
1549 | 1416 |
1550 log_manager_.PauseCurrentLog(); | 1417 log_manager_.PauseCurrentLog(); |
1551 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); | 1418 log_manager_.BeginLoggingWithLog(initial_stability_log.release()); |
1552 #if defined(OS_ANDROID) | 1419 #if defined(OS_ANDROID) |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1831 return; | 1698 return; |
1832 } | 1699 } |
1833 } | 1700 } |
1834 | 1701 |
1835 SyntheticTrialGroup trial_group = trial; | 1702 SyntheticTrialGroup trial_group = trial; |
1836 trial_group.start_time = base::TimeTicks::Now(); | 1703 trial_group.start_time = base::TimeTicks::Now(); |
1837 synthetic_trial_groups_.push_back(trial_group); | 1704 synthetic_trial_groups_.push_back(trial_group); |
1838 } | 1705 } |
1839 | 1706 |
1840 void MetricsService::CheckForClonedInstall() { | 1707 void MetricsService::CheckForClonedInstall() { |
1841 DCHECK(!cloned_install_detector_); | 1708 state_manager_->CheckForClonedInstall(); |
1842 | |
1843 metrics::MachineIdProvider* provider = | |
1844 metrics::MachineIdProvider::CreateInstance(); | |
1845 if (!provider) | |
1846 return; | |
1847 | |
1848 cloned_install_detector_.reset( | |
1849 new metrics::ClonedInstallDetector(provider)); | |
1850 | |
1851 PrefService* local_state = g_browser_process->local_state(); | |
1852 cloned_install_detector_->CheckForClonedInstall(local_state); | |
1853 } | 1709 } |
1854 | 1710 |
1855 void MetricsService::GetCurrentSyntheticFieldTrials( | 1711 void MetricsService::GetCurrentSyntheticFieldTrials( |
1856 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) { | 1712 std::vector<chrome_variations::ActiveGroupId>* synthetic_trials) { |
1857 DCHECK(synthetic_trials); | 1713 DCHECK(synthetic_trials); |
1858 synthetic_trials->clear(); | 1714 synthetic_trials->clear(); |
1859 const MetricsLog* current_log = | 1715 const MetricsLog* current_log = |
1860 static_cast<const MetricsLog*>(log_manager_.current_log()); | 1716 static_cast<const MetricsLog*>(log_manager_.current_log()); |
1861 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { | 1717 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { |
1862 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) | 1718 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2074 // Android has its own settings for metrics / crash uploading. | 1930 // Android has its own settings for metrics / crash uploading. |
2075 const PrefService* prefs = g_browser_process->local_state(); | 1931 const PrefService* prefs = g_browser_process->local_state(); |
2076 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 1932 return prefs->GetBoolean(prefs::kCrashReportingEnabled); |
2077 #else | 1933 #else |
2078 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 1934 return MetricsServiceHelper::IsMetricsReportingEnabled(); |
2079 #endif | 1935 #endif |
2080 #else | 1936 #else |
2081 return false; | 1937 return false; |
2082 #endif | 1938 #endif |
2083 } | 1939 } |
OLD | NEW |