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( | |
ramant (doing other things)
2014/02/03 17:45:27
nit: line# 77 and 78 could be combined into one li
tdresser
2014/02/03 17:55:34
Done.
| |
78 PrefService* pref) { | |
79 SystemProfileProto::Stability* stability = | |
80 uma_proto_->mutable_system_profile()->mutable_stability(); | |
81 | |
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 uma_proto_->mutable_system_profile()->mutable_hardware(); | |
104 | |
105 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that | |
106 // changes this will fail at the DCHECK(). | |
107 device::BluetoothAdapterFactory::GetAdapter( | |
108 base::Bind(&MetricsLogChromeOS::SetBluetoothAdapter, | |
109 base::Unretained(this))); | |
110 DCHECK(adapter_.get()); | |
111 | |
112 SystemProfileProto::Hardware::Bluetooth* bluetooth = | |
113 hardware->mutable_bluetooth(); | |
114 | |
115 bluetooth->set_is_present(adapter_->IsPresent()); | |
116 bluetooth->set_is_enabled(adapter_->IsPowered()); | |
117 | |
118 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | |
119 for (device::BluetoothAdapter::DeviceList::iterator iter = | |
120 devices.begin(); iter != devices.end(); ++iter) { | |
121 PairedDevice* paired_device = bluetooth->add_paired_device(); | |
122 | |
123 device::BluetoothDevice* device = *iter; | |
124 paired_device->set_bluetooth_class(device->GetBluetoothClass()); | |
125 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); | |
126 | |
127 // address is xx:xx:xx:xx:xx:xx, extract the first three components and | |
ramant (doing other things)
2014/02/03 17:45:27
nit: address -> |address|
nit: line# 128, period a
tdresser
2014/02/03 17:55:34
Done.
| |
128 // pack into a uint32 | |
129 std::string address = device->GetAddress(); | |
130 if (address.size() > 9 && | |
131 address[2] == ':' && address[5] == ':' && address[8] == ':') { | |
132 std::string vendor_prefix_str; | |
133 uint64 vendor_prefix; | |
134 | |
135 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); | |
136 DCHECK_EQ(6U, vendor_prefix_str.size()); | |
137 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); | |
138 | |
139 paired_device->set_vendor_prefix(vendor_prefix); | |
140 } | |
141 | |
142 paired_device->set_vendor_id(device->GetVendorID()); | |
143 paired_device->set_product_id(device->GetProductID()); | |
144 paired_device->set_device_id(device->GetDeviceID()); | |
145 } | |
146 } | |
147 | |
148 void MetricsLogChromeOS::UpdateMultiProfileUserCount() { | |
149 metrics::SystemProfileProto* system_profile = | |
150 uma_proto_->mutable_system_profile(); | |
151 | |
152 if (chromeos::UserManager::IsInitialized() && | |
153 chromeos::UserManager::Get()->IsMultipleProfilesAllowed()) { | |
154 size_t user_count = chromeos::UserManager::Get()->GetLoggedInUsers().size(); | |
155 | |
156 // We invalidate the user count if it changed while the log was open. | |
157 if (system_profile->has_multi_profile_user_count() && | |
158 user_count != system_profile->multi_profile_user_count()) { | |
159 user_count = 0; | |
160 } | |
161 | |
162 system_profile->set_multi_profile_user_count(user_count); | |
163 } | |
164 } | |
165 | |
166 void MetricsLogChromeOS::SetBluetoothAdapter( | |
167 scoped_refptr<device::BluetoothAdapter> adapter) { | |
168 adapter_ = adapter; | |
169 } | |
OLD | NEW |