OLD | NEW |
---|---|
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 |
(...skipping 25 matching lines...) Expand all Loading... | |
36 #include "chrome/common/metrics/proto/profiler_event.pb.h" | 36 #include "chrome/common/metrics/proto/profiler_event.pb.h" |
37 #include "chrome/common/metrics/proto/system_profile.pb.h" | 37 #include "chrome/common/metrics/proto/system_profile.pb.h" |
38 #include "chrome/common/metrics/variations/variations_util.h" | 38 #include "chrome/common/metrics/variations/variations_util.h" |
39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
40 #include "chrome/installer/util/google_update_settings.h" | 40 #include "chrome/installer/util/google_update_settings.h" |
41 #include "content/public/browser/content_browser_client.h" | 41 #include "content/public/browser/content_browser_client.h" |
42 #include "content/public/browser/gpu_data_manager.h" | 42 #include "content/public/browser/gpu_data_manager.h" |
43 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
44 #include "content/public/common/gpu_info.h" | 44 #include "content/public/common/gpu_info.h" |
45 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
46 #include "net/base/network_change_notifier.h" | |
46 #include "ui/gfx/screen.h" | 47 #include "ui/gfx/screen.h" |
47 #include "webkit/plugins/webplugininfo.h" | 48 #include "webkit/plugins/webplugininfo.h" |
48 | 49 |
49 #if defined(OS_ANDROID) | 50 #if defined(OS_ANDROID) |
50 #include "base/android/build_info.h" | 51 #include "base/android/build_info.h" |
51 #endif | 52 #endif |
52 | 53 |
53 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) | 54 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
54 | 55 |
55 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 hardware->set_max_dpi_y(si.max_dpi_y); | 298 hardware->set_max_dpi_y(si.max_dpi_y); |
298 } | 299 } |
299 ReleaseDC(GetDesktopWindow(), desktop_dc); | 300 ReleaseDC(GetDesktopWindow(), desktop_dc); |
300 } | 301 } |
301 } | 302 } |
302 | 303 |
303 #endif // defined(OS_WIN) | 304 #endif // defined(OS_WIN) |
304 | 305 |
305 } // namespace | 306 } // namespace |
306 | 307 |
308 class MetricsLog::NetworkObserver | |
309 : public net::NetworkChangeNotifier::ConnectionTypeObserver { | |
310 public: | |
311 NetworkObserver() : is_ambiguous_(false) { | |
312 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | |
313 Reset(); | |
314 } | |
315 virtual ~NetworkObserver() { | |
316 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | |
317 } | |
318 | |
319 void Reset() { | |
320 is_ambiguous_ = false; | |
321 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); | |
322 } | |
323 | |
324 // ConnectionTypeObserver: | |
325 virtual void OnConnectionTypeChanged( | |
326 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { | |
327 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) | |
328 return; | |
329 if (type != connection_type_ && | |
330 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { | |
331 is_ambiguous_ = true; | |
332 } | |
333 connection_type_ = type; | |
334 } | |
335 | |
336 bool is_ambiguous() const { return is_ambiguous_; } | |
337 | |
338 SystemProfileProto::Network::ConnectionType connection_type() const { | |
339 switch (connection_type_) { | |
340 case net::NetworkChangeNotifier::CONNECTION_NONE: | |
341 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | |
342 return SystemProfileProto::Network::CONNECTION_UNKNOWN; | |
343 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | |
344 return SystemProfileProto::Network::CONNECTION_ETHERNET; | |
345 case net::NetworkChangeNotifier::CONNECTION_WIFI: | |
346 return SystemProfileProto::Network::CONNECTION_WIFI; | |
347 case net::NetworkChangeNotifier::CONNECTION_2G: | |
348 return SystemProfileProto::Network::CONNECTION_2G; | |
349 case net::NetworkChangeNotifier::CONNECTION_3G: | |
350 return SystemProfileProto::Network::CONNECTION_3G; | |
351 case net::NetworkChangeNotifier::CONNECTION_4G: | |
352 return SystemProfileProto::Network::CONNECTION_4G; | |
353 default: | |
354 NOTREACHED(); | |
355 return SystemProfileProto::Network::CONNECTION_UNKNOWN; | |
Ilya Sherman
2013/01/26 00:49:00
nit: Please omit this, so that it's a compiler err
szym
2013/01/28 18:16:25
If I drop this, it won't compile on gcc:
../../ch
Ilya Sherman
2013/01/28 20:52:10
Yes, sorry, I should have been clearer: Moving thi
| |
356 } | |
357 } | |
358 | |
359 private: | |
360 bool is_ambiguous_; | |
361 net::NetworkChangeNotifier::ConnectionType connection_type_; | |
362 | |
363 DISALLOW_COPY_AND_ASSIGN(NetworkObserver); | |
364 }; | |
365 | |
307 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} | 366 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
308 | 367 |
309 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} | 368 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
310 | 369 |
311 static base::LazyInstance<std::string>::Leaky | 370 static base::LazyInstance<std::string>::Leaky |
312 g_version_extension = LAZY_INSTANCE_INITIALIZER; | 371 g_version_extension = LAZY_INSTANCE_INITIALIZER; |
313 | 372 |
314 MetricsLog::MetricsLog(const std::string& client_id, int session_id) | 373 MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
315 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} | 374 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()), |
375 network_observer_(new NetworkObserver()) {} | |
316 | 376 |
317 MetricsLog::~MetricsLog() {} | 377 MetricsLog::~MetricsLog() {} |
318 | 378 |
319 // static | 379 // static |
320 void MetricsLog::RegisterPrefs(PrefServiceSimple* local_state) { | 380 void MetricsLog::RegisterPrefs(PrefServiceSimple* local_state) { |
321 local_state->RegisterListPref(prefs::kStabilityPluginStats); | 381 local_state->RegisterListPref(prefs::kStabilityPluginStats); |
322 } | 382 } |
323 | 383 |
324 // static | 384 // static |
325 int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { | 385 int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 system_profile->set_application_locale( | 869 system_profile->set_application_locale( |
810 content::GetContentClient()->browser()->GetApplicationLocale()); | 870 content::GetContentClient()->browser()->GetApplicationLocale()); |
811 | 871 |
812 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); | 872 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); |
813 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); | 873 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
814 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); | 874 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
815 #if defined(OS_WIN) | 875 #if defined(OS_WIN) |
816 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); | 876 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
817 #endif | 877 #endif |
818 | 878 |
879 SystemProfileProto::Network* network = system_profile->mutable_network(); | |
880 network->set_is_ambiguous(network_observer_->is_ambiguous()); | |
881 network->set_connection_type(network_observer_->connection_type()); | |
882 network_observer_->Reset(); | |
883 | |
819 SystemProfileProto::OS* os = system_profile->mutable_os(); | 884 SystemProfileProto::OS* os = system_profile->mutable_os(); |
820 std::string os_name = base::SysInfo::OperatingSystemName(); | 885 std::string os_name = base::SysInfo::OperatingSystemName(); |
821 #if defined(OS_WIN) | 886 #if defined(OS_WIN) |
822 // TODO(mad): This only checks whether the main process is a Metro process at | 887 // TODO(mad): This only checks whether the main process is a Metro process at |
823 // upload time; not whether the collected metrics were all gathered from | 888 // upload time; not whether the collected metrics were all gathered from |
824 // Metro. This is ok as an approximation for now, since users will rarely be | 889 // Metro. This is ok as an approximation for now, since users will rarely be |
825 // switching from Metro to Desktop mode; but we should re-evaluate whether we | 890 // switching from Metro to Desktop mode; but we should re-evaluate whether we |
826 // can distinguish metrics more cleanly in the future: http://crbug.com/140568 | 891 // can distinguish metrics more cleanly in the future: http://crbug.com/140568 |
827 if (base::win::IsMetroProcess()) | 892 if (base::win::IsMetroProcess()) |
828 os_name += " (Metro)"; | 893 os_name += " (Metro)"; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 ProductDataToProto(google_update_metrics.google_update_data, | 1139 ProductDataToProto(google_update_metrics.google_update_data, |
1075 google_update->mutable_google_update_status()); | 1140 google_update->mutable_google_update_status()); |
1076 } | 1141 } |
1077 | 1142 |
1078 if (!google_update_metrics.product_data.version.empty()) { | 1143 if (!google_update_metrics.product_data.version.empty()) { |
1079 ProductDataToProto(google_update_metrics.product_data, | 1144 ProductDataToProto(google_update_metrics.product_data, |
1080 google_update->mutable_client_status()); | 1145 google_update->mutable_client_status()); |
1081 } | 1146 } |
1082 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) | 1147 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
1083 } | 1148 } |
OLD | NEW |