Add EffectiveConnectionType enum to the system profile proto

Value of the EffectiveConnectionType enum is provided by the
NetworkMetricsProvider.

A new class EffectiveConnectionTypeObserver has been added which listens
to the changes in the EffectiveConnectionType, and lives on the same
thread as the NetworkQualityEstimator.

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_cronet_tester

BUG=677158

Review-Url: https://codereview.chromium.org/2605553002
Cr-Commit-Position: refs/heads/master@{#442821}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index ee3e743d..8e77a11 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -603,6 +603,8 @@
     "metrics/metrics_memory_details.h",
     "metrics/metrics_reporting_state.cc",
     "metrics/metrics_reporting_state.h",
+    "metrics/network_quality_estimator_provider_impl.cc",
+    "metrics/network_quality_estimator_provider_impl.h",
     "metrics/perf/perf_provider_chromeos.cc",
     "metrics/perf/perf_provider_chromeos.h",
     "metrics/sampling_metrics_provider.cc",
diff --git a/chrome/browser/metrics/chrome_metrics_service_client.cc b/chrome/browser/metrics/chrome_metrics_service_client.cc
index f736507..1c82b2bc 100644
--- a/chrome/browser/metrics/chrome_metrics_service_client.cc
+++ b/chrome/browser/metrics/chrome_metrics_service_client.cc
@@ -32,6 +32,7 @@
 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
 #include "chrome/browser/metrics/https_engagement_metrics_provider.h"
 #include "chrome/browser/metrics/metrics_reporting_state.h"
+#include "chrome/browser/metrics/network_quality_estimator_provider_impl.h"
 #include "chrome/browser/metrics/sampling_metrics_provider.h"
 #include "chrome/browser/metrics/subprocess_metrics_provider.h"
 #include "chrome/browser/metrics/time_ticks_experiment_win.h"
@@ -571,10 +572,12 @@
       std::unique_ptr<metrics::MetricsProvider>(
           new ExtensionsMetricsProvider(metrics_state_manager_)));
 #endif
+
   metrics_service_->RegisterMetricsProvider(
-      std::unique_ptr<metrics::MetricsProvider>(
-          new metrics::NetworkMetricsProvider(
-              content::BrowserThread::GetBlockingPool())));
+      base::MakeUnique<metrics::NetworkMetricsProvider>(
+          base::MakeUnique<metrics::NetworkQualityEstimatorProviderImpl>(
+              g_browser_process->io_thread()),
+          content::BrowserThread::GetBlockingPool()));
 
   // Currently, we configure OmniboxMetricsProvider to not log events to UMA
   // if there is a single incognito session visible. In the future, it may
diff --git a/chrome/browser/metrics/network_quality_estimator_provider_impl.cc b/chrome/browser/metrics/network_quality_estimator_provider_impl.cc
new file mode 100644
index 0000000..144fa60
--- /dev/null
+++ b/chrome/browser/metrics/network_quality_estimator_provider_impl.cc
@@ -0,0 +1,42 @@
+// Copyright 2017 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/network_quality_estimator_provider_impl.h"
+
+#include "chrome/browser/io_thread.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace net {
+class NetworkQualityEstimator;
+}
+
+namespace metrics {
+
+NetworkQualityEstimatorProviderImpl::NetworkQualityEstimatorProviderImpl(
+    IOThread* io_thread)
+    : io_thread_(io_thread) {
+  DCHECK(io_thread_);
+}
+
+NetworkQualityEstimatorProviderImpl::~NetworkQualityEstimatorProviderImpl() {
+  DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+scoped_refptr<base::SequencedTaskRunner>
+NetworkQualityEstimatorProviderImpl::GetTaskRunner() {
+  DCHECK(thread_checker_.CalledOnValidThread());
+  // |this| is constructed on UI thread, but must be used on the IO thread.
+  thread_checker_.DetachFromThread();
+  return content::BrowserThread::GetTaskRunnerForThread(
+      content::BrowserThread::IO);
+}
+
+net::NetworkQualityEstimator*
+NetworkQualityEstimatorProviderImpl::GetNetworkQualityEstimator() {
+  DCHECK(thread_checker_.CalledOnValidThread());
+  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+  return io_thread_->globals()->network_quality_estimator.get();
+}
+
+}  // namespace metrics
diff --git a/chrome/browser/metrics/network_quality_estimator_provider_impl.h b/chrome/browser/metrics/network_quality_estimator_provider_impl.h
new file mode 100644
index 0000000..9495d8d
--- /dev/null
+++ b/chrome/browser/metrics/network_quality_estimator_provider_impl.h
@@ -0,0 +1,38 @@
+// Copyright 2017 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_NETWORK_QUALITY_ESTIMATOR_PROVIDER_IMPL_H_
+#define CHROME_BROWSER_METRICS_NETWORK_QUALITY_ESTIMATOR_PROVIDER_IMPL_H_
+
+#include "base/macros.h"
+#include "base/threading/thread_checker.h"
+#include "components/metrics/net/network_metrics_provider.h"
+
+class IOThread;
+
+namespace metrics {
+
+// Implements NetworkMetricsProvider::NetworkQualityEstimatorProvider. Provides
+// NetworkQualityEstimator by querying the IOThread.
+class NetworkQualityEstimatorProviderImpl
+    : public NetworkMetricsProvider::NetworkQualityEstimatorProvider {
+ public:
+  explicit NetworkQualityEstimatorProviderImpl(IOThread* io_thread);
+  ~NetworkQualityEstimatorProviderImpl() override;
+
+ private:
+  // NetworkMetricsProvider::NetworkQualityEstimatorProvider:
+  scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() override;
+  net::NetworkQualityEstimator* GetNetworkQualityEstimator() override;
+
+  IOThread* io_thread_;
+
+  base::ThreadChecker thread_checker_;
+
+  DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProviderImpl);
+};
+
+}  // namespace metrics
+
+#endif  // CHROME_BROWSER_METRICS_NETWORK_QUALITY_ESTIMATOR_PROVIDER_IMPL_H_