summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 18:50:19 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 18:50:19 +0000
commit536324ec9e4c6c9db5f3a2485f793ec64e3c4b0f (patch)
treed817555fa6e206a572d4cf07f2f3399bf9396cae
parent17a6219729e23c3053dabebbb7d2d6cca43a135f (diff)
downloadchromium_src-536324ec9e4c6c9db5f3a2485f793ec64e3c4b0f.zip
chromium_src-536324ec9e4c6c9db5f3a2485f793ec64e3c4b0f.tar.gz
chromium_src-536324ec9e4c6c9db5f3a2485f793ec64e3c4b0f.tar.bz2
[Metrics] Transform the MetricsNetworkObserver class into a MetricsProvider subclass.
BUG=374224 TEST=none R=asvitkine@chromium.org Review URL: https://codereview.chromium.org/296043009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272256 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/metrics/metrics_log.cc10
-rw-r--r--chrome/browser/metrics/metrics_log.h5
-rw-r--r--chrome/browser/metrics/metrics_log_unittest.cc2
-rw-r--r--chrome/browser/metrics/metrics_service.cc5
-rw-r--r--chrome/browser/metrics/network_metrics_provider.cc (renamed from chrome/browser/metrics/metrics_network_observer.cc)40
-rw-r--r--chrome/browser/metrics/network_metrics_provider.h (renamed from chrome/browser/metrics/metrics_network_observer.h)49
-rw-r--r--chrome/chrome_browser.gypi4
7 files changed, 53 insertions, 62 deletions
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 05bb173..27c1295 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -570,16 +570,6 @@ void MetricsLog::RecordEnvironment(
hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
#endif
- SystemProfileProto::Network* network = system_profile->mutable_network();
- network->set_connection_type_is_ambiguous(
- network_observer_.connection_type_is_ambiguous());
- network->set_connection_type(network_observer_.connection_type());
- network->set_wifi_phy_layer_protocol_is_ambiguous(
- network_observer_.wifi_phy_layer_protocol_is_ambiguous());
- network->set_wifi_phy_layer_protocol(
- network_observer_.wifi_phy_layer_protocol());
- network_observer_.Reset();
-
SystemProfileProto::OS* os = system_profile->mutable_os();
std::string os_name = base::SysInfo::OperatingSystemName();
#if defined(OS_WIN)
diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h
index 225ef49..177bf31 100644
--- a/chrome/browser/metrics/metrics_log.h
+++ b/chrome/browser/metrics/metrics_log.h
@@ -13,14 +13,12 @@
#include "base/basictypes.h"
#include "chrome/browser/metrics/extension_metrics.h"
-#include "chrome/browser/metrics/metrics_network_observer.h"
#include "chrome/common/variations/variations_util.h"
#include "chrome/installer/util/google_update_settings.h"
#include "components/metrics/metrics_log_base.h"
#include "ui/gfx/size.h"
class HashedExtensionMetrics;
-class MetricsNetworkObserver;
class PrefService;
class PrefRegistrySimple;
@@ -168,9 +166,6 @@ class MetricsLog : public metrics::MetricsLogBase {
// instance.
metrics::MetricsServiceClient* const client_;
- // Observes network state to provide values for SystemProfile::Network.
- MetricsNetworkObserver network_observer_;
-
// The time when the current log was created.
const base::TimeTicks creation_time_;
diff --git a/chrome/browser/metrics/metrics_log_unittest.cc b/chrome/browser/metrics/metrics_log_unittest.cc
index 8241922..a2ae6f4 100644
--- a/chrome/browser/metrics/metrics_log_unittest.cc
+++ b/chrome/browser/metrics/metrics_log_unittest.cc
@@ -336,7 +336,7 @@ TEST_F(MetricsLogTest, RecordEnvironment) {
std::string serialied_system_profile;
EXPECT_TRUE(base::Base64Decode(base64_system_profile,
&serialied_system_profile));
- SystemProfileProto decoded_system_profile;
+ metrics::SystemProfileProto decoded_system_profile;
EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile));
CheckSystemProfile(decoded_system_profile);
}
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 73f8170..b4c96c4 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -189,6 +189,7 @@
#include "chrome/browser/metrics/compression_utils.h"
#include "chrome/browser/metrics/metrics_log.h"
#include "chrome/browser/metrics/metrics_state_manager.h"
+#include "chrome/browser/metrics/network_metrics_provider.h"
#include "chrome/browser/metrics/omnibox_metrics_provider.h"
#include "chrome/browser/metrics/tracking_synchronizer.h"
#include "chrome/browser/ui/browser_otr_state.h"
@@ -466,7 +467,9 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager,
g_browser_process->local_state())));
#endif // defined(OS_ANDROID)
- // TODO(asvitkine): Move this out of MetricsService.
+ // TODO(asvitkine): Move these out of MetricsService.
+ RegisterMetricsProvider(
+ scoped_ptr<metrics::MetricsProvider>(new NetworkMetricsProvider));
RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
diff --git a/chrome/browser/metrics/metrics_network_observer.cc b/chrome/browser/metrics/network_metrics_provider.cc
index 9717d1d..006e1a7 100644
--- a/chrome/browser/metrics/metrics_network_observer.cc
+++ b/chrome/browser/metrics/network_metrics_provider.cc
@@ -1,36 +1,47 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/metrics/metrics_network_observer.h"
+#include "chrome/browser/metrics/network_metrics_provider.h"
#include "base/compiler_specific.h"
#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "content/public/browser/browser_thread.h"
+using metrics::SystemProfileProto;
-MetricsNetworkObserver::MetricsNetworkObserver()
- : weak_ptr_factory_(this),
- connection_type_is_ambiguous_(false),
+NetworkMetricsProvider::NetworkMetricsProvider()
+ : connection_type_is_ambiguous_(false),
wifi_phy_layer_protocol_is_ambiguous_(false),
- wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN) {
+ wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN),
+ weak_ptr_factory_(this) {
net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
ProbeWifiPHYLayerProtocol();
}
-MetricsNetworkObserver::~MetricsNetworkObserver() {
+NetworkMetricsProvider::~NetworkMetricsProvider() {
net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
}
-void MetricsNetworkObserver::Reset() {
+void NetworkMetricsProvider::ProvideSystemProfileMetrics(
+ SystemProfileProto* system_profile) {
+ SystemProfileProto::Network* network = system_profile->mutable_network();
+ network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_);
+ network->set_connection_type(GetConnectionType());
+ network->set_wifi_phy_layer_protocol_is_ambiguous(
+ wifi_phy_layer_protocol_is_ambiguous_);
+ network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol());
+
+ // Resets the "ambiguous" flags, since a new metrics log session has started.
connection_type_is_ambiguous_ = false;
+ // TODO(isherman): This line seems unnecessary.
connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
wifi_phy_layer_protocol_is_ambiguous_ = false;
}
-void MetricsNetworkObserver::OnConnectionTypeChanged(
+void NetworkMetricsProvider::OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) {
if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
return;
@@ -44,7 +55,7 @@ void MetricsNetworkObserver::OnConnectionTypeChanged(
}
SystemProfileProto::Network::ConnectionType
-MetricsNetworkObserver::connection_type() const {
+NetworkMetricsProvider::GetConnectionType() const {
switch (connection_type_) {
case net::NetworkChangeNotifier::CONNECTION_NONE:
case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
@@ -65,7 +76,7 @@ MetricsNetworkObserver::connection_type() const {
}
SystemProfileProto::Network::WifiPHYLayerProtocol
-MetricsNetworkObserver::wifi_phy_layer_protocol() const {
+NetworkMetricsProvider::GetWifiPHYLayerProtocol() const {
switch (wifi_phy_layer_protocol_) {
case net::WIFI_PHY_LAYER_PROTOCOL_NONE:
return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_NONE;
@@ -86,16 +97,16 @@ MetricsNetworkObserver::wifi_phy_layer_protocol() const {
return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN;
}
-void MetricsNetworkObserver::ProbeWifiPHYLayerProtocol() {
+void NetworkMetricsProvider::ProbeWifiPHYLayerProtocol() {
PostTaskAndReplyWithResult(
content::BrowserThread::GetBlockingPool(),
FROM_HERE,
base::Bind(&net::GetWifiPHYLayerProtocol),
- base::Bind(&MetricsNetworkObserver::OnWifiPHYLayerProtocolResult,
+ base::Bind(&NetworkMetricsProvider::OnWifiPHYLayerProtocolResult,
weak_ptr_factory_.GetWeakPtr()));
}
-void MetricsNetworkObserver::OnWifiPHYLayerProtocolResult(
+void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult(
net::WifiPHYLayerProtocol mode) {
if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN &&
mode != wifi_phy_layer_protocol_) {
@@ -103,4 +114,3 @@ void MetricsNetworkObserver::OnWifiPHYLayerProtocolResult(
}
wifi_phy_layer_protocol_ = mode;
}
-
diff --git a/chrome/browser/metrics/metrics_network_observer.h b/chrome/browser/metrics/network_metrics_provider.h
index e64800b..21bd4f8 100644
--- a/chrome/browser/metrics/metrics_network_observer.h
+++ b/chrome/browser/metrics/network_metrics_provider.h
@@ -1,56 +1,47 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_
-#define CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_
+#ifndef CHROME_BROWSER_METRICS_NETWORK_METRICS_PROVIDER_H_
+#define CHROME_BROWSER_METRICS_NETWORK_METRICS_PROVIDER_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "components/metrics/metrics_provider.h"
#include "components/metrics/proto/system_profile.pb.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
-using metrics::SystemProfileProto;
-
// Registers as observer with net::NetworkChangeNotifier and keeps track of
// the network environment.
-class MetricsNetworkObserver
- : public net::NetworkChangeNotifier::ConnectionTypeObserver {
+class NetworkMetricsProvider
+ : public metrics::MetricsProvider,
+ public net::NetworkChangeNotifier::ConnectionTypeObserver {
public:
- MetricsNetworkObserver();
- virtual ~MetricsNetworkObserver();
+ NetworkMetricsProvider();
+ virtual ~NetworkMetricsProvider();
- // Resets the "ambiguous" flags. Call when the environment is recorded.
- void Reset();
+ // metrics::MetricsProvider:
+ virtual void ProvideSystemProfileMetrics(
+ metrics::SystemProfileProto* system_profile) OVERRIDE;
// ConnectionTypeObserver:
virtual void OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
- bool connection_type_is_ambiguous() const {
- return connection_type_is_ambiguous_;
- }
-
- SystemProfileProto::Network::ConnectionType connection_type() const;
-
- bool wifi_phy_layer_protocol_is_ambiguous() const {
- return wifi_phy_layer_protocol_is_ambiguous_;
- }
-
- SystemProfileProto::Network::WifiPHYLayerProtocol
- wifi_phy_layer_protocol() const;
-
private:
+ metrics::SystemProfileProto::Network::ConnectionType
+ GetConnectionType() const;
+ metrics::SystemProfileProto::Network::WifiPHYLayerProtocol
+ GetWifiPHYLayerProtocol() const;
+
// Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
void ProbeWifiPHYLayerProtocol();
// Callback from the blocking pool with the result of
// net::GetWifiPHYLayerProtocol.
void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode);
- base::WeakPtrFactory<MetricsNetworkObserver> weak_ptr_factory_;
-
// True if |connection_type_| changed during the lifetime of the log.
bool connection_type_is_ambiguous_;
// The connection type according to net::NetworkChangeNotifier.
@@ -62,7 +53,9 @@ class MetricsNetworkObserver
// net::GetWifiPHYLayerProtocol.
net::WifiPHYLayerProtocol wifi_phy_layer_protocol_;
- DISALLOW_COPY_AND_ASSIGN(MetricsNetworkObserver);
+ base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
};
-#endif // CHROME_BROWSER_METRICS_METRICS_NETWORK_OBSERVER_H_
+#endif // CHROME_BROWSER_METRICS_NETWORK_METRICS_PROVIDER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 7cc7d67..180f68b 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1202,14 +1202,14 @@
'browser/metrics/metrics_log.h',
'browser/metrics/metrics_log_chromeos.cc',
'browser/metrics/metrics_log_chromeos.h',
- 'browser/metrics/metrics_network_observer.cc',
- 'browser/metrics/metrics_network_observer.h',
'browser/metrics/metrics_service.cc',
'browser/metrics/metrics_service.h',
'browser/metrics/metrics_services_manager.cc',
'browser/metrics/metrics_services_manager.h',
'browser/metrics/metrics_state_manager.cc',
'browser/metrics/metrics_state_manager.h',
+ 'browser/metrics/network_metrics_provider.cc',
+ 'browser/metrics/network_metrics_provider.h',
'browser/metrics/network_stats_uploader.cc',
'browser/metrics/network_stats_uploader.h',
'browser/metrics/omnibox_metrics_provider.cc',