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) | |
68 #include "chrome/browser/chromeos/login/user_manager.h" | |
69 #endif | |
70 | |
71 using content::GpuDataManager; | 64 using content::GpuDataManager; |
72 using metrics::OmniboxEventProto; | 65 using metrics::OmniboxEventProto; |
73 using metrics::PerfDataProto; | |
74 using metrics::ProfilerEventProto; | 66 using metrics::ProfilerEventProto; |
75 using metrics::SystemProfileProto; | 67 using metrics::SystemProfileProto; |
76 using tracked_objects::ProcessDataSnapshot; | 68 using tracked_objects::ProcessDataSnapshot; |
77 typedef chrome_variations::ActiveGroupId ActiveGroupId; | 69 typedef chrome_variations::ActiveGroupId ActiveGroupId; |
78 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; | 70 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; |
79 typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice; | |
80 | 71 |
81 namespace { | 72 namespace { |
82 | 73 |
83 // Returns the date at which the current metrics client ID was created as | 74 // 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. | 75 // a string containing seconds since the epoch, or "0" if none was found. |
85 std::string GetMetricsEnabledDate(PrefService* pref) { | 76 std::string GetMetricsEnabledDate(PrefService* pref) { |
86 if (!pref) { | 77 if (!pref) { |
87 NOTREACHED(); | 78 NOTREACHED(); |
88 return "0"; | 79 return "0"; |
89 } | 80 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 reinterpret_cast<LPARAM>(&si))) { | 327 reinterpret_cast<LPARAM>(&si))) { |
337 hardware->set_max_dpi_x(si.max_dpi_x); | 328 hardware->set_max_dpi_x(si.max_dpi_x); |
338 hardware->set_max_dpi_y(si.max_dpi_y); | 329 hardware->set_max_dpi_y(si.max_dpi_y); |
339 } | 330 } |
340 ReleaseDC(GetDesktopWindow(), desktop_dc); | 331 ReleaseDC(GetDesktopWindow(), desktop_dc); |
341 } | 332 } |
342 } | 333 } |
343 | 334 |
344 #endif // defined(OS_WIN) | 335 #endif // defined(OS_WIN) |
345 | 336 |
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 | 337 // 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 | 338 // of an hour. This can be used before uploaded potentially sensitive |
387 // timestamps. | 339 // timestamps. |
388 int64 RoundSecondsToHour(int64 time_in_seconds) { | 340 int64 RoundSecondsToHour(int64 time_in_seconds) { |
389 return 3600 * (time_in_seconds / 3600); | 341 return 3600 * (time_in_seconds / 3600); |
390 } | 342 } |
391 | 343 |
392 } // namespace | 344 } // namespace |
393 | 345 |
394 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} | 346 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
395 | 347 |
396 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} | 348 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
397 | 349 |
398 static base::LazyInstance<std::string>::Leaky | 350 static base::LazyInstance<std::string>::Leaky |
399 g_version_extension = LAZY_INSTANCE_INITIALIZER; | 351 g_version_extension = LAZY_INSTANCE_INITIALIZER; |
400 | 352 |
401 MetricsLog::MetricsLog(const std::string& client_id, int session_id) | 353 MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
402 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()), | 354 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()), |
403 creation_time_(base::TimeTicks::Now()) { | 355 creation_time_(base::TimeTicks::Now()) { |
404 #if defined(OS_CHROMEOS) | 356 #if defined(OS_CHROMEOS) |
405 UpdateMultiProfileUserCount(); | 357 metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); |
406 #endif | 358 #endif // OS_CHROMEOS |
407 } | 359 } |
408 | 360 |
409 MetricsLog::~MetricsLog() {} | 361 MetricsLog::~MetricsLog() {} |
410 | 362 |
411 // static | 363 // static |
412 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { | 364 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
413 registry->RegisterListPref(prefs::kStabilityPluginStats); | 365 registry->RegisterListPref(prefs::kStabilityPluginStats); |
414 } | 366 } |
415 | 367 |
416 // static | 368 // static |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); | 598 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
647 } | 599 } |
648 | 600 |
649 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); | 601 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
650 if (count) { | 602 if (count) { |
651 stability->set_child_process_crash_count(count); | 603 stability->set_child_process_crash_count(count); |
652 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); | 604 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
653 } | 605 } |
654 | 606 |
655 #if defined(OS_CHROMEOS) | 607 #if defined(OS_CHROMEOS) |
656 count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); | 608 metrics_log_chromeos_->WriteRealtimeStabilityAttributes(pref, stability); |
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 | 609 #endif // OS_CHROMEOS |
674 | 610 |
675 const uint64 uptime_sec = incremental_uptime.InSeconds(); | 611 const uint64 uptime_sec = incremental_uptime.InSeconds(); |
676 if (uptime_sec) | 612 if (uptime_sec) |
677 stability->set_uptime_sec(uptime_sec); | 613 stability->set_uptime_sec(uptime_sec); |
678 } | 614 } |
679 | 615 |
680 void MetricsLog::WritePluginList( | 616 void MetricsLog::WritePluginList( |
681 const std::vector<content::WebPluginInfo>& plugin_list) { | 617 const std::vector<content::WebPluginInfo>& plugin_list) { |
682 DCHECK(!locked()); | 618 DCHECK(!locked()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 | 724 |
789 WriteGoogleUpdateProto(google_update_metrics); | 725 WriteGoogleUpdateProto(google_update_metrics); |
790 | 726 |
791 WritePluginList(plugin_list); | 727 WritePluginList(plugin_list); |
792 | 728 |
793 std::vector<ActiveGroupId> field_trial_ids; | 729 std::vector<ActiveGroupId> field_trial_ids; |
794 GetFieldTrialIds(&field_trial_ids); | 730 GetFieldTrialIds(&field_trial_ids); |
795 WriteFieldTrials(field_trial_ids, system_profile); | 731 WriteFieldTrials(field_trial_ids, system_profile); |
796 WriteFieldTrials(synthetic_trials, system_profile); | 732 WriteFieldTrials(synthetic_trials, system_profile); |
797 | 733 |
798 #if defined(OS_CHROMEOS) | |
799 PerfDataProto perf_data_proto; | |
800 if (perf_provider_.GetPerfData(&perf_data_proto)) | |
801 uma_proto()->add_perf_data()->Swap(&perf_data_proto); | |
802 | |
803 WriteBluetoothProto(hardware); | |
804 UpdateMultiProfileUserCount(); | |
805 #endif | |
806 | |
807 std::string serialied_system_profile; | 734 std::string serialied_system_profile; |
808 std::string base64_system_profile; | 735 std::string base64_system_profile; |
809 if (system_profile->SerializeToString(&serialied_system_profile)) { | 736 if (system_profile->SerializeToString(&serialied_system_profile)) { |
810 base::Base64Encode(serialied_system_profile, &base64_system_profile); | 737 base::Base64Encode(serialied_system_profile, &base64_system_profile); |
811 PrefService* local_state = GetPrefService(); | 738 PrefService* local_state = GetPrefService(); |
812 local_state->SetString(prefs::kStabilitySavedSystemProfile, | 739 local_state->SetString(prefs::kStabilitySavedSystemProfile, |
813 base64_system_profile); | 740 base64_system_profile); |
814 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, | 741 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
815 ComputeSHA1(serialied_system_profile)); | 742 ComputeSHA1(serialied_system_profile)); |
816 } | 743 } |
744 | |
745 #if defined(OS_CHROMEOS) | |
746 metrics_log_chromeos_->LogChromeOSMetrics(uma_proto()); | |
Alexei Svitkine (slow)
2014/01/30 16:30:45
Please move this to where the old code was (above)
tdresser
2014/01/30 18:04:25
Done.
| |
747 #endif // OS_CHROMEOS | |
817 } | 748 } |
818 | 749 |
819 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { | 750 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
820 PrefService* local_state = GetPrefService(); | 751 PrefService* local_state = GetPrefService(); |
821 const std::string base64_system_profile = | 752 const std::string base64_system_profile = |
822 local_state->GetString(prefs::kStabilitySavedSystemProfile); | 753 local_state->GetString(prefs::kStabilitySavedSystemProfile); |
823 if (base64_system_profile.empty()) | 754 if (base64_system_profile.empty()) |
824 return false; | 755 return false; |
825 | 756 |
826 const std::string system_profile_hash = | 757 const std::string system_profile_hash = |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 ProductDataToProto(google_update_metrics.google_update_data, | 866 ProductDataToProto(google_update_metrics.google_update_data, |
936 google_update->mutable_google_update_status()); | 867 google_update->mutable_google_update_status()); |
937 } | 868 } |
938 | 869 |
939 if (!google_update_metrics.product_data.version.empty()) { | 870 if (!google_update_metrics.product_data.version.empty()) { |
940 ProductDataToProto(google_update_metrics.product_data, | 871 ProductDataToProto(google_update_metrics.product_data, |
941 google_update->mutable_client_status()); | 872 google_update->mutable_client_status()); |
942 } | 873 } |
943 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) | 874 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
944 } | 875 } |
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 |