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