Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "chrome/browser/metrics/chromeos_metrics_provider.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/chromeos/login/users/user_manager.h" | 12 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 13 #include "chrome/browser/metrics/metrics_service.h" | |
| 12 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 13 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 15 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 14 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 17 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 16 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
| 17 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 18 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| 19 | 21 |
| 20 #if defined(USE_X11) | 22 #if defined(USE_X11) |
| 21 #include "ui/events/x/touch_factory_x11.h" | 23 #include "ui/events/x/touch_factory_x11.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 it != touchscreen_ids.end(); | 75 it != touchscreen_ids.end(); |
| 74 ++it) { | 76 ++it) { |
| 75 SystemProfileProto::Hardware::TouchScreen* touchscreen = | 77 SystemProfileProto::Hardware::TouchScreen* touchscreen = |
| 76 hardware->add_external_touchscreen(); | 78 hardware->add_external_touchscreen(); |
| 77 touchscreen->set_vendor_id(it->first); | 79 touchscreen->set_vendor_id(it->first); |
| 78 touchscreen->set_product_id(it->second); | 80 touchscreen->set_product_id(it->second); |
| 79 } | 81 } |
| 80 #endif // defined(USE_X11) | 82 #endif // defined(USE_X11) |
| 81 } | 83 } |
| 82 | 84 |
| 85 void IncrementPrefValue(const char* path) { | |
| 86 PrefService* pref = g_browser_process->local_state(); | |
| 87 DCHECK(pref); | |
| 88 int value = pref->GetInteger(path); | |
| 89 pref->SetInteger(path, value + 1); | |
| 90 } | |
| 91 | |
| 83 } // namespace | 92 } // namespace |
| 84 | 93 |
| 85 MetricsLogChromeOS::~MetricsLogChromeOS() { | 94 ChromeOSMetricsProvider::ChromeOSMetricsProvider() |
| 95 : user_count_at_log_initialization_(0) { | |
| 86 } | 96 } |
| 87 | 97 |
| 88 MetricsLogChromeOS::MetricsLogChromeOS(ChromeUserMetricsExtension* uma_proto) | 98 ChromeOSMetricsProvider::~ChromeOSMetricsProvider() { |
| 89 : uma_proto_(uma_proto) { | |
| 90 UpdateMultiProfileUserCount(); | |
| 91 } | 99 } |
| 92 | 100 |
| 93 void MetricsLogChromeOS::LogChromeOSMetrics() { | 101 // static |
| 102 void ChromeOSMetricsProvider::LogChromeOSCrash(const std::string& crash_type) { | |
| 103 if (crash_type == "user") | |
| 104 IncrementPrefValue(prefs::kStabilityOtherUserCrashCount); | |
| 105 else if (crash_type == "kernel") | |
| 106 IncrementPrefValue(prefs::kStabilityKernelCrashCount); | |
|
Alexei Svitkine (slow)
2014/05/23 08:41:47
Can you move the registration of these prefs to a
blundell
2014/05/23 12:09:22
Done.
| |
| 107 else if (crash_type == "uncleanshutdown") | |
| 108 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); | |
| 109 else | |
| 110 NOTREACHED() << "Unexpected Chrome OS crash type " << crash_type; | |
| 111 | |
| 112 // TODO(blundell): Should this check be at the beginning to preserve current | |
| 113 // behavior? | |
| 114 // Wake up metrics logs sending if necessary now that new | |
| 115 // log data is available. | |
| 116 if (g_browser_process && g_browser_process->metrics_service()) | |
| 117 g_browser_process->metrics_service()->OnApplicationNotIdle(); | |
| 118 } | |
| 119 | |
| 120 void ChromeOSMetricsProvider::OnDidCreateMetricsLog() { | |
| 121 if (chromeos::UserManager::IsInitialized()) { | |
| 122 user_count_at_log_initialization_ = | |
| 123 chromeos::UserManager::Get()->GetLoggedInUsers().size(); | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 void ChromeOSMetricsProvider::ProvideSystemProfileMetrics( | |
| 128 metrics::SystemProfileProto* system_profile_proto) { | |
| 94 std::vector<PerfDataProto> perf_data; | 129 std::vector<PerfDataProto> perf_data; |
| 95 if (perf_provider_.GetPerfData(&perf_data)) { | 130 if (perf_provider_.GetPerfData(&perf_data)) { |
| 96 for (std::vector<PerfDataProto>::iterator iter = perf_data.begin(); | 131 for (std::vector<PerfDataProto>::iterator iter = perf_data.begin(); |
| 97 iter != perf_data.end(); | 132 iter != perf_data.end(); |
| 98 ++iter) { | 133 ++iter) { |
| 99 uma_proto_->add_perf_data()->Swap(&(*iter)); | 134 uma_proto_->add_perf_data()->Swap(&(*iter)); |
| 100 } | 135 } |
| 101 } | 136 } |
| 102 | 137 |
| 103 WriteBluetoothProto(); | 138 WriteBluetoothProto(system_profile_proto); |
| 104 UpdateMultiProfileUserCount(); | 139 UpdateMultiProfileUserCount(system_profile_proto); |
| 105 | 140 |
| 106 SystemProfileProto::Hardware* hardware = | 141 metrics::SystemProfileProto::Hardware* hardware = |
| 107 uma_proto_->mutable_system_profile()->mutable_hardware(); | 142 system_profile_proto->mutable_hardware(); |
| 108 gfx::Display::TouchSupport has_touch = ui::GetInternalDisplayTouchSupport(); | 143 gfx::Display::TouchSupport has_touch = ui::GetInternalDisplayTouchSupport(); |
| 109 if (has_touch == gfx::Display::TOUCH_SUPPORT_AVAILABLE) | 144 if (has_touch == gfx::Display::TOUCH_SUPPORT_AVAILABLE) |
| 110 hardware->set_internal_display_supports_touch(true); | 145 hardware->set_internal_display_supports_touch(true); |
| 111 else if (has_touch == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE) | 146 else if (has_touch == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE) |
| 112 hardware->set_internal_display_supports_touch(false); | 147 hardware->set_internal_display_supports_touch(false); |
| 113 WriteExternalTouchscreensProto(hardware); | 148 WriteExternalTouchscreensProto(hardware); |
| 114 } | 149 } |
| 115 | 150 |
| 116 void MetricsLogChromeOS::WriteRealtimeStabilityAttributes(PrefService* pref) { | 151 void ChromeOSMetricsProvider::ProvideStabilityMetrics( |
| 117 SystemProfileProto::Stability* stability = | 152 metrics::SystemProfileProto_Stability* stability_proto) { |
| 118 uma_proto_->mutable_system_profile()->mutable_stability(); | 153 PrefService* pref = g_browser_process->local_state(); |
| 119 | |
| 120 int count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); | 154 int count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
| 121 if (count) { | 155 if (count) { |
| 122 stability->set_other_user_crash_count(count); | 156 stability_proto->set_other_user_crash_count(count); |
| 123 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); | 157 pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
| 124 } | 158 } |
| 125 | 159 |
| 126 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); | 160 count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
| 127 if (count) { | 161 if (count) { |
| 128 stability->set_kernel_crash_count(count); | 162 stability_proto->set_kernel_crash_count(count); |
| 129 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); | 163 pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
| 130 } | 164 } |
| 131 | 165 |
| 132 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); | 166 count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
| 133 if (count) { | 167 if (count) { |
| 134 stability->set_unclean_system_shutdown_count(count); | 168 stability_proto->set_unclean_system_shutdown_count(count); |
| 135 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); | 169 pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 136 } | 170 } |
| 137 } | 171 } |
| 138 | 172 |
| 139 void MetricsLogChromeOS::WriteBluetoothProto() { | 173 void ChromeOSMetricsProvider::WriteBluetoothProto( |
| 140 SystemProfileProto::Hardware* hardware = | 174 metrics::SystemProfileProto* system_profile_proto) { |
| 141 uma_proto_->mutable_system_profile()->mutable_hardware(); | 175 metrics::SystemProfileProto::Hardware* hardware = |
| 176 system_profile_proto->mutable_hardware(); | |
| 142 | 177 |
| 143 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that | 178 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that |
| 144 // changes this will fail at the DCHECK(). | 179 // changes this will fail at the DCHECK(). |
| 145 device::BluetoothAdapterFactory::GetAdapter( | 180 device::BluetoothAdapterFactory::GetAdapter(base::Bind( |
| 146 base::Bind(&MetricsLogChromeOS::SetBluetoothAdapter, | 181 &ChromeOSMetricsProvider::SetBluetoothAdapter, base::Unretained(this))); |
| 147 base::Unretained(this))); | |
| 148 DCHECK(adapter_.get()); | 182 DCHECK(adapter_.get()); |
| 149 | 183 |
| 150 SystemProfileProto::Hardware::Bluetooth* bluetooth = | 184 SystemProfileProto::Hardware::Bluetooth* bluetooth = |
| 151 hardware->mutable_bluetooth(); | 185 hardware->mutable_bluetooth(); |
| 152 | 186 |
| 153 bluetooth->set_is_present(adapter_->IsPresent()); | 187 bluetooth->set_is_present(adapter_->IsPresent()); |
| 154 bluetooth->set_is_enabled(adapter_->IsPowered()); | 188 bluetooth->set_is_enabled(adapter_->IsPowered()); |
| 155 | 189 |
| 156 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 190 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 157 for (device::BluetoothAdapter::DeviceList::iterator iter = | 191 for (device::BluetoothAdapter::DeviceList::iterator iter = devices.begin(); |
| 158 devices.begin(); iter != devices.end(); ++iter) { | 192 iter != devices.end(); |
| 193 ++iter) { | |
| 159 device::BluetoothDevice* device = *iter; | 194 device::BluetoothDevice* device = *iter; |
| 160 // Don't collect information about LE devices yet. | 195 // Don't collect information about LE devices yet. |
| 161 if (!device->IsPaired()) | 196 if (!device->IsPaired()) |
| 162 continue; | 197 continue; |
| 163 | 198 |
| 164 PairedDevice* paired_device = bluetooth->add_paired_device(); | 199 PairedDevice* paired_device = bluetooth->add_paired_device(); |
| 165 paired_device->set_bluetooth_class(device->GetBluetoothClass()); | 200 paired_device->set_bluetooth_class(device->GetBluetoothClass()); |
| 166 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); | 201 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); |
| 167 | 202 |
| 168 // |address| is xx:xx:xx:xx:xx:xx, extract the first three components and | 203 // |address| is xx:xx:xx:xx:xx:xx, extract the first three components and |
| 169 // pack into a uint32. | 204 // pack into a uint32. |
| 170 std::string address = device->GetAddress(); | 205 std::string address = device->GetAddress(); |
| 171 if (address.size() > 9 && | 206 if (address.size() > 9 && address[2] == ':' && address[5] == ':' && |
| 172 address[2] == ':' && address[5] == ':' && address[8] == ':') { | 207 address[8] == ':') { |
| 173 std::string vendor_prefix_str; | 208 std::string vendor_prefix_str; |
| 174 uint64 vendor_prefix; | 209 uint64 vendor_prefix; |
| 175 | 210 |
| 176 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); | 211 base::RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); |
| 177 DCHECK_EQ(6U, vendor_prefix_str.size()); | 212 DCHECK_EQ(6U, vendor_prefix_str.size()); |
| 178 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); | 213 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); |
| 179 | 214 |
| 180 paired_device->set_vendor_prefix(vendor_prefix); | 215 paired_device->set_vendor_prefix(vendor_prefix); |
| 181 } | 216 } |
| 182 | 217 |
| 183 switch (device->GetVendorIDSource()) { | 218 switch (device->GetVendorIDSource()) { |
| 184 case device::BluetoothDevice::VENDOR_ID_BLUETOOTH: | 219 case device::BluetoothDevice::VENDOR_ID_BLUETOOTH: |
| 185 paired_device->set_vendor_id_source(PairedDevice::VENDOR_ID_BLUETOOTH); | 220 paired_device->set_vendor_id_source(PairedDevice::VENDOR_ID_BLUETOOTH); |
| 186 break; | 221 break; |
| 187 case device::BluetoothDevice::VENDOR_ID_USB: | 222 case device::BluetoothDevice::VENDOR_ID_USB: |
| 188 paired_device->set_vendor_id_source(PairedDevice::VENDOR_ID_USB); | 223 paired_device->set_vendor_id_source(PairedDevice::VENDOR_ID_USB); |
| 189 break; | 224 break; |
| 190 default: | 225 default: |
| 191 paired_device->set_vendor_id_source(PairedDevice::VENDOR_ID_UNKNOWN); | 226 paired_device->set_vendor_id_source(PairedDevice::VENDOR_ID_UNKNOWN); |
| 192 } | 227 } |
| 193 | 228 |
| 194 paired_device->set_vendor_id(device->GetVendorID()); | 229 paired_device->set_vendor_id(device->GetVendorID()); |
| 195 paired_device->set_product_id(device->GetProductID()); | 230 paired_device->set_product_id(device->GetProductID()); |
| 196 paired_device->set_device_id(device->GetDeviceID()); | 231 paired_device->set_device_id(device->GetDeviceID()); |
| 197 } | 232 } |
| 198 } | 233 } |
| 199 | 234 |
| 200 void MetricsLogChromeOS::UpdateMultiProfileUserCount() { | 235 void ChromeOSMetricsProvider::UpdateMultiProfileUserCount( |
| 201 metrics::SystemProfileProto* system_profile = | 236 metrics::SystemProfileProto* system_profile_proto) { |
| 202 uma_proto_->mutable_system_profile(); | |
| 203 | |
| 204 if (chromeos::UserManager::IsInitialized()) { | 237 if (chromeos::UserManager::IsInitialized()) { |
| 205 size_t user_count = chromeos::UserManager::Get()->GetLoggedInUsers().size(); | 238 size_t user_count = chromeos::UserManager::Get()->GetLoggedInUsers().size(); |
| 206 | 239 |
| 207 // We invalidate the user count if it changed while the log was open. | 240 // We invalidate the user count if it changed while the log was open. |
| 208 if (system_profile->has_multi_profile_user_count() && | 241 if (user_count != user_count_at_log_initialization_) { |
|
Alexei Svitkine (slow)
2014/05/23 08:41:47
Hmm, what happens if chromeos::UserManager::IsInit
blundell
2014/05/23 12:09:22
Done.
| |
| 209 user_count != system_profile->multi_profile_user_count()) { | |
| 210 user_count = 0; | 242 user_count = 0; |
| 211 } | 243 } |
| 212 | 244 |
| 213 system_profile->set_multi_profile_user_count(user_count); | 245 system_profile_proto->set_multi_profile_user_count(user_count); |
| 214 } | 246 } |
| 215 } | 247 } |
| 216 | 248 |
| 217 void MetricsLogChromeOS::SetBluetoothAdapter( | 249 void ChromeOSMetricsProvider::SetBluetoothAdapter( |
| 218 scoped_refptr<device::BluetoothAdapter> adapter) { | 250 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 219 adapter_ = adapter; | 251 adapter_ = adapter; |
| 220 } | 252 } |
| OLD | NEW |