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

Unified Diff: content/browser/url_loader_factory_getter.cc

Issue 2874163004: Add support in the network service for different contexts. (Closed)
Patch Set: update after r471804 Created 3 years, 7 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: content/browser/url_loader_factory_getter.cc
diff --git a/content/browser/url_loader_factory_getter.cc b/content/browser/url_loader_factory_getter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..406368e372d5aff3e640953f38916dea2d6fd034
--- /dev/null
+++ b/content/browser/url_loader_factory_getter.cc
@@ -0,0 +1,49 @@
+// 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 "content/browser/url_loader_factory_getter.h"
+
+#include "base/bind.h"
+
+namespace content {
+
+URLLoaderFactoryGetter::URLLoaderFactoryGetter() {}
+
+URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {}
+
+void URLLoaderFactoryGetter::Initialize(
+ mojom::URLLoaderFactoryPtr network_factory) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this,
+ std::move(network_factory.PassInterface())));
+}
+
+mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
scottmg 2017/05/16 03:53:43 DCHECK_CURRENTLY_ON(BrowserThread::IO);
jam 2017/05/16 04:08:40 Done.
+ return test_factory_.is_bound() ? &test_factory_ : &network_factory_;
+}
+
+void URLLoaderFactoryGetter::SetNetworkFactoryForTesting(
+ mojom::URLLoaderFactoryPtr test_factory) {
+ // Since the URLLoaderFactory pointers are bound on the IO thread, and this
+ // method is called on the UI thread, we are not able to unbind and return the
+ // old value. As such this class keeps two separate pointers, one for test.
+ BrowserThread::PostTask(
scottmg 2017/05/16 03:53:43 I was worried at first about this racing with the
jam 2017/05/16 04:08:40 Yep exactly :)
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread,
+ this, std::move(test_factory.PassInterface())));
+}
+
+void URLLoaderFactoryGetter::InitializeOnIOThread(
+ mojom::URLLoaderFactoryPtrInfo network_factory) {
+ network_factory_.Bind(std::move(network_factory));
+}
+
+void URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread(
+ mojom::URLLoaderFactoryPtrInfo test_factory) {
+ test_factory_.Bind(std::move(test_factory));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698