Chromium Code Reviews| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/perftimer.h" | 16 #include "base/perftimer.h" |
| 16 #include "base/profiler/alternate_timer.h" | 17 #include "base/profiler/alternate_timer.h" |
| 17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 20 #include "base/third_party/nspr/prtime.h" | 21 #include "base/third_party/nspr/prtime.h" |
| 22 #include "base/threading/worker_pool.h" | |
|
Ilya Sherman
2013/02/11 06:26:13
You should pretty much never use the WorkerPool cl
szym
2013/02/11 08:30:53
Habits from net/. BrowserThread is not available t
| |
| 21 #include "base/time.h" | 23 #include "base/time.h" |
| 22 #include "base/tracked_objects.h" | 24 #include "base/tracked_objects.h" |
| 23 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete_input.h" | 26 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_log.h" | 27 #include "chrome/browser/autocomplete/autocomplete_log.h" |
| 26 #include "chrome/browser/autocomplete/autocomplete_match.h" | 28 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 27 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 29 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 28 #include "chrome/browser/autocomplete/autocomplete_result.h" | 30 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 29 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 30 #include "chrome/browser/google/google_util.h" | 32 #include "chrome/browser/google/google_util.h" |
| 31 #include "chrome/browser/plugins/plugin_prefs.h" | 33 #include "chrome/browser/plugins/plugin_prefs.h" |
| 32 #include "chrome/browser/prefs/pref_registry_simple.h" | 34 #include "chrome/browser/prefs/pref_registry_simple.h" |
| 33 #include "chrome/browser/prefs/pref_service.h" | 35 #include "chrome/browser/prefs/pref_service.h" |
| 34 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 35 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
| 36 #include "chrome/common/logging_chrome.h" | 38 #include "chrome/common/logging_chrome.h" |
| 37 #include "chrome/common/metrics/proto/omnibox_event.pb.h" | 39 #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
| 38 #include "chrome/common/metrics/proto/profiler_event.pb.h" | 40 #include "chrome/common/metrics/proto/profiler_event.pb.h" |
| 39 #include "chrome/common/metrics/proto/system_profile.pb.h" | 41 #include "chrome/common/metrics/proto/system_profile.pb.h" |
| 40 #include "chrome/common/metrics/variations/variations_util.h" | 42 #include "chrome/common/metrics/variations/variations_util.h" |
| 41 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 42 #include "chrome/installer/util/google_update_settings.h" | 44 #include "chrome/installer/util/google_update_settings.h" |
| 43 #include "content/public/browser/content_browser_client.h" | 45 #include "content/public/browser/content_browser_client.h" |
| 44 #include "content/public/browser/gpu_data_manager.h" | 46 #include "content/public/browser/gpu_data_manager.h" |
| 45 #include "content/public/common/content_client.h" | 47 #include "content/public/common/content_client.h" |
| 46 #include "content/public/common/gpu_info.h" | 48 #include "content/public/common/gpu_info.h" |
| 47 #include "googleurl/src/gurl.h" | 49 #include "googleurl/src/gurl.h" |
| 50 #include "net/base/net_util.h" | |
| 48 #include "net/base/network_change_notifier.h" | 51 #include "net/base/network_change_notifier.h" |
| 49 #include "ui/gfx/screen.h" | 52 #include "ui/gfx/screen.h" |
| 50 #include "webkit/plugins/webplugininfo.h" | 53 #include "webkit/plugins/webplugininfo.h" |
| 51 | 54 |
| 52 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
| 53 #include "base/android/build_info.h" | 56 #include "base/android/build_info.h" |
| 54 #endif | 57 #endif |
| 55 | 58 |
| 56 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) | 59 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 57 | 60 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 } | 305 } |
| 303 ReleaseDC(GetDesktopWindow(), desktop_dc); | 306 ReleaseDC(GetDesktopWindow(), desktop_dc); |
| 304 } | 307 } |
| 305 } | 308 } |
| 306 | 309 |
| 307 #endif // defined(OS_WIN) | 310 #endif // defined(OS_WIN) |
| 308 | 311 |
| 309 } // namespace | 312 } // namespace |
| 310 | 313 |
| 311 class MetricsLog::NetworkObserver | 314 class MetricsLog::NetworkObserver |
| 312 : public net::NetworkChangeNotifier::ConnectionTypeObserver { | 315 : public net::NetworkChangeNotifier::ConnectionTypeObserver { |
|
Ilya Sherman
2013/02/11 06:26:13
Can you move this class out to its own header file
szym
2013/02/11 08:30:53
Done.
| |
| 313 public: | 316 public: |
| 314 NetworkObserver() : connection_type_is_ambiguous_(false) { | 317 NetworkObserver() |
| 318 : weak_ptr_factory_(this), | |
|
Ilya Sherman
2013/02/11 06:26:13
nit: ALLOW_THIS_IN_...
szym
2013/02/11 08:30:53
Done.
| |
| 319 connection_type_is_ambiguous_(false), | |
| 320 wifi_phy_mode_is_ambiguous_(false) { | |
| 315 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 321 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 316 Reset(); | 322 Reset(); |
| 317 } | 323 } |
| 318 virtual ~NetworkObserver() { | 324 virtual ~NetworkObserver() { |
| 319 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 325 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 320 } | 326 } |
| 321 | 327 |
| 322 void Reset() { | 328 void Reset() { |
| 323 connection_type_is_ambiguous_ = false; | 329 connection_type_is_ambiguous_ = false; |
| 324 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); | 330 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
| 331 wifi_phy_mode_is_ambiguous_ = false; | |
| 332 wifi_phy_mode_ = net::WIFI_PHY_MODE_UNKNOWN; | |
| 325 } | 333 } |
| 326 | 334 |
| 327 // ConnectionTypeObserver: | 335 // ConnectionTypeObserver: |
| 328 virtual void OnConnectionTypeChanged( | 336 virtual void OnConnectionTypeChanged( |
| 329 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 337 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { |
| 330 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) | 338 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) |
| 331 return; | 339 return; |
| 332 if (type != connection_type_ && | 340 if (type != connection_type_ && |
| 333 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { | 341 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 334 connection_type_is_ambiguous_ = true; | 342 connection_type_is_ambiguous_ = true; |
| 335 } | 343 } |
| 336 connection_type_ = type; | 344 connection_type_ = type; |
| 345 | |
| 346 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 347 new WifiPhyModeJob(weak_ptr_factory_.GetWeakPtr()); | |
| 337 } | 348 } |
| 338 | 349 |
| 339 bool connection_type_is_ambiguous() const { | 350 bool connection_type_is_ambiguous() const { |
| 340 return connection_type_is_ambiguous_; | 351 return connection_type_is_ambiguous_; |
| 341 } | 352 } |
| 342 | 353 |
| 343 SystemProfileProto::Network::ConnectionType connection_type() const { | 354 SystemProfileProto::Network::ConnectionType connection_type() const { |
| 344 switch (connection_type_) { | 355 switch (connection_type_) { |
| 345 case net::NetworkChangeNotifier::CONNECTION_NONE: | 356 case net::NetworkChangeNotifier::CONNECTION_NONE: |
| 346 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: | 357 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| 347 return SystemProfileProto::Network::CONNECTION_UNKNOWN; | 358 return SystemProfileProto::Network::CONNECTION_UNKNOWN; |
| 348 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: | 359 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| 349 return SystemProfileProto::Network::CONNECTION_ETHERNET; | 360 return SystemProfileProto::Network::CONNECTION_ETHERNET; |
| 350 case net::NetworkChangeNotifier::CONNECTION_WIFI: | 361 case net::NetworkChangeNotifier::CONNECTION_WIFI: |
| 351 return SystemProfileProto::Network::CONNECTION_WIFI; | 362 return SystemProfileProto::Network::CONNECTION_WIFI; |
| 352 case net::NetworkChangeNotifier::CONNECTION_2G: | 363 case net::NetworkChangeNotifier::CONNECTION_2G: |
| 353 return SystemProfileProto::Network::CONNECTION_2G; | 364 return SystemProfileProto::Network::CONNECTION_2G; |
| 354 case net::NetworkChangeNotifier::CONNECTION_3G: | 365 case net::NetworkChangeNotifier::CONNECTION_3G: |
| 355 return SystemProfileProto::Network::CONNECTION_3G; | 366 return SystemProfileProto::Network::CONNECTION_3G; |
| 356 case net::NetworkChangeNotifier::CONNECTION_4G: | 367 case net::NetworkChangeNotifier::CONNECTION_4G: |
| 357 return SystemProfileProto::Network::CONNECTION_4G; | 368 return SystemProfileProto::Network::CONNECTION_4G; |
| 358 } | 369 } |
| 359 NOTREACHED(); | 370 NOTREACHED(); |
| 360 return SystemProfileProto::Network::CONNECTION_UNKNOWN; | 371 return SystemProfileProto::Network::CONNECTION_UNKNOWN; |
| 361 } | 372 } |
| 362 | 373 |
| 374 bool wifi_phy_mode_is_ambiguous() const { | |
| 375 return wifi_phy_mode_is_ambiguous_; | |
| 376 } | |
| 377 | |
| 378 SystemProfileProto::Network::WifiPhyMode wifi_phy_mode() const { | |
| 379 switch (wifi_phy_mode_) { | |
| 380 case net::WIFI_PHY_MODE_NONE: | |
| 381 return SystemProfileProto::Network::WIFI_PHY_MODE_NONE; | |
| 382 case net::WIFI_PHY_MODE_ANCIENT: | |
| 383 return SystemProfileProto::Network::WIFI_PHY_MODE_ANCIENT; | |
| 384 case net::WIFI_PHY_MODE_A: | |
| 385 return SystemProfileProto::Network::WIFI_PHY_MODE_A; | |
| 386 case net::WIFI_PHY_MODE_B: | |
| 387 return SystemProfileProto::Network::WIFI_PHY_MODE_B; | |
| 388 case net::WIFI_PHY_MODE_G: | |
| 389 return SystemProfileProto::Network::WIFI_PHY_MODE_G; | |
| 390 case net::WIFI_PHY_MODE_N: | |
| 391 return SystemProfileProto::Network::WIFI_PHY_MODE_N; | |
| 392 case net::WIFI_PHY_MODE_UNKNOWN: | |
| 393 return SystemProfileProto::Network::WIFI_PHY_MODE_UNKNOWN; | |
| 394 } | |
| 395 NOTREACHED(); | |
| 396 return SystemProfileProto::Network::WIFI_PHY_MODE_UNKNOWN; | |
| 397 } | |
| 398 | |
| 363 private: | 399 private: |
| 400 class WifiPhyModeJob { | |
|
Ilya Sherman
2013/02/11 06:26:13
Why are you creating a class for this, rather than
szym
2013/02/11 08:30:53
A separate class (a DataBuffer) to hold the result
| |
| 401 public: | |
| 402 explicit WifiPhyModeJob(const base::WeakPtr<NetworkObserver>& observer) | |
| 403 : observer_(observer) { | |
| 404 base::WorkerPool::PostTaskAndReply( | |
| 405 FROM_HERE, | |
| 406 base::Bind(&WifiPhyModeJob::DoProbe, base::Unretained(this)), | |
| 407 base::Bind(&WifiPhyModeJob::OnProbeComplete, base::Owned(this)), | |
| 408 true /* isSlow */); | |
| 409 } | |
| 410 virtual ~WifiPhyModeJob() {} | |
| 411 | |
| 412 private: | |
| 413 // Runs on worker thread. | |
| 414 void DoProbe() { | |
| 415 result_ = net::GetWifiPhyMode(); | |
|
Ilya Sherman
2013/02/11 06:26:13
This is not thread-safe. Why are you storing the
szym
2013/02/11 08:30:53
This is as thread-safe as the PostTaskAndReply exa
| |
| 416 } | |
| 417 | |
| 418 void OnProbeComplete() { | |
| 419 if (observer_) | |
| 420 observer_->OnWifiModeChanged(result_); | |
| 421 } | |
| 422 | |
| 423 base::WeakPtr<NetworkObserver> observer_; | |
| 424 net::WifiPhyMode result_; | |
| 425 | |
| 426 DISALLOW_COPY_AND_ASSIGN(WifiPhyModeJob); | |
| 427 }; | |
| 428 | |
| 429 void OnWifiModeChanged(net::WifiPhyMode mode) { | |
| 430 if (mode != wifi_phy_mode_) | |
| 431 wifi_phy_mode_is_ambiguous_ = true; | |
| 432 wifi_phy_mode_ = mode; | |
| 433 } | |
| 434 | |
| 435 base::WeakPtrFactory<NetworkObserver> weak_ptr_factory_; | |
| 436 | |
| 364 bool connection_type_is_ambiguous_; | 437 bool connection_type_is_ambiguous_; |
| 365 net::NetworkChangeNotifier::ConnectionType connection_type_; | 438 net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 366 | 439 |
| 440 bool wifi_phy_mode_is_ambiguous_; | |
| 441 net::WifiPhyMode wifi_phy_mode_; | |
| 442 | |
| 367 DISALLOW_COPY_AND_ASSIGN(NetworkObserver); | 443 DISALLOW_COPY_AND_ASSIGN(NetworkObserver); |
| 368 }; | 444 }; |
| 369 | 445 |
| 370 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} | 446 GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| 371 | 447 |
| 372 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} | 448 GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
| 373 | 449 |
| 374 static base::LazyInstance<std::string>::Leaky | 450 static base::LazyInstance<std::string>::Leaky |
| 375 g_version_extension = LAZY_INSTANCE_INITIALIZER; | 451 g_version_extension = LAZY_INSTANCE_INITIALIZER; |
| 376 | 452 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); | 947 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
| 872 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); | 948 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 873 #if defined(OS_WIN) | 949 #if defined(OS_WIN) |
| 874 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); | 950 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
| 875 #endif | 951 #endif |
| 876 | 952 |
| 877 SystemProfileProto::Network* network = system_profile->mutable_network(); | 953 SystemProfileProto::Network* network = system_profile->mutable_network(); |
| 878 network->set_connection_type_is_ambiguous( | 954 network->set_connection_type_is_ambiguous( |
| 879 network_observer_->connection_type_is_ambiguous()); | 955 network_observer_->connection_type_is_ambiguous()); |
| 880 network->set_connection_type(network_observer_->connection_type()); | 956 network->set_connection_type(network_observer_->connection_type()); |
| 957 network->set_wifi_phy_mode_is_ambiguous( | |
| 958 network_observer_->wifi_phy_mode_is_ambiguous()); | |
| 959 network->set_wifi_phy_mode(network_observer_->wifi_phy_mode()); | |
| 881 network_observer_->Reset(); | 960 network_observer_->Reset(); |
| 882 | 961 |
| 883 SystemProfileProto::OS* os = system_profile->mutable_os(); | 962 SystemProfileProto::OS* os = system_profile->mutable_os(); |
| 884 std::string os_name = base::SysInfo::OperatingSystemName(); | 963 std::string os_name = base::SysInfo::OperatingSystemName(); |
| 885 #if defined(OS_WIN) | 964 #if defined(OS_WIN) |
| 886 // TODO(mad): This only checks whether the main process is a Metro process at | 965 // TODO(mad): This only checks whether the main process is a Metro process at |
| 887 // upload time; not whether the collected metrics were all gathered from | 966 // upload time; not whether the collected metrics were all gathered from |
| 888 // Metro. This is ok as an approximation for now, since users will rarely be | 967 // Metro. This is ok as an approximation for now, since users will rarely be |
| 889 // switching from Metro to Desktop mode; but we should re-evaluate whether we | 968 // switching from Metro to Desktop mode; but we should re-evaluate whether we |
| 890 // can distinguish metrics more cleanly in the future: http://crbug.com/140568 | 969 // can distinguish metrics more cleanly in the future: http://crbug.com/140568 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1144 ProductDataToProto(google_update_metrics.google_update_data, | 1223 ProductDataToProto(google_update_metrics.google_update_data, |
| 1145 google_update->mutable_google_update_status()); | 1224 google_update->mutable_google_update_status()); |
| 1146 } | 1225 } |
| 1147 | 1226 |
| 1148 if (!google_update_metrics.product_data.version.empty()) { | 1227 if (!google_update_metrics.product_data.version.empty()) { |
| 1149 ProductDataToProto(google_update_metrics.product_data, | 1228 ProductDataToProto(google_update_metrics.product_data, |
| 1150 google_update->mutable_client_status()); | 1229 google_update->mutable_client_status()); |
| 1151 } | 1230 } |
| 1152 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) | 1231 #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 1153 } | 1232 } |
| OLD | NEW |