| 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 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/browser/profiles/profile_manager.h" | 37 #include "chrome/browser/profiles/profile_manager.h" |
| 38 #include "chrome/common/chrome_version_info.h" | 38 #include "chrome/common/chrome_version_info.h" |
| 39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/installer/util/google_update_settings.h" | 40 #include "chrome/installer/util/google_update_settings.h" |
| 41 #include "components/metrics/metrics_data_provider.h" | 41 #include "components/metrics/metrics_data_provider.h" |
| 42 #include "components/metrics/proto/omnibox_event.pb.h" | 42 #include "components/metrics/proto/omnibox_event.pb.h" |
| 43 #include "components/metrics/proto/profiler_event.pb.h" | 43 #include "components/metrics/proto/profiler_event.pb.h" |
| 44 #include "components/metrics/proto/system_profile.pb.h" | 44 #include "components/metrics/proto/system_profile.pb.h" |
| 45 #include "components/nacl/common/nacl_process_type.h" | 45 #include "components/nacl/common/nacl_process_type.h" |
| 46 #include "components/variations/active_field_trials.h" | 46 #include "components/variations/active_field_trials.h" |
| 47 #include "content/public/browser/gpu_data_manager.h" | |
| 48 #include "content/public/common/content_client.h" | 47 #include "content/public/common/content_client.h" |
| 49 #include "content/public/common/webplugininfo.h" | 48 #include "content/public/common/webplugininfo.h" |
| 50 #include "gpu/config/gpu_info.h" | |
| 51 #include "ui/gfx/screen.h" | |
| 52 #include "url/gurl.h" | 49 #include "url/gurl.h" |
| 53 | 50 |
| 54 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
| 55 #include "base/android/build_info.h" | 52 #include "base/android/build_info.h" |
| 56 #endif | 53 #endif |
| 57 | 54 |
| 58 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 59 #include "base/win/metro.h" | 56 #include "base/win/metro.h" |
| 60 | 57 |
| 61 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 58 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 62 extern "C" IMAGE_DOS_HEADER __ImageBase; | 59 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 63 #endif | 60 #endif |
| 64 | 61 |
| 65 #if defined(OS_CHROMEOS) | 62 #if defined(OS_CHROMEOS) |
| 66 #include "chrome/browser/metrics/metrics_log_chromeos.h" | 63 #include "chrome/browser/metrics/metrics_log_chromeos.h" |
| 67 #endif // OS_CHROMEOS | 64 #endif // OS_CHROMEOS |
| 68 | 65 |
| 69 using content::GpuDataManager; | |
| 70 using metrics::MetricsLogBase; | 66 using metrics::MetricsLogBase; |
| 71 using metrics::OmniboxEventProto; | 67 using metrics::OmniboxEventProto; |
| 72 using metrics::ProfilerEventProto; | 68 using metrics::ProfilerEventProto; |
| 73 using metrics::SystemProfileProto; | 69 using metrics::SystemProfileProto; |
| 74 using tracked_objects::ProcessDataSnapshot; | 70 using tracked_objects::ProcessDataSnapshot; |
| 75 typedef variations::ActiveGroupId ActiveGroupId; | 71 typedef variations::ActiveGroupId ActiveGroupId; |
| 76 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; | 72 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; |
| 77 | 73 |
| 78 namespace { | 74 namespace { |
| 79 | 75 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 product_data.last_success.ToTimeT()); | 336 product_data.last_success.ToTimeT()); |
| 341 product_info->set_last_error(product_data.last_error_code); | 337 product_info->set_last_error(product_data.last_error_code); |
| 342 product_info->set_last_extra_error(product_data.last_extra_code); | 338 product_info->set_last_extra_error(product_data.last_extra_code); |
| 343 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) { | 339 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) { |
| 344 product_info->set_last_result( | 340 product_info->set_last_result( |
| 345 static_cast<ProductInfo::InstallResult>(product_data.last_result)); | 341 static_cast<ProductInfo::InstallResult>(product_data.last_result)); |
| 346 } | 342 } |
| 347 } | 343 } |
| 348 #endif | 344 #endif |
| 349 | 345 |
| 350 #if defined(OS_WIN) | |
| 351 struct ScreenDPIInformation { | |
| 352 double max_dpi_x; | |
| 353 double max_dpi_y; | |
| 354 }; | |
| 355 | |
| 356 // Called once for each connected monitor. | |
| 357 BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) { | |
| 358 const double kMillimetersPerInch = 25.4; | |
| 359 ScreenDPIInformation* screen_info = | |
| 360 reinterpret_cast<ScreenDPIInformation*>(dwData); | |
| 361 // Size of screen, in mm. | |
| 362 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE); | |
| 363 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE); | |
| 364 double dpi_x = (size_x > 0) ? | |
| 365 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0; | |
| 366 double dpi_y = (size_y > 0) ? | |
| 367 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0; | |
| 368 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x); | |
| 369 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y); | |
| 370 return TRUE; | |
| 371 } | |
| 372 | |
| 373 void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { | |
| 374 HDC desktop_dc = GetDC(NULL); | |
| 375 if (desktop_dc) { | |
| 376 ScreenDPIInformation si = {0, 0}; | |
| 377 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback, | |
| 378 reinterpret_cast<LPARAM>(&si))) { | |
| 379 hardware->set_max_dpi_x(si.max_dpi_x); | |
| 380 hardware->set_max_dpi_y(si.max_dpi_y); | |
| 381 } | |
| 382 ReleaseDC(GetDesktopWindow(), desktop_dc); | |
| 383 } | |
| 384 } | |
| 385 | |
| 386 #endif // defined(OS_WIN) | |
| 387 | |
| 388 // Round a timestamp measured in seconds since epoch to one with a granularity | 346 // Round a timestamp measured in seconds since epoch to one with a granularity |
| 389 // of an hour. This can be used before uploaded potentially sensitive | 347 // of an hour. This can be used before uploaded potentially sensitive |
| 390 // timestamps. | 348 // timestamps. |
| 391 int64 RoundSecondsToHour(int64 time_in_seconds) { | 349 int64 RoundSecondsToHour(int64 time_in_seconds) { |
| 392 return 3600 * (time_in_seconds / 3600); | 350 return 3600 * (time_in_seconds / 3600); |
| 393 } | 351 } |
| 394 | 352 |
| 395 } // namespace | 353 } // namespace |
| 396 | 354 |
| 397 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} | 355 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 void MetricsLog::RecordGeneralMetrics( | 470 void MetricsLog::RecordGeneralMetrics( |
| 513 const std::vector<metrics::MetricsDataProvider*>& data_providers) { | 471 const std::vector<metrics::MetricsDataProvider*>& data_providers) { |
| 514 for (size_t i = 0; i < data_providers.size(); ++i) | 472 for (size_t i = 0; i < data_providers.size(); ++i) |
| 515 data_providers[i]->ProvideGeneralMetrics(uma_proto()); | 473 data_providers[i]->ProvideGeneralMetrics(uma_proto()); |
| 516 } | 474 } |
| 517 | 475 |
| 518 PrefService* MetricsLog::GetPrefService() { | 476 PrefService* MetricsLog::GetPrefService() { |
| 519 return g_browser_process->local_state(); | 477 return g_browser_process->local_state(); |
| 520 } | 478 } |
| 521 | 479 |
| 522 gfx::Size MetricsLog::GetScreenSize() const { | |
| 523 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); | |
| 524 } | |
| 525 | |
| 526 float MetricsLog::GetScreenDeviceScaleFactor() const { | |
| 527 return gfx::Screen::GetNativeScreen()-> | |
| 528 GetPrimaryDisplay().device_scale_factor(); | |
| 529 } | |
| 530 | |
| 531 int MetricsLog::GetScreenCount() const { | |
| 532 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 | |
| 533 return gfx::Screen::GetNativeScreen()->GetNumDisplays(); | |
| 534 } | |
| 535 | |
| 536 void MetricsLog::GetFieldTrialIds( | 480 void MetricsLog::GetFieldTrialIds( |
| 537 std::vector<ActiveGroupId>* field_trial_ids) const { | 481 std::vector<ActiveGroupId>* field_trial_ids) const { |
| 538 variations::GetFieldTrialActiveGroupIds(field_trial_ids); | 482 variations::GetFieldTrialActiveGroupIds(field_trial_ids); |
| 539 } | 483 } |
| 540 | 484 |
| 541 bool MetricsLog::HasEnvironment() const { | 485 bool MetricsLog::HasEnvironment() const { |
| 542 return uma_proto()->system_profile().has_uma_enabled_date(); | 486 return uma_proto()->system_profile().has_uma_enabled_date(); |
| 543 } | 487 } |
| 544 | 488 |
| 545 bool MetricsLog::HasStabilityMetrics() const { | 489 bool MetricsLog::HasStabilityMetrics() const { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 #if defined(OS_ANDROID) | 706 #if defined(OS_ANDROID) |
| 763 os->set_fingerprint( | 707 os->set_fingerprint( |
| 764 base::android::BuildInfo::GetInstance()->android_build_fp()); | 708 base::android::BuildInfo::GetInstance()->android_build_fp()); |
| 765 #endif | 709 #endif |
| 766 | 710 |
| 767 base::CPU cpu_info; | 711 base::CPU cpu_info; |
| 768 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu(); | 712 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu(); |
| 769 cpu->set_vendor_name(cpu_info.vendor_name()); | 713 cpu->set_vendor_name(cpu_info.vendor_name()); |
| 770 cpu->set_signature(cpu_info.signature()); | 714 cpu->set_signature(cpu_info.signature()); |
| 771 | 715 |
| 772 const gpu::GPUInfo& gpu_info = | |
| 773 GpuDataManager::GetInstance()->GetGPUInfo(); | |
| 774 SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu(); | |
| 775 gpu->set_vendor_id(gpu_info.gpu.vendor_id); | |
| 776 gpu->set_device_id(gpu_info.gpu.device_id); | |
| 777 gpu->set_driver_version(gpu_info.driver_version); | |
| 778 gpu->set_driver_date(gpu_info.driver_date); | |
| 779 SystemProfileProto::Hardware::Graphics::PerformanceStatistics* | |
| 780 gpu_performance = gpu->mutable_performance_statistics(); | |
| 781 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); | |
| 782 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); | |
| 783 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); | |
| 784 gpu->set_gl_vendor(gpu_info.gl_vendor); | |
| 785 gpu->set_gl_renderer(gpu_info.gl_renderer); | |
| 786 | |
| 787 const gfx::Size display_size = GetScreenSize(); | |
| 788 hardware->set_primary_screen_width(display_size.width()); | |
| 789 hardware->set_primary_screen_height(display_size.height()); | |
| 790 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); | |
| 791 hardware->set_screen_count(GetScreenCount()); | |
| 792 | |
| 793 #if defined(OS_WIN) | |
| 794 WriteScreenDPIInformationProto(hardware); | |
| 795 #endif | |
| 796 | |
| 797 WriteGoogleUpdateProto(google_update_metrics); | 716 WriteGoogleUpdateProto(google_update_metrics); |
| 798 | 717 |
| 799 WritePluginList(plugin_list); | 718 WritePluginList(plugin_list); |
| 800 extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile()); | 719 extension_metrics_.WriteExtensionList(uma_proto()->mutable_system_profile()); |
| 801 | 720 |
| 802 std::vector<ActiveGroupId> field_trial_ids; | 721 std::vector<ActiveGroupId> field_trial_ids; |
| 803 GetFieldTrialIds(&field_trial_ids); | 722 GetFieldTrialIds(&field_trial_ids); |
| 804 WriteFieldTrials(field_trial_ids, system_profile); | 723 WriteFieldTrials(field_trial_ids, system_profile); |
| 805 WriteFieldTrials(synthetic_trials, system_profile); | 724 WriteFieldTrials(synthetic_trials, system_profile); |
| 806 | 725 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 ProductDataToProto(google_update_metrics.google_update_data, | 875 ProductDataToProto(google_update_metrics.google_update_data, |
| 957 google_update->mutable_google_update_status()); | 876 google_update->mutable_google_update_status()); |
| 958 } | 877 } |
| 959 | 878 |
| 960 if (!google_update_metrics.product_data.version.empty()) { | 879 if (!google_update_metrics.product_data.version.empty()) { |
| 961 ProductDataToProto(google_update_metrics.product_data, | 880 ProductDataToProto(google_update_metrics.product_data, |
| 962 google_update->mutable_client_status()); | 881 google_update->mutable_client_status()); |
| 963 } | 882 } |
| 964 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) | 883 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 965 } | 884 } |
| OLD | NEW |