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