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 a63fc2d37936d8f1d8463bd6a0403694bbe343bc..2c77487f4fc65589914561a7c598e4a718095731 100644 |
| --- a/chrome/browser/metrics/metrics_log.cc |
| +++ b/chrome/browser/metrics/metrics_log.cc |
| @@ -43,6 +43,7 @@ |
| #include "content/public/common/content_client.h" |
| #include "content/public/common/gpu_info.h" |
| #include "googleurl/src/gurl.h" |
| +#include "net/base/network_change_notifier.h" |
| #include "ui/gfx/screen.h" |
| #include "webkit/plugins/webplugininfo.h" |
| @@ -304,6 +305,64 @@ void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { |
| } // namespace |
| +class MetricsLog::NetworkObserver |
| + : public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| + public: |
| + NetworkObserver() : is_ambiguous_(false) { |
| + net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| + Reset(); |
| + } |
| + virtual ~NetworkObserver() { |
| + net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| + } |
| + |
| + void Reset() { |
| + is_ambiguous_ = false; |
| + connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
| + } |
| + |
| + // ConnectionTypeObserver: |
| + virtual void OnConnectionTypeChanged( |
| + net::NetworkChangeNotifier::ConnectionType type) OVERRIDE { |
| + if (type == net::NetworkChangeNotifier::CONNECTION_NONE) |
| + return; |
| + if (type != connection_type_ && |
| + connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| + is_ambiguous_ = true; |
| + } |
| + connection_type_ = type; |
| + } |
| + |
| + bool is_ambiguous() const { return is_ambiguous_; } |
| + |
| + SystemProfileProto::Network::ConnectionType connection_type() const { |
| + switch (connection_type_) { |
| + case net::NetworkChangeNotifier::CONNECTION_NONE: |
| + case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| + return SystemProfileProto::Network::CONNECTION_UNKNOWN; |
| + case net::NetworkChangeNotifier::CONNECTION_ETHERNET: |
| + return SystemProfileProto::Network::CONNECTION_ETHERNET; |
| + case net::NetworkChangeNotifier::CONNECTION_WIFI: |
| + return SystemProfileProto::Network::CONNECTION_WIFI; |
| + case net::NetworkChangeNotifier::CONNECTION_2G: |
| + return SystemProfileProto::Network::CONNECTION_2G; |
| + case net::NetworkChangeNotifier::CONNECTION_3G: |
| + return SystemProfileProto::Network::CONNECTION_3G; |
| + case net::NetworkChangeNotifier::CONNECTION_4G: |
| + return SystemProfileProto::Network::CONNECTION_4G; |
| + default: |
| + NOTREACHED(); |
| + 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
|
| + } |
| + } |
| + |
| + private: |
| + bool is_ambiguous_; |
| + net::NetworkChangeNotifier::ConnectionType connection_type_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NetworkObserver); |
| +}; |
| + |
| GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
| @@ -312,7 +371,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()), |
| + network_observer_(new NetworkObserver()) {} |
| MetricsLog::~MetricsLog() {} |
| @@ -816,6 +876,11 @@ void MetricsLog::RecordEnvironmentProto( |
| hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
| #endif |
| + SystemProfileProto::Network* network = system_profile->mutable_network(); |
| + network->set_is_ambiguous(network_observer_->is_ambiguous()); |
| + network->set_connection_type(network_observer_->connection_type()); |
| + network_observer_->Reset(); |
| + |
| SystemProfileProto::OS* os = system_profile->mutable_os(); |
| std::string os_name = base::SysInfo::OperatingSystemName(); |
| #if defined(OS_WIN) |