Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: chrome/browser/metrics/metrics_log.cc

Issue 13872017: Bluetooth: gather usage metrics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase since Cellular.* appeared under us Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/metrics_log.h ('k') | chrome/common/metrics/proto/system_profile.proto » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/perftimer.h" 16 #include "base/perftimer.h"
16 #include "base/prefs/pref_registry_simple.h" 17 #include "base/prefs/pref_registry_simple.h"
17 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
18 #include "base/profiler/alternate_timer.h" 19 #include "base/profiler/alternate_timer.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
21 #include "base/sys_info.h" 22 #include "base/sys_info.h"
(...skipping 15 matching lines...) Expand all
37 #include "chrome/common/logging_chrome.h" 38 #include "chrome/common/logging_chrome.h"
38 #include "chrome/common/metrics/proto/omnibox_event.pb.h" 39 #include "chrome/common/metrics/proto/omnibox_event.pb.h"
39 #include "chrome/common/metrics/proto/profiler_event.pb.h" 40 #include "chrome/common/metrics/proto/profiler_event.pb.h"
40 #include "chrome/common/metrics/proto/system_profile.pb.h" 41 #include "chrome/common/metrics/proto/system_profile.pb.h"
41 #include "chrome/common/metrics/variations/variations_util.h" 42 #include "chrome/common/metrics/variations/variations_util.h"
42 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
43 #include "chrome/installer/util/google_update_settings.h" 44 #include "chrome/installer/util/google_update_settings.h"
44 #include "content/public/browser/gpu_data_manager.h" 45 #include "content/public/browser/gpu_data_manager.h"
45 #include "content/public/common/content_client.h" 46 #include "content/public/common/content_client.h"
46 #include "content/public/common/gpu_info.h" 47 #include "content/public/common/gpu_info.h"
48 #include "device/bluetooth/bluetooth_adapter.h"
49 #include "device/bluetooth/bluetooth_adapter_factory.h"
50 #include "device/bluetooth/bluetooth_device.h"
47 #include "googleurl/src/gurl.h" 51 #include "googleurl/src/gurl.h"
48 #include "ui/gfx/screen.h" 52 #include "ui/gfx/screen.h"
49 #include "webkit/plugins/webplugininfo.h" 53 #include "webkit/plugins/webplugininfo.h"
50 54
51 #if defined(OS_ANDROID) 55 #if defined(OS_ANDROID)
52 #include "base/android/build_info.h" 56 #include "base/android/build_info.h"
53 #endif 57 #endif
54 58
55 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) 59 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
56 60
57 #if defined(OS_WIN) 61 #if defined(OS_WIN)
58 #include "base/win/metro.h" 62 #include "base/win/metro.h"
59 63
60 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx 64 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
61 extern "C" IMAGE_DOS_HEADER __ImageBase; 65 extern "C" IMAGE_DOS_HEADER __ImageBase;
62 #endif 66 #endif
63 67
64 using content::GpuDataManager; 68 using content::GpuDataManager;
65 using metrics::OmniboxEventProto; 69 using metrics::OmniboxEventProto;
66 using metrics::PerfDataProto; 70 using metrics::PerfDataProto;
67 using metrics::ProfilerEventProto; 71 using metrics::ProfilerEventProto;
68 using metrics::SystemProfileProto; 72 using metrics::SystemProfileProto;
69 using tracked_objects::ProcessDataSnapshot; 73 using tracked_objects::ProcessDataSnapshot;
70 typedef chrome_variations::ActiveGroupId ActiveGroupId; 74 typedef chrome_variations::ActiveGroupId ActiveGroupId;
71 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; 75 typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
76 typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice;
72 77
73 namespace { 78 namespace {
74 79
75 // Returns the date at which the current metrics client ID was created as 80 // Returns the date at which the current metrics client ID was created as
76 // a string containing seconds since the epoch, or "0" if none was found. 81 // a string containing seconds since the epoch, or "0" if none was found.
77 std::string GetMetricsEnabledDate(PrefService* pref) { 82 std::string GetMetricsEnabledDate(PrefService* pref) {
78 if (!pref) { 83 if (!pref) {
79 NOTREACHED(); 84 NOTREACHED();
80 return "0"; 85 return "0";
81 } 86 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 reinterpret_cast<LPARAM>(&si))) { 301 reinterpret_cast<LPARAM>(&si))) {
297 hardware->set_max_dpi_x(si.max_dpi_x); 302 hardware->set_max_dpi_x(si.max_dpi_x);
298 hardware->set_max_dpi_y(si.max_dpi_y); 303 hardware->set_max_dpi_y(si.max_dpi_y);
299 } 304 }
300 ReleaseDC(GetDesktopWindow(), desktop_dc); 305 ReleaseDC(GetDesktopWindow(), desktop_dc);
301 } 306 }
302 } 307 }
303 308
304 #endif // defined(OS_WIN) 309 #endif // defined(OS_WIN)
305 310
311 #if defined(OS_CHROMEOS)
312 PairedDevice::Type AsBluetoothDeviceType(
313 enum device::BluetoothDevice::DeviceType device_type) {
314 switch (device_type) {
315 case device::BluetoothDevice::DEVICE_UNKNOWN:
316 return PairedDevice::DEVICE_UNKNOWN;
317 case device::BluetoothDevice::DEVICE_COMPUTER:
318 return PairedDevice::DEVICE_COMPUTER;
319 case device::BluetoothDevice::DEVICE_PHONE:
320 return PairedDevice::DEVICE_PHONE;
321 case device::BluetoothDevice::DEVICE_MODEM:
322 return PairedDevice::DEVICE_MODEM;
323 case device::BluetoothDevice::DEVICE_AUDIO:
324 return PairedDevice::DEVICE_AUDIO;
325 case device::BluetoothDevice::DEVICE_CAR_AUDIO:
326 return PairedDevice::DEVICE_CAR_AUDIO;
327 case device::BluetoothDevice::DEVICE_VIDEO:
328 return PairedDevice::DEVICE_VIDEO;
329 case device::BluetoothDevice::DEVICE_PERIPHERAL:
330 return PairedDevice::DEVICE_PERIPHERAL;
331 case device::BluetoothDevice::DEVICE_JOYSTICK:
332 return PairedDevice::DEVICE_JOYSTICK;
333 case device::BluetoothDevice::DEVICE_GAMEPAD:
334 return PairedDevice::DEVICE_GAMEPAD;
335 case device::BluetoothDevice::DEVICE_KEYBOARD:
336 return PairedDevice::DEVICE_KEYBOARD;
337 case device::BluetoothDevice::DEVICE_MOUSE:
338 return PairedDevice::DEVICE_MOUSE;
339 case device::BluetoothDevice::DEVICE_TABLET:
340 return PairedDevice::DEVICE_TABLET;
341 case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO:
342 return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO;
343 }
344
345 NOTREACHED();
346 return PairedDevice::DEVICE_UNKNOWN;
347 }
348 #endif // defined(OS_CHROMEOS)
349
306 } // namespace 350 } // namespace
307 351
308 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} 352 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {}
309 353
310 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} 354 GoogleUpdateMetrics::~GoogleUpdateMetrics() {}
311 355
312 static base::LazyInstance<std::string>::Leaky 356 static base::LazyInstance<std::string>::Leaky
313 g_version_extension = LAZY_INSTANCE_INITIALIZER; 357 g_version_extension = LAZY_INSTANCE_INITIALIZER;
314 358
315 MetricsLog::MetricsLog(const std::string& client_id, int session_id) 359 MetricsLog::MetricsLog(const std::string& client_id, int session_id)
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 WritePluginList(plugin_list, write_as_xml); 914 WritePluginList(plugin_list, write_as_xml);
871 915
872 std::vector<ActiveGroupId> field_trial_ids; 916 std::vector<ActiveGroupId> field_trial_ids;
873 GetFieldTrialIds(&field_trial_ids); 917 GetFieldTrialIds(&field_trial_ids);
874 WriteFieldTrials(field_trial_ids, system_profile); 918 WriteFieldTrials(field_trial_ids, system_profile);
875 919
876 #if defined(OS_CHROMEOS) 920 #if defined(OS_CHROMEOS)
877 PerfDataProto perf_data_proto; 921 PerfDataProto perf_data_proto;
878 if (perf_provider_.GetPerfData(&perf_data_proto)) 922 if (perf_provider_.GetPerfData(&perf_data_proto))
879 uma_proto()->add_perf_data()->Swap(&perf_data_proto); 923 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
924
925 // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that
926 // changes this will fail at the DCHECK().
927 device::BluetoothAdapterFactory::GetAdapter(
928 base::Bind(&MetricsLog::SetBluetoothAdapter,
929 base::Unretained(this)));
930 DCHECK(adapter_.get());
931 WriteBluetoothProto(hardware);
880 #endif 932 #endif
881 } 933 }
882 934
883 void MetricsLog::RecordProfilerData( 935 void MetricsLog::RecordProfilerData(
884 const tracked_objects::ProcessDataSnapshot& process_data, 936 const tracked_objects::ProcessDataSnapshot& process_data,
885 int process_type) { 937 int process_type) {
886 DCHECK(!locked()); 938 DCHECK(!locked());
887 939
888 if (tracked_objects::GetTimeSourceType() != 940 if (tracked_objects::GetTimeSourceType() !=
889 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { 941 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 ProductDataToProto(google_update_metrics.google_update_data, 1132 ProductDataToProto(google_update_metrics.google_update_data,
1081 google_update->mutable_google_update_status()); 1133 google_update->mutable_google_update_status());
1082 } 1134 }
1083 1135
1084 if (!google_update_metrics.product_data.version.empty()) { 1136 if (!google_update_metrics.product_data.version.empty()) {
1085 ProductDataToProto(google_update_metrics.product_data, 1137 ProductDataToProto(google_update_metrics.product_data,
1086 google_update->mutable_client_status()); 1138 google_update->mutable_client_status());
1087 } 1139 }
1088 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) 1140 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1089 } 1141 }
1142
1143 void MetricsLog::SetBluetoothAdapter(
1144 scoped_refptr<device::BluetoothAdapter> adapter) {
1145 adapter_ = adapter;
1146 }
1147
1148 void MetricsLog::WriteBluetoothProto(
1149 SystemProfileProto::Hardware* hardware) {
1150 #if defined(OS_CHROMEOS)
1151 SystemProfileProto::Hardware::Bluetooth* bluetooth =
1152 hardware->mutable_bluetooth();
1153
1154 bluetooth->set_is_present(adapter_->IsPresent());
1155 bluetooth->set_is_enabled(adapter_->IsPowered());
1156
1157 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
1158 for (device::BluetoothAdapter::DeviceList::iterator iter =
1159 devices.begin(); iter != devices.end(); ++iter) {
1160 PairedDevice* paired_device = bluetooth->add_paired_device();
1161
1162 device::BluetoothDevice* device = *iter;
1163 paired_device->set_bluetooth_class(device->GetBluetoothClass());
1164 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
1165
1166 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
1167 // pack into a uint32
1168 std::string address = device->GetAddress();
1169 if (address.size() > 9 &&
1170 address[2] == ':' && address[5] == ':' && address[8] == ':') {
1171 std::string vendor_prefix_str;
1172 uint64 vendor_prefix;
1173
1174 RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
1175 DCHECK_EQ(6U, vendor_prefix_str.size());
1176 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
1177
1178 paired_device->set_vendor_prefix(vendor_prefix);
1179 }
1180
1181 paired_device->set_vendor_id(device->GetVendorID());
1182 paired_device->set_product_id(device->GetProductID());
1183 paired_device->set_device_id(device->GetDeviceID());
1184 }
1185 #endif // defined(OS_CHROMEOS)
1186 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log.h ('k') | chrome/common/metrics/proto/system_profile.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698