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 28 matching lines...) Expand all Loading... |
39 #include "chrome/common/metrics/proto/omnibox_event.pb.h" | 39 #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
40 #include "chrome/common/metrics/proto/profiler_event.pb.h" | 40 #include "chrome/common/metrics/proto/profiler_event.pb.h" |
41 #include "chrome/common/metrics/proto/system_profile.pb.h" | 41 #include "chrome/common/metrics/proto/system_profile.pb.h" |
42 #include "chrome/common/metrics/variations/variations_util.h" | 42 #include "chrome/common/metrics/variations/variations_util.h" |
43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
44 #include "chrome/installer/util/google_update_settings.h" | 44 #include "chrome/installer/util/google_update_settings.h" |
45 #include "components/nacl/common/nacl_process_type.h" | 45 #include "components/nacl/common/nacl_process_type.h" |
46 #include "content/public/browser/gpu_data_manager.h" | 46 #include "content/public/browser/gpu_data_manager.h" |
47 #include "content/public/common/content_client.h" | 47 #include "content/public/common/content_client.h" |
48 #include "content/public/common/webplugininfo.h" | 48 #include "content/public/common/webplugininfo.h" |
49 #include "device/bluetooth/bluetooth_adapter.h" | |
50 #include "device/bluetooth/bluetooth_adapter_factory.h" | |
51 #include "device/bluetooth/bluetooth_device.h" | |
52 #include "gpu/config/gpu_info.h" | 49 #include "gpu/config/gpu_info.h" |
53 #include "ui/gfx/screen.h" | 50 #include "ui/gfx/screen.h" |
54 #include "url/gurl.h" | 51 #include "url/gurl.h" |
55 | 52 |
56 #if defined(OS_ANDROID) | 53 #if defined(OS_ANDROID) |
57 #include "base/android/build_info.h" | 54 #include "base/android/build_info.h" |
58 #endif | 55 #endif |
59 | 56 |
60 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
61 #include "base/win/metro.h" | 58 #include "base/win/metro.h" |
62 | 59 |
63 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 60 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
64 extern "C" IMAGE_DOS_HEADER __ImageBase; | 61 extern "C" IMAGE_DOS_HEADER __ImageBase; |
65 #endif | 62 #endif |
66 | 63 |
67 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
68 #include "chrome/browser/chromeos/login/user_manager.h" | 65 #include "chrome/browser/metrics/metrics_log_chromeos.h" |
69 #endif | 66 #endif // OS_CHROMEOS |
70 | 67 |
71 using content::GpuDataManager; | 68 using content::GpuDataManager; |
72 using metrics::OmniboxEventProto; | 69 using metrics::OmniboxEventProto; |
73 using metrics::PerfDataProto; | |
74 using metrics::ProfilerEventProto; | 70 using metrics::ProfilerEventProto; |
75 using metrics::SystemProfileProto; | 71 using metrics::SystemProfileProto; |
76 using tracked_objects::ProcessDataSnapshot; | 72 using tracked_objects::ProcessDataSnapshot; |
77 typedef chrome_variations::ActiveGroupId ActiveGroupId; | 73 typedef chrome_variations::ActiveGroupId ActiveGroupId; |
78 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; | 74 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; |
79 typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice; | |
80 | 75 |
81 namespace { | 76 namespace { |
82 | 77 |
83 // Returns the date at which the current metrics client ID was created as | 78 // Returns the date at which the current metrics client ID was created as |
84 // a string containing seconds since the epoch, or "0" if none was found. | 79 // a string containing seconds since the epoch, or "0" if none was found. |
85 std::string GetMetricsEnabledDate(PrefService* pref) { | 80 std::string GetMetricsEnabledDate(PrefService* pref) { |
86 if (!pref) { | 81 if (!pref) { |
87 NOTREACHED(); | 82 NOTREACHED(); |
88 return "0"; | 83 return "0"; |
89 } | 84 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 reinterpret_cast<LPARAM>(&si))) { | 331 reinterpret_cast<LPARAM>(&si))) { |
337 hardware->set_max_dpi_x(si.max_dpi_x); | 332 hardware->set_max_dpi_x(si.max_dpi_x); |
338 hardware->set_max_dpi_y(si.max_dpi_y); | 333 hardware->set_max_dpi_y(si.max_dpi_y); |
339 } | 334 } |
340 ReleaseDC(GetDesktopWindow(), desktop_dc); | 335 ReleaseDC(GetDesktopWindow(), desktop_dc); |
341 } | 336 } |
342 } | 337 } |
343 | 338 |
344 #endif // defined(OS_WIN) | 339 #endif // defined(OS_WIN) |
345 | 340 |
346 #if defined(OS_CHROMEOS) | |
347 PairedDevice::Type AsBluetoothDeviceType( | |
348 enum device::BluetoothDevice::DeviceType device_type) { | |
349 switch (device_type) { | |
350 case device::BluetoothDevice::DEVICE_UNKNOWN: | |
351 return PairedDevice::DEVICE_UNKNOWN; | |
352 case device::BluetoothDevice::DEVICE_COMPUTER: | |
353 return PairedDevice::DEVICE_COMPUTER; | |
354 case device::BluetoothDevice::DEVICE_PHONE: | |
355 return PairedDevice::DEVICE_PHONE; | |
356 case device::BluetoothDevice::DEVICE_MODEM: | |
357 return PairedDevice::DEVICE_MODEM; | |
358 case device::BluetoothDevice::DEVICE_AUDIO: | |
359 return PairedDevice::DEVICE_AUDIO; | |
360 case device::BluetoothDevice::DEVICE_CAR_AUDIO: | |
361 return PairedDevice::DEVICE_CAR_AUDIO; | |
362 case device::BluetoothDevice::DEVICE_VIDEO: | |
363 return PairedDevice::DEVICE_VIDEO; | |
364 case device::BluetoothDevice::DEVICE_PERIPHERAL: | |
365 return PairedDevice::DEVICE_PERIPHERAL; | |
366 case device::BluetoothDevice::DEVICE_JOYSTICK: | |
367 return PairedDevice::DEVICE_JOYSTICK; | |
368 case device::BluetoothDevice::DEVICE_GAMEPAD: | |
369 return PairedDevice::DEVICE_GAMEPAD; | |
370 case device::BluetoothDevice::DEVICE_KEYBOARD: | |
371 return PairedDevice::DEVICE_KEYBOARD; | |
372 case device::BluetoothDevice::DEVICE_MOUSE: | |
373 return PairedDevice::DEVICE_MOUSE; | |
374 case device::BluetoothDevice::DEVICE_TABLET: | |
375 return PairedDevice::DEVICE_TABLET; | |
376 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO: | |
377 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO; | |
378 } | |
379 | |
380 NOTREACHED(); | |
381 return PairedDevice::DEVICE_UNKNOWN; | |
382 } | |
383 #endif // defined(OS_CHROMEOS) | |
384 | |
385 // Round a timestamp measured in seconds since epoch to one with a granularity | 341 // Round a timestamp measured in seconds since epoch to one with a granularity |
386 // of an hour. This can be used before uploaded potentially sensitive | 342 // of an hour. This can be used before uploaded potentially sensitive |
387 // timestamps. | 343 // timestamps. |
388 int64 RoundSecondsToHour(int64 time_in_seconds) { | 344 int64 RoundSecondsToHour(int64 time_in_seconds) { |
389 return 3600 * (time_in_seconds / 3600); | 345 return 3600 * (time_in_seconds / 3600); |
390 } | 346 } |
391 | 347 |
392 } // namespace | 348 } // namespace |
393 | 349 |
394 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} | 350 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
395 | 351 |
396 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} | 352 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
397 | 353 |
398 static base::LazyInstance<std::string>::Leaky | 354 static base::LazyInstance<std::string>::Leaky |
399 g_version_extension = LAZY_INSTANCE_INITIALIZER; | 355 g_version_extension = LAZY_INSTANCE_INITIALIZER; |
400 | 356 |
401 MetricsLog::MetricsLog(const std::string& client_id, int session_id) | 357 MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
402 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()), | 358 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()), |
403 creation_time_(base::TimeTicks::Now()) { | 359 creation_time_(base::TimeTicks::Now()) { |
404 #if defined(OS_CHROMEOS) | 360 #if defined(OS_CHROMEOS) |
405 UpdateMultiProfileUserCount(); | 361 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); |
406 #endif | 362 #endif // OS_CHROMEOS |
407 } | 363 } |
408 | 364 |
409 MetricsLog::~MetricsLog() {} | 365 MetricsLog::~MetricsLog() {} |
410 | 366 |
411 // static | 367 // static |
412 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { | 368 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
413 registry->RegisterListPref(prefs::kStabilityPluginStats); | 369 registry->RegisterListPref(prefs::kStabilityPluginStats); |
414 } | 370 } |
415 | 371 |
416 // static | 372 // static |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); | 602 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
647 } | 603 } |
648 | 604 |
649 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); | 605 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
650 if (count) { | 606 if (count) { |
651 stability->set_child_process_crash_count(count); | 607 stability->set_child_process_crash_count(count); |
652 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); | 608 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
653 } | 609 } |
654 | 610 |
655 #if defined(OS_CHROMEOS) | 611 #if defined(OS_CHROMEOS) |
656 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); | 612 metrics_log_chromeos_->WriteRealtimeStabilityAttributes(pref); |
657 if (count) { | |
658 stability->set_other_user_crash_count(count); | |
659 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); | |
660 } | |
661 | |
662 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); | |
663 if (count) { | |
664 stability->set_kernel_crash_count(count); | |
665 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); | |
666 } | |
667 | |
668 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); | |
669 if (count) { | |
670 stability->set_unclean_system_shutdown_count(count); | |
671 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); | |
672 } | |
673 #endif // OS_CHROMEOS | 613 #endif // OS_CHROMEOS |
674 | 614 |
675 const uint64 uptime_sec = incremental_uptime.InSeconds(); | 615 const uint64 uptime_sec = incremental_uptime.InSeconds(); |
676 if (uptime_sec) | 616 if (uptime_sec) |
677 stability->set_uptime_sec(uptime_sec); | 617 stability->set_uptime_sec(uptime_sec); |
678 } | 618 } |
679 | 619 |
680 void MetricsLog::WritePluginList( | 620 void MetricsLog::WritePluginList( |
681 const std::vector<content::WebPluginInfo>& plugin_list) { | 621 const std::vector<content::WebPluginInfo>& plugin_list) { |
682 DCHECK(!locked()); | 622 DCHECK(!locked()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 WriteGoogleUpdateProto(google_update_metrics); | 729 WriteGoogleUpdateProto(google_update_metrics); |
790 | 730 |
791 WritePluginList(plugin_list); | 731 WritePluginList(plugin_list); |
792 | 732 |
793 std::vector<ActiveGroupId> field_trial_ids; | 733 std::vector<ActiveGroupId> field_trial_ids; |
794 GetFieldTrialIds(&field_trial_ids); | 734 GetFieldTrialIds(&field_trial_ids); |
795 WriteFieldTrials(field_trial_ids, system_profile); | 735 WriteFieldTrials(field_trial_ids, system_profile); |
796 WriteFieldTrials(synthetic_trials, system_profile); | 736 WriteFieldTrials(synthetic_trials, system_profile); |
797 | 737 |
798 #if defined(OS_CHROMEOS) | 738 #if defined(OS_CHROMEOS) |
799 PerfDataProto perf_data_proto; | 739 metrics_log_chromeos_->LogChromeOSMetrics(); |
800 if (perf_provider_.GetPerfData(&perf_data_proto)) | 740 #endif // OS_CHROMEOS |
801 uma_proto()->add_perf_data()->Swap(&perf_data_proto); | |
802 | |
803 WriteBluetoothProto(hardware); | |
804 UpdateMultiProfileUserCount(); | |
805 #endif | |
806 | 741 |
807 std::string serialied_system_profile; | 742 std::string serialied_system_profile; |
808 std::string base64_system_profile; | 743 std::string base64_system_profile; |
809 if (system_profile->SerializeToString(&serialied_system_profile)) { | 744 if (system_profile->SerializeToString(&serialied_system_profile)) { |
810 base::Base64Encode(serialied_system_profile, &base64_system_profile); | 745 base::Base64Encode(serialied_system_profile, &base64_system_profile); |
811 PrefService* local_state = GetPrefService(); | 746 PrefService* local_state = GetPrefService(); |
812 local_state->SetString(prefs::kStabilitySavedSystemProfile, | 747 local_state->SetString(prefs::kStabilitySavedSystemProfile, |
813 base64_system_profile); | 748 base64_system_profile); |
814 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, | 749 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
815 ComputeSHA1(serialied_system_profile)); | 750 ComputeSHA1(serialied_system_profile)); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 ProductDataToProto(google_update_metrics.google_update_data, | 870 ProductDataToProto(google_update_metrics.google_update_data, |
936 google_update->mutable_google_update_status()); | 871 google_update->mutable_google_update_status()); |
937 } | 872 } |
938 | 873 |
939 if (!google_update_metrics.product_data.version.empty()) { | 874 if (!google_update_metrics.product_data.version.empty()) { |
940 ProductDataToProto(google_update_metrics.product_data, | 875 ProductDataToProto(google_update_metrics.product_data, |
941 google_update->mutable_client_status()); | 876 google_update->mutable_client_status()); |
942 } | 877 } |
943 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) | 878 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
944 } | 879 } |
945 | |
946 void MetricsLog::SetBluetoothAdapter( | |
947 scoped_refptr<device::BluetoothAdapter> adapter) { | |
948 adapter_ = adapter; | |
949 } | |
950 | |
951 void MetricsLog::WriteBluetoothProto( | |
952 SystemProfileProto::Hardware* hardware) { | |
953 #if defined(OS_CHROMEOS) | |
954 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that | |
955 // changes this will fail at the DCHECK(). | |
956 device::BluetoothAdapterFactory::GetAdapter( | |
957 base::Bind(&MetricsLog::SetBluetoothAdapter, | |
958 base::Unretained(this))); | |
959 DCHECK(adapter_.get()); | |
960 | |
961 SystemProfileProto::Hardware::Bluetooth* bluetooth = | |
962 hardware->mutable_bluetooth(); | |
963 | |
964 bluetooth->set_is_present(adapter_->IsPresent()); | |
965 bluetooth->set_is_enabled(adapter_->IsPowered()); | |
966 | |
967 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | |
968 for (device::BluetoothAdapter::DeviceList::iterator iter = | |
969 devices.begin(); iter != devices.end(); ++iter) { | |
970 PairedDevice* paired_device = bluetooth->add_paired_device(); | |
971 | |
972 device::BluetoothDevice* device = *iter; | |
973 paired_device->set_bluetooth_class(device->GetBluetoothClass()); | |
974 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); | |
975 | |
976 // address is xx:xx:xx:xx:xx:xx, extract the first three components and | |
977 // pack into a uint32 | |
978 std::string address = device->GetAddress(); | |
979 if (address.size() > 9 && | |
980 address[2] == ':' && address[5] == ':' && address[8] == ':') { | |
981 std::string vendor_prefix_str; | |
982 uint64 vendor_prefix; | |
983 | |
984 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); | |
985 DCHECK_EQ(6U, vendor_prefix_str.size()); | |
986 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); | |
987 | |
988 paired_device->set_vendor_prefix(vendor_prefix); | |
989 } | |
990 | |
991 paired_device->set_vendor_id(device->GetVendorID()); | |
992 paired_device->set_product_id(device->GetProductID()); | |
993 paired_device->set_device_id(device->GetDeviceID()); | |
994 } | |
995 #endif // defined(OS_CHROMEOS) | |
996 } | |
997 | |
998 #if defined(OS_CHROMEOS) | |
999 void MetricsLog::UpdateMultiProfileUserCount() { | |
1000 if (chromeos::UserManager::IsInitialized() && | |
1001 chromeos::UserManager::Get()->IsMultipleProfilesAllowed()) { | |
1002 uint32 user_count = chromeos::UserManager::Get() | |
1003 ->GetLoggedInUsers().size(); | |
1004 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | |
1005 | |
1006 // We invalidate the user count if it changed while the log was open. | |
1007 if (system_profile->has_multi_profile_user_count() && | |
1008 user_count != system_profile->multi_profile_user_count()) | |
1009 user_count = 0; | |
1010 | |
1011 system_profile->set_multi_profile_user_count(user_count); | |
1012 } | |
1013 } | |
1014 #endif | |
OLD | NEW |