| 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 #include "chrome/browser/metrics/metrics_log.h" | 5 #include "chrome/browser/metrics/metrics_log.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 395 |
| 396 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} | 396 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| 397 | 397 |
| 398 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} | 398 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
| 399 | 399 |
| 400 static base::LazyInstance<std::string>::Leaky | 400 static base::LazyInstance<std::string>::Leaky |
| 401 g_version_extension = LAZY_INSTANCE_INITIALIZER; | 401 g_version_extension = LAZY_INSTANCE_INITIALIZER; |
| 402 | 402 |
| 403 MetricsLog::MetricsLog(const std::string& client_id, | 403 MetricsLog::MetricsLog(const std::string& client_id, |
| 404 int session_id, | 404 int session_id, |
| 405 LogType log_type) | 405 LogType log_type, |
| 406 : MetricsLogBase(client_id, session_id, log_type, | 406 PrefService* local_state) |
| 407 : MetricsLogBase(client_id, |
| 408 session_id, |
| 409 log_type, |
| 407 MetricsLog::GetVersionString()), | 410 MetricsLog::GetVersionString()), |
| 408 creation_time_(base::TimeTicks::Now()), | 411 creation_time_(base::TimeTicks::Now()), |
| 409 extension_metrics_(uma_proto()->client_id()) { | 412 extension_metrics_(uma_proto()->client_id()), |
| 413 local_state_(local_state) { |
| 410 uma_proto()->mutable_system_profile()->set_channel( | 414 uma_proto()->mutable_system_profile()->set_channel( |
| 411 AsProtobufChannel(chrome::VersionInfo::GetChannel())); | 415 AsProtobufChannel(chrome::VersionInfo::GetChannel())); |
| 412 | 416 |
| 413 #if defined(OS_CHROMEOS) | 417 #if defined(OS_CHROMEOS) |
| 414 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); | 418 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); |
| 415 #endif // OS_CHROMEOS | 419 #endif // OS_CHROMEOS |
| 416 } | 420 } |
| 417 | 421 |
| 418 MetricsLog::~MetricsLog() {} | 422 MetricsLog::~MetricsLog() {} |
| 419 | 423 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 447 const std::string& MetricsLog::version_extension() { | 451 const std::string& MetricsLog::version_extension() { |
| 448 return g_version_extension.Get(); | 452 return g_version_extension.Get(); |
| 449 } | 453 } |
| 450 | 454 |
| 451 void MetricsLog::RecordStabilityMetrics(base::TimeDelta incremental_uptime, | 455 void MetricsLog::RecordStabilityMetrics(base::TimeDelta incremental_uptime, |
| 452 base::TimeDelta uptime) { | 456 base::TimeDelta uptime) { |
| 453 DCHECK(!locked()); | 457 DCHECK(!locked()); |
| 454 DCHECK(HasEnvironment()); | 458 DCHECK(HasEnvironment()); |
| 455 DCHECK(!HasStabilityMetrics()); | 459 DCHECK(!HasStabilityMetrics()); |
| 456 | 460 |
| 457 PrefService* pref = GetPrefService(); | 461 PrefService* pref = local_state_; |
| 458 DCHECK(pref); | 462 DCHECK(pref); |
| 459 | 463 |
| 460 // Get stability attributes out of Local State, zeroing out stored values. | 464 // Get stability attributes out of Local State, zeroing out stored values. |
| 461 // NOTE: This could lead to some data loss if this report isn't successfully | 465 // NOTE: This could lead to some data loss if this report isn't successfully |
| 462 // sent, but that's true for all the metrics. | 466 // sent, but that's true for all the metrics. |
| 463 | 467 |
| 464 WriteRequiredStabilityAttributes(pref); | 468 WriteRequiredStabilityAttributes(pref); |
| 465 WritePluginStabilityElements(pref); | 469 WritePluginStabilityElements(pref); |
| 466 | 470 |
| 467 // Record recent delta for critical stability metrics. We can't wait for a | 471 // Record recent delta for critical stability metrics. We can't wait for a |
| (...skipping 28 matching lines...) Expand all Loading... |
| 496 uma_proto()->mutable_system_profile()->mutable_stability(); | 500 uma_proto()->mutable_system_profile()->mutable_stability(); |
| 497 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); | 501 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 498 stability->set_breakpad_registration_success_count( | 502 stability->set_breakpad_registration_success_count( |
| 499 breakpad_registration_success_count); | 503 breakpad_registration_success_count); |
| 500 stability->set_breakpad_registration_failure_count( | 504 stability->set_breakpad_registration_failure_count( |
| 501 breakpad_registration_failure_count); | 505 breakpad_registration_failure_count); |
| 502 stability->set_debugger_present_count(debugger_present_count); | 506 stability->set_debugger_present_count(debugger_present_count); |
| 503 stability->set_debugger_not_present_count(debugger_not_present_count); | 507 stability->set_debugger_not_present_count(debugger_not_present_count); |
| 504 } | 508 } |
| 505 | 509 |
| 506 PrefService* MetricsLog::GetPrefService() { | |
| 507 return g_browser_process->local_state(); | |
| 508 } | |
| 509 | |
| 510 gfx::Size MetricsLog::GetScreenSize() const { | 510 gfx::Size MetricsLog::GetScreenSize() const { |
| 511 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); | 511 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
| 512 } | 512 } |
| 513 | 513 |
| 514 float MetricsLog::GetScreenDeviceScaleFactor() const { | 514 float MetricsLog::GetScreenDeviceScaleFactor() const { |
| 515 return gfx::Screen::GetNativeScreen()-> | 515 return gfx::Screen::GetNativeScreen()-> |
| 516 GetPrimaryDisplay().device_scale_factor(); | 516 GetPrimaryDisplay().device_scale_factor(); |
| 517 } | 517 } |
| 518 | 518 |
| 519 int MetricsLog::GetScreenCount() const { | 519 int MetricsLog::GetScreenCount() const { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials) { | 694 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials) { |
| 695 DCHECK(!HasEnvironment()); | 695 DCHECK(!HasEnvironment()); |
| 696 | 696 |
| 697 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 697 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 698 | 698 |
| 699 std::string brand_code; | 699 std::string brand_code; |
| 700 if (google_util::GetBrand(&brand_code)) | 700 if (google_util::GetBrand(&brand_code)) |
| 701 system_profile->set_brand_code(brand_code); | 701 system_profile->set_brand_code(brand_code); |
| 702 | 702 |
| 703 int enabled_date; | 703 int enabled_date; |
| 704 bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()), | 704 bool success = |
| 705 &enabled_date); | 705 base::StringToInt(GetMetricsEnabledDate(local_state_), &enabled_date); |
| 706 DCHECK(success); | 706 DCHECK(success); |
| 707 | 707 |
| 708 // Reduce granularity of the enabled_date field to nearest hour. | 708 // Reduce granularity of the enabled_date field to nearest hour. |
| 709 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date)); | 709 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date)); |
| 710 | 710 |
| 711 int64 install_date = GetPrefService()->GetInt64(prefs::kInstallDate); | 711 int64 install_date = local_state_->GetInt64(prefs::kInstallDate); |
| 712 | 712 |
| 713 // Reduce granularity of the install_date field to nearest hour. | 713 // Reduce granularity of the install_date field to nearest hour. |
| 714 system_profile->set_install_date(RoundSecondsToHour(install_date)); | 714 system_profile->set_install_date(RoundSecondsToHour(install_date)); |
| 715 | 715 |
| 716 system_profile->set_application_locale( | 716 system_profile->set_application_locale( |
| 717 g_browser_process->GetApplicationLocale()); | 717 g_browser_process->GetApplicationLocale()); |
| 718 | 718 |
| 719 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); | 719 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); |
| 720 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); | 720 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
| 721 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); | 721 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 WriteFieldTrials(synthetic_trials, system_profile); | 792 WriteFieldTrials(synthetic_trials, system_profile); |
| 793 | 793 |
| 794 #if defined(OS_CHROMEOS) | 794 #if defined(OS_CHROMEOS) |
| 795 metrics_log_chromeos_->LogChromeOSMetrics(); | 795 metrics_log_chromeos_->LogChromeOSMetrics(); |
| 796 #endif // OS_CHROMEOS | 796 #endif // OS_CHROMEOS |
| 797 | 797 |
| 798 std::string serialied_system_profile; | 798 std::string serialied_system_profile; |
| 799 std::string base64_system_profile; | 799 std::string base64_system_profile; |
| 800 if (system_profile->SerializeToString(&serialied_system_profile)) { | 800 if (system_profile->SerializeToString(&serialied_system_profile)) { |
| 801 base::Base64Encode(serialied_system_profile, &base64_system_profile); | 801 base::Base64Encode(serialied_system_profile, &base64_system_profile); |
| 802 PrefService* local_state = GetPrefService(); | 802 PrefService* local_state = local_state_; |
| 803 local_state->SetString(prefs::kStabilitySavedSystemProfile, | 803 local_state->SetString(prefs::kStabilitySavedSystemProfile, |
| 804 base64_system_profile); | 804 base64_system_profile); |
| 805 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, | 805 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
| 806 ComputeSHA1(serialied_system_profile)); | 806 ComputeSHA1(serialied_system_profile)); |
| 807 } | 807 } |
| 808 } | 808 } |
| 809 | 809 |
| 810 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { | 810 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
| 811 PrefService* local_state = GetPrefService(); | 811 PrefService* local_state = local_state_; |
| 812 const std::string base64_system_profile = | 812 const std::string base64_system_profile = |
| 813 local_state->GetString(prefs::kStabilitySavedSystemProfile); | 813 local_state->GetString(prefs::kStabilitySavedSystemProfile); |
| 814 if (base64_system_profile.empty()) | 814 if (base64_system_profile.empty()) |
| 815 return false; | 815 return false; |
| 816 | 816 |
| 817 const std::string system_profile_hash = | 817 const std::string system_profile_hash = |
| 818 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); | 818 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); |
| 819 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); | 819 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); |
| 820 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); | 820 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); |
| 821 | 821 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 ProductDataToProto(google_update_metrics.google_update_data, | 940 ProductDataToProto(google_update_metrics.google_update_data, |
| 941 google_update->mutable_google_update_status()); | 941 google_update->mutable_google_update_status()); |
| 942 } | 942 } |
| 943 | 943 |
| 944 if (!google_update_metrics.product_data.version.empty()) { | 944 if (!google_update_metrics.product_data.version.empty()) { |
| 945 ProductDataToProto(google_update_metrics.product_data, | 945 ProductDataToProto(google_update_metrics.product_data, |
| 946 google_update->mutable_client_status()); | 946 google_update->mutable_client_status()); |
| 947 } | 947 } |
| 948 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) | 948 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 949 } | 949 } |
| OLD | NEW |