Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1105)

Unified Diff: chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc

Issue 2103323007: Exposing NQE on the Browser UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc
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
new file mode 100644
index 0000000000000000000000000000000000000000..acfbd96288454c3a89f3512235ba304d768370ef
--- /dev/null
+++ b/chrome/browser/net/nqe/ui_network_quality_estimator_service_test_util.cc
@@ -0,0 +1,47 @@
+// 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 "chrome/browser/browser_process.h"
+#include "chrome/browser/io_thread.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace nqe_test_util {
+
+namespace {
+
+// Reports |type| to all of NetworkQualityEstimator's
+// EffectiveConnectionTypeObservers.
+void OverrideEffectiveConnectionTypeOnIO(
+ net::NetworkQualityEstimator::EffectiveConnectionType type,
+ IOThread* io_thread) {
+ if (!io_thread->globals()->network_quality_estimator)
+ return;
+ net::NetworkQualityEstimator* network_quality_estimator =
+ io_thread->globals()->network_quality_estimator.get();
+ if (!network_quality_estimator)
+ return;
+ network_quality_estimator->ReportEffectiveConnectionTypeForTesting(type);
+}
+
+} // namespace
+
+void OverrideEffectiveConnectionTypeAndWait(
+ net::NetworkQualityEstimator::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;
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&OverrideEffectiveConnectionTypeOnIO, type,
+ g_browser_process->io_thread()),
+ run_loop.QuitClosure());
+ run_loop.Run();
+}
+
+} // namespace nqe_test_util

Powered by Google App Engine
This is Rietveld 408576698