Move NQE prefs from browser process to network

Currently, Network Quality Estimator (NQE) stores
prefs on the disk. These prefs are managed (written t0
and read by) in the browser process, and then notified
to the network quality estimator object.

With network servicification, NQE object would live
in the network process, and would no longer be
accessible in the browser process.

This CL moves the management of prefs from the browser
process to the network process.

Bug: 878844
Change-Id: Id533c2260201c0c665ae3bde1a0fe955a140a70e
Reviewed-on: https://chromium-review.googlesource.com/c/1312977
Commit-Queue: Tarun Bansal <[email protected]>
Reviewed-by: Martin Šrámek <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Reviewed-by: Ryan Sturm <[email protected]>
Cr-Commit-Position: refs/heads/master@{#605910}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index f23f9eb..bfaed79 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -834,10 +834,6 @@
     "net/net_error_tab_helper.h",
     "net/net_export_helper.cc",
     "net/net_export_helper.h",
-    "net/nqe/ui_network_quality_estimator_service.cc",
-    "net/nqe/ui_network_quality_estimator_service.h",
-    "net/nqe/ui_network_quality_estimator_service_factory.cc",
-    "net/nqe/ui_network_quality_estimator_service_factory.h",
     "net/prediction_options.cc",
     "net/prediction_options.h",
     "net/probe_message.cc",
diff --git a/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc b/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc
index aebf916..0f827aa 100644
--- a/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc
+++ b/chrome/browser/browsing_data/browsing_data_remover_browsertest.cc
@@ -15,6 +15,7 @@
 #include "base/run_loop.h"
 #include "base/strings/string_util.h"
 #include "base/test/bind_test_util.h"
+#include "base/test/metrics/histogram_tester.h"
 #include "base/test/scoped_feature_list.h"
 #include "base/threading/thread_restrictions.h"
 #include "base/time/time.h"
@@ -30,6 +31,7 @@
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
 #include "chrome/browser/external_protocol/external_protocol_handler.h"
+#include "chrome/browser/metrics/subprocess_metrics_provider.h"
 #include "chrome/browser/net/system_network_context_manager.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/profiles/profile_manager.h"
@@ -845,6 +847,34 @@
   RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_CACHE);
 }
 
+// Verifies that the network quality prefs are cleared.
+IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, VerifyNQECacheCleared) {
+  base::HistogramTester histogram_tester;
+  RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_CACHE);
+
+  // Wait until there is at least one sample in NQE.PrefsSizeOnClearing.
+  bool histogram_populated = false;
+  for (size_t attempt = 0; attempt < 3; ++attempt) {
+    const std::vector<base::Bucket> buckets =
+        histogram_tester.GetAllSamples("NQE.PrefsSizeOnClearing");
+    for (const auto& bucket : buckets) {
+      if (bucket.count > 0) {
+        histogram_populated = true;
+        break;
+      }
+    }
+    if (histogram_populated)
+      break;
+
+    // Retry fetching the histogram since it's not populated yet.
+    content::FetchHistogramsFromChildProcesses();
+    SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
+    base::RunLoop().RunUntilIdle();
+  }
+
+  histogram_tester.ExpectTotalCount("NQE.PrefsSizeOnClearing", 1);
+}
+
 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
                        ExternalProtocolHandlerPrefs) {
   Profile* profile = GetBrowser()->profile();
diff --git a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
index 32860c0..edcc47ee8 100644
--- a/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
+++ b/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
@@ -41,8 +41,6 @@
 #include "chrome/browser/media/media_device_id_salt.h"
 #include "chrome/browser/media/media_engagement_service.h"
 #include "chrome/browser/media/webrtc/webrtc_event_log_manager.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
@@ -915,20 +913,6 @@
 #endif  // BUILDFLAG(ENABLE_FEED_IN_CHROME)
 #endif  // defined(OS_ANDROID)
 
-    // |ui_nqe_service| may be null if |profile_| is not a regular profile.
-    UINetworkQualityEstimatorService* ui_nqe_service =
-        UINetworkQualityEstimatorServiceFactory::GetForProfile(profile_);
-    DCHECK(profile_->GetProfileType() !=
-               Profile::ProfileType::REGULAR_PROFILE ||
-           ui_nqe_service != nullptr);
-    if (ui_nqe_service) {
-      // Network Quality Estimator (NQE) stores the quality (RTT, bandwidth
-      // etc.) of different networks in prefs. The stored quality is not
-      // broken down by URLs or timestamps, so clearing the cache should
-      // completely clear the prefs.
-      ui_nqe_service->ClearPrefs();
-    }
-
     // Notify data reduction component.
     data_reduction_proxy::DataReductionProxySettings*
         data_reduction_proxy_settings =
diff --git a/chrome/browser/net/nqe/OWNERS b/chrome/browser/net/nqe/OWNERS
deleted file mode 100644
index 470cb3de..0000000
--- a/chrome/browser/net/nqe/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
[email protected]
-
-file://net/nqe/OWNERS
\ No newline at end of file
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc
deleted file mode 100644
index 4691cef9..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2016 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/net/nqe/ui_network_quality_estimator_service.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/memory/ptr_util.h"
-#include "base/metrics/histogram_macros.h"
-#include "base/task/post_task.h"
-#include "base/threading/thread_checker.h"
-#include "base/values.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/io_thread.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_registry.h"
-#include "components/prefs/pref_registry_simple.h"
-#include "components/prefs/pref_service.h"
-#include "content/public/browser/browser_task_traits.h"
-#include "content/public/browser/browser_thread.h"
-#include "net/nqe/network_qualities_prefs_manager.h"
-#include "net/nqe/network_quality_estimator.h"
-#include "net/url_request/url_request_context.h"
-
-namespace {
-
-// PrefDelegateImpl writes the provided dictionary value to the network quality
-// estimator prefs on the disk.
-class PrefDelegateImpl
-    : public net::NetworkQualitiesPrefsManager::PrefDelegate {
- public:
-  // |pref_service| is used to read and write prefs from/to the disk.
-  explicit PrefDelegateImpl(PrefService* pref_service)
-      : pref_service_(pref_service), path_(prefs::kNetworkQualities) {
-    DCHECK(pref_service_);
-  }
-  ~PrefDelegateImpl() override {}
-
-  void SetDictionaryValue(const base::DictionaryValue& value) override {
-    DCHECK(thread_checker_.CalledOnValidThread());
-
-    pref_service_->Set(path_, value);
-    UMA_HISTOGRAM_EXACT_LINEAR("NQE.Prefs.WriteCount", 1, 2);
-  }
-
-  std::unique_ptr<base::DictionaryValue> GetDictionaryValue() override {
-    DCHECK(thread_checker_.CalledOnValidThread());
-    UMA_HISTOGRAM_EXACT_LINEAR("NQE.Prefs.ReadCount", 1, 2);
-    return pref_service_->GetDictionary(path_)->CreateDeepCopy();
-  }
-
- private:
-  PrefService* pref_service_;
-
-  // |path_| is the location of the network quality estimator prefs.
-  const std::string path_;
-
-  base::ThreadChecker thread_checker_;
-
-  DISALLOW_COPY_AND_ASSIGN(PrefDelegateImpl);
-};
-
-// Initializes |pref_manager| on |io_thread|.
-void SetNQEOnIOThread(net::NetworkQualitiesPrefsManager* prefs_manager,
-                      IOThread* io_thread) {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
-
-  // Avoid null pointer referencing during browser shutdown, or when the network
-  // service is running out of process.
-  if (!io_thread->globals()->system_request_context ||
-      !io_thread->globals()
-           ->system_request_context->network_quality_estimator()) {
-    return;
-  }
-
-  prefs_manager->InitializeOnNetworkThread(
-      io_thread->globals()
-          ->system_request_context->network_quality_estimator());
-}
-
-}  // namespace
-
-UINetworkQualityEstimatorService::UINetworkQualityEstimatorService(
-    Profile* profile)
-    : weak_factory_(this) {
-  DCHECK(profile);
-  // If this is running in a context without an IOThread, don't try to create
-  // the IO object.
-  if (!g_browser_process->io_thread())
-    return;
-  std::unique_ptr<PrefDelegateImpl> pref_delegate(
-      new PrefDelegateImpl(profile->GetPrefs()));
-  prefs_manager_ = base::WrapUnique(
-      new net::NetworkQualitiesPrefsManager(std::move(pref_delegate)));
-
-  base::PostTaskWithTraits(
-      FROM_HERE, {content::BrowserThread::IO},
-      base::BindOnce(&SetNQEOnIOThread, prefs_manager_.get(),
-                     g_browser_process->io_thread()));
-}
-
-UINetworkQualityEstimatorService::~UINetworkQualityEstimatorService() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-}
-
-void UINetworkQualityEstimatorService::Shutdown() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  weak_factory_.InvalidateWeakPtrs();
-  if (prefs_manager_) {
-    prefs_manager_->ShutdownOnPrefSequence();
-    bool deleted = content::BrowserThread::DeleteSoon(
-        content::BrowserThread::IO, FROM_HERE, prefs_manager_.release());
-    DCHECK(deleted);
-    // Silence unused variable warning in release builds.
-    (void)deleted;
-  }
-}
-
-void UINetworkQualityEstimatorService::ClearPrefs() {
-  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
-  if (!prefs_manager_)
-    return;
-  prefs_manager_->ClearPrefs();
-}
-
-// static
-void UINetworkQualityEstimatorService::RegisterProfilePrefs(
-    PrefRegistrySimple* registry) {
-  registry->RegisterDictionaryPref(prefs::kNetworkQualities,
-                                   PrefRegistry::LOSSY_PREF);
-}
-
-std::map<net::nqe::internal::NetworkID,
-         net::nqe::internal::CachedNetworkQuality>
-UINetworkQualityEstimatorService::ForceReadPrefsForTesting() const {
-  if (!prefs_manager_) {
-    return std::map<net::nqe::internal::NetworkID,
-                    net::nqe::internal::CachedNetworkQuality>();
-  }
-  return prefs_manager_->ForceReadPrefsForTesting();
-}
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service.h b/chrome/browser/net/nqe/ui_network_quality_estimator_service.h
deleted file mode 100644
index 58401fa8..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2016 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_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
-#define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
-
-#include <stdint.h>
-
-#include <map>
-#include <memory>
-
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/time/time.h"
-#include "components/keyed_service/core/keyed_service.h"
-#include "net/nqe/cached_network_quality.h"
-#include "net/nqe/network_id.h"
-
-class PrefRegistrySimple;
-class Profile;
-
-namespace net {
-class NetworkQualitiesPrefsManager;
-}
-
-// UI service to manage storage of network quality prefs.
-class UINetworkQualityEstimatorService : public KeyedService {
- public:
-  explicit UINetworkQualityEstimatorService(Profile* profile);
-  ~UINetworkQualityEstimatorService() override;
-
-  // Registers the profile-specific network quality estimator prefs.
-  static void RegisterProfilePrefs(PrefRegistrySimple* registry);
-
-  // Clear the network quality estimator prefs.
-  void ClearPrefs();
-
-  // Reads the prefs from the disk, parses them into a map of NetworkIDs and
-  // CachedNetworkQualities, and returns the map.
-  std::map<net::nqe::internal::NetworkID,
-           net::nqe::internal::CachedNetworkQuality>
-  ForceReadPrefsForTesting() const;
-
- private:
-  // KeyedService implementation:
-  void Shutdown() override;
-
-  // Prefs manager that is owned by this service. Created on the UI thread, but
-  // used and deleted on the IO thread.
-  std::unique_ptr<net::NetworkQualitiesPrefsManager> prefs_manager_;
-
-  base::WeakPtrFactory<UINetworkQualityEstimatorService> weak_factory_;
-
-  DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorService);
-};
-
-#endif  // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_H_
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc
deleted file mode 100644
index 0027edd..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_browsertest.cc
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2016 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 <map>
-#include <string>
-
-#include "base/bind.h"
-#include "base/macros.h"
-#include "base/metrics/field_trial.h"
-#include "base/run_loop.h"
-#include "base/test/metrics/histogram_tester.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/io_thread.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.h"
-#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/test/base/in_process_browser_test.h"
-#include "components/variations/variations_associated_data.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/test/browser_test.h"
-#include "net/base/network_change_notifier.h"
-#include "net/nqe/cached_network_quality.h"
-#include "net/nqe/effective_connection_type.h"
-#include "net/nqe/network_id.h"
-#include "net/nqe/network_quality_estimator.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class Profile;
-
-namespace {
-
-class UINetworkQualityEstimatorServiceBrowserTest
-    : public InProcessBrowserTest {
- public:
-  UINetworkQualityEstimatorServiceBrowserTest() {}
-
-  // Verifies that the network quality prefs are written amd read correctly.
-  void VerifyWritingReadingPrefs() {
-    variations::testing::ClearAllVariationParams();
-    std::map<std::string, std::string> variation_params;
-
-    variations::AssociateVariationParams("NetworkQualityEstimator", "Enabled",
-                                         variation_params);
-    base::FieldTrialList::CreateFieldTrial("NetworkQualityEstimator",
-                                           "Enabled");
-
-    // Verifies that NQE notifying EffectiveConnectionTypeObservers causes the
-    // UINetworkQualityEstimatorService to receive an updated
-    // EffectiveConnectionType.
-    Profile* profile = ProfileManager::GetActiveUserProfile();
-
-    UINetworkQualityEstimatorService* nqe_service =
-        UINetworkQualityEstimatorServiceFactory::GetForProfile(profile);
-    ASSERT_NE(nullptr, nqe_service);
-    // NetworkQualityEstimator must be notified of the read prefs at startup.
-    EXPECT_FALSE(histogram_tester_.GetAllSamples("NQE.Prefs.ReadSize").empty());
-
-    {
-      base::HistogramTester histogram_tester;
-      nqe_test_util::OverrideEffectiveConnectionTypeAndWait(
-          net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
-
-      // Prefs are written only if persistent caching was enabled.
-      EXPECT_FALSE(
-          histogram_tester.GetAllSamples("NQE.Prefs.WriteCount").empty());
-      histogram_tester.ExpectTotalCount("NQE.Prefs.ReadCount", 0);
-
-      // NetworkQualityEstimator should not be notified of change in prefs.
-      histogram_tester.ExpectTotalCount("NQE.Prefs.ReadSize", 0);
-    }
-
-    {
-      base::HistogramTester histogram_tester;
-      nqe_test_util::OverrideEffectiveConnectionTypeAndWait(
-          net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
-
-      // Prefs are written even if the network id was unavailable.
-      EXPECT_FALSE(
-          histogram_tester.GetAllSamples("NQE.Prefs.WriteCount").empty());
-      histogram_tester.ExpectTotalCount("NQE.Prefs.ReadCount", 0);
-
-      // NetworkQualityEstimator should not be notified of change in prefs.
-      histogram_tester.ExpectTotalCount("NQE.Prefs.ReadSize", 0);
-    }
-
-    // Verify the contents of the prefs by reading them again.
-    std::map<net::nqe::internal::NetworkID,
-             net::nqe::internal::CachedNetworkQuality>
-        read_prefs = nqe_service->ForceReadPrefsForTesting();
-    // Number of entries must be between 1 and 2. It's possible that 2 entries
-    // are added if the connection type is unknown to network quality estimator
-    // at the time of startup, and shortly after it receives a notification
-    // about the change in the connection type.
-    EXPECT_LE(1u, read_prefs.size());
-    EXPECT_GE(2u, read_prefs.size());
-
-    // Verify that the cached network quality was written correctly.
-    EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
-              read_prefs.begin()->second.effective_connection_type());
-    if (net::NetworkChangeNotifier::GetConnectionType() ==
-        net::NetworkChangeNotifier::CONNECTION_ETHERNET) {
-      // Verify that the network ID was written correctly.
-      net::nqe::internal::NetworkID ethernet_network_id(
-          net::NetworkChangeNotifier::CONNECTION_ETHERNET, std::string(),
-          INT32_MIN);
-      EXPECT_EQ(ethernet_network_id, read_prefs.begin()->first);
-      }
-  }
-
- private:
-  base::HistogramTester histogram_tester_;
-
-  DISALLOW_COPY_AND_ASSIGN(UINetworkQualityEstimatorServiceBrowserTest);
-};
-
-}  // namespace
-
-// Verify that prefs are writen and read correctly.
-IN_PROC_BROWSER_TEST_F(UINetworkQualityEstimatorServiceBrowserTest,
-                       WritingReadingToPrefsEnabled) {
-  VerifyWritingReadingPrefs();
-}
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.cc
deleted file mode 100644
index d6aacd8..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2016 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/net/nqe/ui_network_quality_estimator_service_factory.h"
-
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
-#include "chrome/browser/profiles/incognito_helpers.h"
-#include "chrome/browser/profiles/profile.h"
-#include "components/keyed_service/content/browser_context_dependency_manager.h"
-#include "content/public/browser/browser_context.h"
-
-// static
-UINetworkQualityEstimatorService*
-UINetworkQualityEstimatorServiceFactory::GetForProfile(Profile* profile) {
-  return static_cast<UINetworkQualityEstimatorService*>(
-      GetInstance()->GetServiceForBrowserContext(profile, true));
-}
-
-// static
-UINetworkQualityEstimatorServiceFactory*
-UINetworkQualityEstimatorServiceFactory::GetInstance() {
-  return base::Singleton<UINetworkQualityEstimatorServiceFactory>::get();
-}
-
-UINetworkQualityEstimatorServiceFactory::
-    UINetworkQualityEstimatorServiceFactory()
-    : BrowserContextKeyedServiceFactory(
-          "UINetworkQualityEstimatorService",
-          BrowserContextDependencyManager::GetInstance()) {}
-
-UINetworkQualityEstimatorServiceFactory::
-    ~UINetworkQualityEstimatorServiceFactory() {}
-
-bool UINetworkQualityEstimatorServiceFactory::
-    ServiceIsCreatedWithBrowserContext() const {
-  // Initialize the UI network quality estimator service so it can
-  // read/write the prefs.
-  return true;
-}
-
-KeyedService* UINetworkQualityEstimatorServiceFactory::BuildServiceInstanceFor(
-    content::BrowserContext* context) const {
-  return new UINetworkQualityEstimatorService(
-      Profile::FromBrowserContext(context));
-}
-
-content::BrowserContext*
-UINetworkQualityEstimatorServiceFactory::GetBrowserContextToUse(
-    content::BrowserContext* context) const {
-  return chrome::GetBrowserContextOwnInstanceInIncognito(context);
-}
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h b/chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h
deleted file mode 100644
index 4fb6c48..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2016 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_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_FACTORY_H_
-#define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_FACTORY_H_
-
-#include "base/memory/singleton.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-
-class Profile;
-
-namespace content {
-class BrowserContext;
-}
-
-class UINetworkQualityEstimatorService;
-
-class UINetworkQualityEstimatorServiceFactory
-    : public BrowserContextKeyedServiceFactory {
- public:
-  static UINetworkQualityEstimatorService* GetForProfile(Profile* profile);
-
-  static UINetworkQualityEstimatorServiceFactory* GetInstance();
-
- private:
-  friend struct base::DefaultSingletonTraits<
-      UINetworkQualityEstimatorServiceFactory>;
-
-  UINetworkQualityEstimatorServiceFactory();
-  ~UINetworkQualityEstimatorServiceFactory() override;
-
-  // BrowserContextKeyedServiceFactory:
-  KeyedService* BuildServiceInstanceFor(
-      content::BrowserContext* context) const override;
-  content::BrowserContext* GetBrowserContextToUse(
-      content::BrowserContext* context) const override;
-
-  bool ServiceIsCreatedWithBrowserContext() const override;
-};
-
-#endif  // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_FACTORY_H_
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc b/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc
deleted file mode 100644
index 14307b1..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2016 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/net/nqe/ui_network_quality_estimator_service_test_util.h"
-
-#include "base/bind.h"
-#include "base/run_loop.h"
-#include "base/task/post_task.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/io_thread.h"
-#include "content/public/browser/browser_task_traits.h"
-#include "content/public/browser/browser_thread.h"
-#include "net/nqe/network_quality_estimator.h"
-#include "net/url_request/url_request_context.h"
-
-namespace nqe_test_util {
-
-namespace {
-
-// Reports |type| to all of NetworkQualityEstimator's
-// EffectiveConnectionTypeObservers.
-void OverrideEffectiveConnectionTypeOnIO(net::EffectiveConnectionType type,
-                                         IOThread* io_thread) {
-  net::NetworkQualityEstimator* network_quality_estimator =
-      io_thread->globals()->system_request_context->network_quality_estimator();
-  if (!network_quality_estimator)
-    return;
-  network_quality_estimator->ReportEffectiveConnectionTypeForTesting(type);
-}
-
-void OverrideRTTsAndWaitOnIO(base::TimeDelta rtt, IOThread* io_thread) {
-  net::NetworkQualityEstimator* network_quality_estimator =
-      io_thread->globals()->system_request_context->network_quality_estimator();
-  if (!network_quality_estimator)
-    return;
-  network_quality_estimator->ReportRTTsAndThroughputForTesting(rtt, rtt, -1);
-}
-
-}  // namespace
-
-void OverrideEffectiveConnectionTypeAndWait(net::EffectiveConnectionType type) {
-  // Block |run_loop| until OverrideEffectiveConnectionTypeOnIO has completed.
-  // Any UI tasks posted by calling OverrideEffectiveConnectionTypeOnIO will
-  // complete before the reply unblocks |run_loop|.
-  base::RunLoop run_loop;
-  base::PostTaskWithTraitsAndReply(
-      FROM_HERE, {content::BrowserThread::IO},
-      base::BindOnce(&OverrideEffectiveConnectionTypeOnIO, type,
-                     g_browser_process->io_thread()),
-      run_loop.QuitClosure());
-  run_loop.Run();
-}
-
-void OverrideRTTsAndWait(base::TimeDelta rtt) {
-  // Block |run_loop| until OverrideRTTsAndWaitOnIO has completed.
-  // Any UI tasks posted by calling OverrideRTTsAndWaitOnIO will complete before
-  // the reply unblocks |run_loop|.
-  base::RunLoop run_loop;
-  base::PostTaskWithTraitsAndReply(
-      FROM_HERE, {content::BrowserThread::IO},
-      base::BindOnce(&OverrideRTTsAndWaitOnIO, rtt,
-                     g_browser_process->io_thread()),
-      run_loop.QuitClosure());
-  run_loop.Run();
-}
-
-}  // namespace nqe_test_util
diff --git a/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.h b/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.h
deleted file mode 100644
index 35943ce..0000000
--- a/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2016 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_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_TEST_UTIL_H_
-#define CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_TEST_UTIL_H_
-
-#include "base/time/time.h"
-#include "net/nqe/effective_connection_type.h"
-
-namespace nqe_test_util {
-
-// Forces NetworkQualityEstimator to report |type| to all its
-// EffectiveConnectionTypeObservers.
-// This blocks execution on the calling thread until the IO task runs and
-// replies.
-void OverrideEffectiveConnectionTypeAndWait(net::EffectiveConnectionType type);
-
-// Forces NetworkQualityEstimator to report |rtt| to all its
-// RTTAndThroughputEstimatesObservers.
-// This blocks execution on the calling thread until the IO task runs and
-// replies.
-void OverrideRTTsAndWait(base::TimeDelta rtt);
-
-}  // namespace nqe_test_util
-
-#endif  // CHROME_BROWSER_NET_NQE_UI_NETWORK_QUALITY_ESTIMATOR_SERVICE_TEST_UTIL_H_
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index c6be13b..f308b91 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -32,7 +32,6 @@
 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
 #include "chrome/browser/net/prediction_options.h"
 #include "chrome/browser/net/profile_network_context_service.h"
 #include "chrome/browser/net/system_network_context_manager.h"
@@ -378,6 +377,9 @@
 // Deprecated 10/2018
 const char kReverseAutologinEnabled[] = "reverse_autologin.enabled";
 
+// Deprecated 11/2018.
+const char kNetworkQualities[] = "net.network_qualities";
+
 // Register prefs used only for migration (clearing or moving to a new key).
 void RegisterProfilePrefsForMigration(
     user_prefs::PrefRegistrySyncable* registry) {
@@ -403,6 +405,8 @@
   registry->RegisterBooleanPref(kSupervisedUserCreationAllowed, true);
 
   registry->RegisterBooleanPref(kReverseAutologinEnabled, true);
+
+  registry->RegisterDictionaryPref(kNetworkQualities, PrefRegistry::LOSSY_PREF);
 }
 
 }  // namespace
@@ -603,7 +607,6 @@
   syncer::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry);
   TemplateURLPrepopulateData::RegisterProfilePrefs(registry);
   translate::TranslatePrefs::RegisterProfilePrefs(registry);
-  UINetworkQualityEstimatorService::RegisterProfilePrefs(registry);
   ZeroSuggestProvider::RegisterProfilePrefs(registry);
 
 #if BUILDFLAG(ENABLE_EXTENSIONS)
@@ -862,4 +865,7 @@
 
   // Added 10/2018
   profile_prefs->ClearPref(kReverseAutologinEnabled);
+
+  // Added 11/2018.
+  profile_prefs->ClearPref(kNetworkQualities);
 }
diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
index 21ccdb1..5120f5b 100644
--- a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
+++ b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
@@ -41,7 +41,6 @@
 #include "chrome/browser/media/webrtc/webrtc_event_log_manager_keyed_service_factory.h"
 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h"
 #include "chrome/browser/metrics/desktop_session_duration/desktop_profile_session_durations_service_factory.h"
-#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
 #include "chrome/browser/password_manager/password_store_factory.h"
@@ -381,7 +380,6 @@
 #if defined(OS_WIN)
   TriggeredProfileResetterFactory::GetInstance();
 #endif
-  UINetworkQualityEstimatorServiceFactory::GetInstance();
   UnifiedConsentServiceFactory::GetInstance();
   UrlLanguageHistogramFactory::GetInstance();
 #if !defined(OS_ANDROID)