OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/metrics/metrics_log_chromeos.h" |
| 6 |
| 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chromeos/login/user_manager.h" |
| 12 #include "chrome/common/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 13 #include "chrome/common/pref_names.h" |
| 14 #include "device/bluetooth/bluetooth_adapter.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 16 #include "device/bluetooth/bluetooth_device.h" |
| 17 |
| 18 using metrics::ChromeUserMetricsExtension; |
| 19 using metrics::PerfDataProto; |
| 20 using metrics::SystemProfileProto; |
| 21 typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice; |
| 22 |
| 23 PairedDevice::Type AsBluetoothDeviceType( |
| 24 device::BluetoothDevice::DeviceType device_type) { |
| 25 switch (device_type) { |
| 26 case device::BluetoothDevice::DEVICE_UNKNOWN: |
| 27 return PairedDevice::DEVICE_UNKNOWN; |
| 28 case device::BluetoothDevice::DEVICE_COMPUTER: |
| 29 return PairedDevice::DEVICE_COMPUTER; |
| 30 case device::BluetoothDevice::DEVICE_PHONE: |
| 31 return PairedDevice::DEVICE_PHONE; |
| 32 case device::BluetoothDevice::DEVICE_MODEM: |
| 33 return PairedDevice::DEVICE_MODEM; |
| 34 case device::BluetoothDevice::DEVICE_AUDIO: |
| 35 return PairedDevice::DEVICE_AUDIO; |
| 36 case device::BluetoothDevice::DEVICE_CAR_AUDIO: |
| 37 return PairedDevice::DEVICE_CAR_AUDIO; |
| 38 case device::BluetoothDevice::DEVICE_VIDEO: |
| 39 return PairedDevice::DEVICE_VIDEO; |
| 40 case device::BluetoothDevice::DEVICE_PERIPHERAL: |
| 41 return PairedDevice::DEVICE_PERIPHERAL; |
| 42 case device::BluetoothDevice::DEVICE_JOYSTICK: |
| 43 return PairedDevice::DEVICE_JOYSTICK; |
| 44 case device::BluetoothDevice::DEVICE_GAMEPAD: |
| 45 return PairedDevice::DEVICE_GAMEPAD; |
| 46 case device::BluetoothDevice::DEVICE_KEYBOARD: |
| 47 return PairedDevice::DEVICE_KEYBOARD; |
| 48 case device::BluetoothDevice::DEVICE_MOUSE: |
| 49 return PairedDevice::DEVICE_MOUSE; |
| 50 case device::BluetoothDevice::DEVICE_TABLET: |
| 51 return PairedDevice::DEVICE_TABLET; |
| 52 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO: |
| 53 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO; |
| 54 } |
| 55 |
| 56 NOTREACHED(); |
| 57 return PairedDevice::DEVICE_UNKNOWN; |
| 58 } |
| 59 |
| 60 MetricsLogChromeOS::~MetricsLogChromeOS() { |
| 61 } |
| 62 |
| 63 MetricsLogChromeOS::MetricsLogChromeOS(ChromeUserMetricsExtension* uma_proto) |
| 64 : uma_proto_(uma_proto) { |
| 65 UpdateMultiProfileUserCount(); |
| 66 } |
| 67 |
| 68 void MetricsLogChromeOS::LogChromeOSMetrics() { |
| 69 PerfDataProto perf_data_proto; |
| 70 if (perf_provider_.GetPerfData(&perf_data_proto)) |
| 71 uma_proto_->add_perf_data()->Swap(&perf_data_proto); |
| 72 |
| 73 WriteBluetoothProto(); |
| 74 UpdateMultiProfileUserCount(); |
| 75 } |
| 76 |
| 77 void MetricsLogChromeOS::WriteRealtimeStabilityAttributes(PrefService* pref) { |
| 78 SystemProfileProto::Stability* stability = |
| 79 uma_proto_->mutable_system_profile()->mutable_stability(); |
| 80 |
| 81 int count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
| 82 if (count) { |
| 83 stability->set_other_user_crash_count(count); |
| 84 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
| 85 } |
| 86 |
| 87 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
| 88 if (count) { |
| 89 stability->set_kernel_crash_count(count); |
| 90 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
| 91 } |
| 92 |
| 93 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
| 94 if (count) { |
| 95 stability->set_unclean_system_shutdown_count(count); |
| 96 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 97 } |
| 98 } |
| 99 |
| 100 void MetricsLogChromeOS::WriteBluetoothProto() { |
| 101 SystemProfileProto::Hardware* hardware = |
| 102 uma_proto_->mutable_system_profile()->mutable_hardware(); |
| 103 |
| 104 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that |
| 105 // changes this will fail at the DCHECK(). |
| 106 device::BluetoothAdapterFactory::GetAdapter( |
| 107 base::Bind(&MetricsLogChromeOS::SetBluetoothAdapter, |
| 108 base::Unretained(this))); |
| 109 DCHECK(adapter_.get()); |
| 110 |
| 111 SystemProfileProto::Hardware::Bluetooth* bluetooth = |
| 112 hardware->mutable_bluetooth(); |
| 113 |
| 114 bluetooth->set_is_present(adapter_->IsPresent()); |
| 115 bluetooth->set_is_enabled(adapter_->IsPowered()); |
| 116 |
| 117 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 118 for (device::BluetoothAdapter::DeviceList::iterator iter = |
| 119 devices.begin(); iter != devices.end(); ++iter) { |
| 120 PairedDevice* paired_device = bluetooth->add_paired_device(); |
| 121 |
| 122 device::BluetoothDevice* device = *iter; |
| 123 paired_device->set_bluetooth_class(device->GetBluetoothClass()); |
| 124 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); |
| 125 |
| 126 // |address| is xx:xx:xx:xx:xx:xx, extract the first three components and |
| 127 // pack into a uint32. |
| 128 std::string address = device->GetAddress(); |
| 129 if (address.size() > 9 && |
| 130 address[2] == ':' && address[5] == ':' && address[8] == ':') { |
| 131 std::string vendor_prefix_str; |
| 132 uint64 vendor_prefix; |
| 133 |
| 134 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); |
| 135 DCHECK_EQ(6U, vendor_prefix_str.size()); |
| 136 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); |
| 137 |
| 138 paired_device->set_vendor_prefix(vendor_prefix); |
| 139 } |
| 140 |
| 141 paired_device->set_vendor_id(device->GetVendorID()); |
| 142 paired_device->set_product_id(device->GetProductID()); |
| 143 paired_device->set_device_id(device->GetDeviceID()); |
| 144 } |
| 145 } |
| 146 |
| 147 void MetricsLogChromeOS::UpdateMultiProfileUserCount() { |
| 148 metrics::SystemProfileProto* system_profile = |
| 149 uma_proto_->mutable_system_profile(); |
| 150 |
| 151 if (chromeos::UserManager::IsInitialized() && |
| 152 chromeos::UserManager::Get()->IsMultipleProfilesAllowed()) { |
| 153 size_t user_count = chromeos::UserManager::Get()->GetLoggedInUsers().size(); |
| 154 |
| 155 // We invalidate the user count if it changed while the log was open. |
| 156 if (system_profile->has_multi_profile_user_count() && |
| 157 user_count != system_profile->multi_profile_user_count()) { |
| 158 user_count = 0; |
| 159 } |
| 160 |
| 161 system_profile->set_multi_profile_user_count(user_count); |
| 162 } |
| 163 } |
| 164 |
| 165 void MetricsLogChromeOS::SetBluetoothAdapter( |
| 166 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 167 adapter_ = adapter; |
| 168 } |
OLD | NEW |