Chromium Code Reviews| Index: chrome/browser/metrics/metrics_log.cc |
| diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc |
| index ec39326a7784b74f401734e5e355c8cc2f10b78a..700b23facc1a5a0e69e0f85d493e80d14496c2ab 100644 |
| --- a/chrome/browser/metrics/metrics_log.cc |
| +++ b/chrome/browser/metrics/metrics_log.cc |
| @@ -9,6 +9,7 @@ |
| #include <vector> |
| #include "base/basictypes.h" |
| +#include "base/bind.h" |
| #include "base/file_util.h" |
| #include "base/lazy_instance.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -44,6 +45,9 @@ |
| #include "content/public/browser/gpu_data_manager.h" |
| #include "content/public/common/content_client.h" |
| #include "content/public/common/gpu_info.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_adapter_factory.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| #include "googleurl/src/gurl.h" |
| #include "ui/gfx/screen.h" |
| #include "webkit/plugins/webplugininfo.h" |
| @@ -303,6 +307,61 @@ void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { |
| #endif // defined(OS_WIN) |
| +#if defined(OS_CHROMEOS) |
| +SystemProfileProto::Hardware::Bluetooth::PairedDevice::Type |
| +AsBluetoothDeviceType( |
| + enum device::BluetoothDevice::DeviceType device_type) { |
| + switch (device_type) { |
| + case device::BluetoothDevice::DEVICE_UNKNOWN: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_UNKNOWN; |
| + case device::BluetoothDevice::DEVICE_COMPUTER: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_COMPUTER; |
| + case device::BluetoothDevice::DEVICE_PHONE: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_PHONE; |
| + case device::BluetoothDevice::DEVICE_MODEM: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_MODEM; |
| + case device::BluetoothDevice::DEVICE_AUDIO: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_AUDIO; |
| + case device::BluetoothDevice::DEVICE_CAR_AUDIO: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_CAR_AUDIO; |
| + case device::BluetoothDevice::DEVICE_VIDEO: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_VIDEO; |
| + case device::BluetoothDevice::DEVICE_PERIPHERAL: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_PERIPHERAL; |
| + case device::BluetoothDevice::DEVICE_JOYSTICK: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_JOYSTICK; |
| + case device::BluetoothDevice::DEVICE_GAMEPAD: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_GAMEPAD; |
| + case device::BluetoothDevice::DEVICE_KEYBOARD: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_KEYBOARD; |
| + case device::BluetoothDevice::DEVICE_MOUSE: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_MOUSE; |
| + case device::BluetoothDevice::DEVICE_TABLET: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_TABLET; |
| + case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO: |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_KEYBOARD_MOUSE_COMBO; |
| + } |
| + |
| + NOTREACHED(); |
| + return SystemProfileProto::Hardware::Bluetooth::PairedDevice:: |
| + DEVICE_UNKNOWN; |
| +} |
| +#endif // defined(OS_CHROMEOS) |
| + |
| } // namespace |
| GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| @@ -313,7 +372,8 @@ static base::LazyInstance<std::string>::Leaky |
| g_version_extension = LAZY_INSTANCE_INITIALIZER; |
| MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
| - : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} |
| + : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()), |
| + weak_ptr_factory_(this) {} |
| MetricsLog::~MetricsLog() {} |
| @@ -877,6 +937,11 @@ void MetricsLog::RecordEnvironmentProto( |
| PerfDataProto perf_data_proto; |
| if (perf_provider_.GetPerfData(&perf_data_proto)) |
| uma_proto()->add_perf_data()->Swap(&perf_data_proto); |
| + |
| + device::BluetoothAdapterFactory::GetAdapter( |
| + base::Bind(&MetricsLog::WriteBluetoothProto, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + hardware)); |
|
Ilya Sherman
2013/04/23 00:09:43
Sorry, I should have caught this in the previous r
keybuk
2013/04/23 00:41:42
On Chrome OS it's guaranteed to be 100% synchronou
|
| #endif |
| } |
| @@ -1087,3 +1152,52 @@ void MetricsLog::WriteGoogleUpdateProto( |
| } |
| #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| } |
| + |
| +void MetricsLog::WriteBluetoothProto( |
| + SystemProfileProto::Hardware* hardware, |
| + scoped_refptr<device::BluetoothAdapter> adapter) { |
| +#if defined(OS_CHROMEOS) |
| + SystemProfileProto::Hardware::Bluetooth* bluetooth = |
| + hardware->mutable_bluetooth(); |
| + |
| + bluetooth->set_is_present(adapter->IsPresent()); |
| + bluetooth->set_is_enabled(adapter->IsPowered()); |
| + |
| + device::BluetoothAdapter::DeviceList devices = adapter->GetDevices(); |
| + for (device::BluetoothAdapter::DeviceList::iterator iter = |
| + devices.begin(); iter != devices.end(); ++iter) { |
| + SystemProfileProto::Hardware::Bluetooth::PairedDevice* paired_device = |
| + bluetooth->add_paired_device(); |
| + |
| + device::BluetoothDevice* device = *iter; |
| + paired_device->set_bluetooth_class(device->GetBluetoothClass()); |
| + paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); |
| + |
| + // address is xx:xx:xx:xx:xx:xx, extract the first three components and |
| + // pack into a uint32 |
| + std::string address = device->GetAddress(); |
| + if (address.length() > 9 && |
| + address[2] == ':' && address[5] == ':' && address[8] == ':') { |
| + uint32 vendor_prefix = 0; |
| + |
| + uint64 component = 0; |
| + base::HexStringToUInt64(address.substr(0, 2), &component); |
| + vendor_prefix |= component << 16; |
| + |
| + component = 0; |
| + base::HexStringToUInt64(address.substr(3, 2), &component); |
| + vendor_prefix |= component << 8; |
| + |
| + component = 0; |
| + base::HexStringToUInt64(address.substr(6, 2), &component); |
| + vendor_prefix |= component; |
|
Ilya Sherman
2013/04/23 00:09:43
Rather than calling HexStringToUInt64 three times,
keybuk
2013/04/23 00:41:42
Done.
|
| + |
| + paired_device->set_vendor_prefix(vendor_prefix); |
| + } |
| + |
| + paired_device->set_vendor_id(device->GetVendorID()); |
| + paired_device->set_product_id(device->GetProductID()); |
| + paired_device->set_device_id(device->GetDeviceID()); |
| + } |
| +#endif // defined(OS_CHROMEOS) |
| +} |