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

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: Further review comments Created 7 years, 8 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)
316 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} 360 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()),
361 weak_ptr_factory_(this) {}
317 362
318 MetricsLog::~MetricsLog() {} 363 MetricsLog::~MetricsLog() {}
319 364
320 // static 365 // static
321 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { 366 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
322 registry->RegisterListPref(prefs::kStabilityPluginStats); 367 registry->RegisterListPref(prefs::kStabilityPluginStats);
323 } 368 }
324 369
325 // static 370 // static
326 int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { 371 int64 MetricsLog::GetIncrementalUptime(PrefService* pref) {
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 WritePluginList(plugin_list, write_as_xml); 915 WritePluginList(plugin_list, write_as_xml);
871 916
872 std::vector<ActiveGroupId> field_trial_ids; 917 std::vector<ActiveGroupId> field_trial_ids;
873 GetFieldTrialIds(&field_trial_ids); 918 GetFieldTrialIds(&field_trial_ids);
874 WriteFieldTrials(field_trial_ids, system_profile); 919 WriteFieldTrials(field_trial_ids, system_profile);
875 920
876 #if defined(OS_CHROMEOS) 921 #if defined(OS_CHROMEOS)
877 PerfDataProto perf_data_proto; 922 PerfDataProto perf_data_proto;
878 if (perf_provider_.GetPerfData(&perf_data_proto)) 923 if (perf_provider_.GetPerfData(&perf_data_proto))
879 uma_proto()->add_perf_data()->Swap(&perf_data_proto); 924 uma_proto()->add_perf_data()->Swap(&perf_data_proto);
925
926 device::BluetoothAdapterFactory::GetAdapter(
927 base::Bind(&MetricsLog::SetBluetoothAdapter,
Ilya Sherman 2013/04/23 01:01:55 Looks like the body for this method is missing.
keybuk 2013/04/23 01:17:54 oops, editor rebellion Done.
928 weak_ptr_factory_.GetWeakPtr()));
929 if (adapter_.get())
Ilya Sherman 2013/04/23 01:01:55 Per IM conversation, it sounds like this is expect
keybuk 2013/04/23 01:17:54 Done.
930 WriteBluetoothProto(hardware);
880 #endif 931 #endif
881 } 932 }
882 933
883 void MetricsLog::RecordProfilerData( 934 void MetricsLog::RecordProfilerData(
884 const tracked_objects::ProcessDataSnapshot& process_data, 935 const tracked_objects::ProcessDataSnapshot& process_data,
885 int process_type) { 936 int process_type) {
886 DCHECK(!locked()); 937 DCHECK(!locked());
887 938
888 if (tracked_objects::GetTimeSourceType() != 939 if (tracked_objects::GetTimeSourceType() !=
889 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { 940 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, 1131 ProductDataToProto(google_update_metrics.google_update_data,
1081 google_update->mutable_google_update_status()); 1132 google_update->mutable_google_update_status());
1082 } 1133 }
1083 1134
1084 if (!google_update_metrics.product_data.version.empty()) { 1135 if (!google_update_metrics.product_data.version.empty()) {
1085 ProductDataToProto(google_update_metrics.product_data, 1136 ProductDataToProto(google_update_metrics.product_data,
1086 google_update->mutable_client_status()); 1137 google_update->mutable_client_status());
1087 } 1138 }
1088 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) 1139 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
1089 } 1140 }
1141
1142 void MetricsLog::WriteBluetoothProto(
1143 SystemProfileProto::Hardware* hardware) {
1144 #if defined(OS_CHROMEOS)
1145 SystemProfileProto::Hardware::Bluetooth* bluetooth =
1146 hardware->mutable_bluetooth();
1147
1148 bluetooth->set_is_present(adapter_->IsPresent());
1149 bluetooth->set_is_enabled(adapter_->IsPowered());
1150
1151 device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
1152 for (device::BluetoothAdapter::DeviceList::iterator iter =
1153 devices.begin(); iter != devices.end(); ++iter) {
1154 PairedDevice* paired_device = bluetooth->add_paired_device();
1155
1156 device::BluetoothDevice* device = *iter;
1157 paired_device->set_bluetooth_class(device->GetBluetoothClass());
1158 paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType()));
1159
1160 // address is xx:xx:xx:xx:xx:xx, extract the first three components and
1161 // pack into a uint32
1162 std::string address = device->GetAddress();
1163 if (address.length() > 9 &&
1164 address[2] == ':' && address[5] == ':' && address[8] == ':') {
1165 std::string vendor_prefix_str;
1166 uint64 vendor_prefix;
1167
1168 RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str);
Ilya Sherman 2013/04/23 01:01:55 nit: Just to be extra sure, could you add a DCHECK
keybuk 2013/04/23 01:17:54 Done.
1169 base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix);
1170
1171 paired_device->set_vendor_prefix(vendor_prefix);
1172 }
1173
1174 paired_device->set_vendor_id(device->GetVendorID());
1175 paired_device->set_product_id(device->GetProductID());
1176 paired_device->set_device_id(device->GetDeviceID());
1177 }
1178 #endif // defined(OS_CHROMEOS)
1179 }
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