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 device::BluetoothDevice::DeviceType device_type) { | |
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( | |
62 metrics::SystemProfileProto* system_profile) { | |
63 UpdateMultiProfileUserCount(system_profile); | |
64 } | |
65 | |
66 void MetricsLogChromeOS::LogChromeOSMetrics( | |
67 metrics::SystemProfileProto* system_profile, | |
68 metrics::ChromeUserMetricsExtension* uma_proto) { | |
69 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); | |
70 | |
71 PerfDataProto perf_data_proto; | |
72 if (perf_provider_.GetPerfData(&perf_data_proto)) | |
73 uma_proto->add_perf_data()->Swap(&perf_data_proto); | |
74 | |
75 WriteBluetoothProto(hardware); | |
76 UpdateMultiProfileUserCount(system_profile); | |
77 } | |
78 | |
79 void MetricsLogChromeOS::WriteRealtimeStabilityAttributes( | |
80 PrefService* pref, | |
81 metrics::SystemProfileProto::Stability* stability) { | |
82 int count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); | |
83 if (count) { | |
84 stability->set_other_user_crash_count(count); | |
85 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); | |
86 } | |
87 | |
88 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); | |
89 if (count) { | |
90 stability->set_kernel_crash_count(count); | |
91 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); | |
92 } | |
93 | |
94 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); | |
95 if (count) { | |
96 stability->set_unclean_system_shutdown_count(count); | |
97 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); | |
98 } | |
99 } | |
100 | |
101 void MetricsLogChromeOS::WriteBluetoothProto( | |
102 SystemProfileProto::Hardware* hardware) { | |
103 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that | |
104 // changes this will fail at the DCHECK(). | |
105 device::BluetoothAdapterFactory::GetAdapter( | |
106 base::Bind(&MetricsLogChromeOS::SetBluetoothAdapter, | |
107 base::Unretained(this))); | |
108 DCHECK(adapter_.get()); | |
109 | |
110 SystemProfileProto::Hardware::Bluetooth* bluetooth = | |
111 hardware->mutable_bluetooth(); | |
112 | |
113 bluetooth->set_is_present(adapter_->IsPresent()); | |
114 bluetooth->set_is_enabled(adapter_->IsPowered()); | |
115 | |
116 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | |
117 for (device::BluetoothAdapter::DeviceList::iterator iter = | |
118 devices.begin(); iter != devices.end(); ++iter) { | |
119 PairedDevice* paired_device = bluetooth->add_paired_device(); | |
120 | |
121 device::BluetoothDevice* device = *iter; | |
122 paired_device->set_bluetooth_class(device->GetBluetoothClass()); | |
123 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); | |
124 | |
125 // address is xx:xx:xx:xx:xx:xx, extract the first three components and | |
126 // pack into a uint32 | |
127 std::string address = device->GetAddress(); | |
128 if (address.size() > 9 && | |
129 address[2] == ':' && address[5] == ':' && address[8] == ':') { | |
130 std::string vendor_prefix_str; | |
131 uint64 vendor_prefix; | |
132 | |
133 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); | |
134 DCHECK_EQ(6U, vendor_prefix_str.size()); | |
135 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); | |
136 | |
137 paired_device->set_vendor_prefix(vendor_prefix); | |
138 } | |
139 | |
140 paired_device->set_vendor_id(device->GetVendorID()); | |
141 paired_device->set_product_id(device->GetProductID()); | |
142 paired_device->set_device_id(device->GetDeviceID()); | |
143 } | |
144 } | |
145 | |
146 void MetricsLogChromeOS::UpdateMultiProfileUserCount( | |
147 metrics::SystemProfileProto* system_profile) { | |
148 if (chromeos::UserManager::IsInitialized() && | |
149 chromeos::UserManager::Get()->IsMultipleProfilesAllowed()) { | |
150 size_t user_count = chromeos::UserManager::Get() | |
Alexei Svitkine (slow)
2014/01/30 18:17:54
Nit: I'd wrap this like so:
size_t user_count =
tdresser
2014/01/30 19:32:30
Didn't actually need wrapping...
| |
151 ->GetLoggedInUsers().size(); | |
152 | |
153 // We invalidate the user count if it changed while the log was open. | |
154 if (system_profile->has_multi_profile_user_count() && | |
155 user_count != system_profile->multi_profile_user_count()) { | |
156 user_count = 0; | |
157 } | |
158 | |
159 system_profile->set_multi_profile_user_count(user_count); | |
160 } | |
161 } | |
162 | |
163 void MetricsLogChromeOS::SetBluetoothAdapter( | |
164 scoped_refptr<device::BluetoothAdapter> adapter) { | |
165 adapter_ = adapter; | |
166 } | |
OLD | NEW |