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

Unified Diff: content/browser/url_loader_factory_getter.cc

Issue 2874163004: Add support in the network service for different contexts. (Closed)
Patch Set: review comment and clang fixes 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
« no previous file with comments | « content/browser/url_loader_factory_getter.h ('k') | content/browser/webui/web_ui_url_loader_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..be9038340184bd980f2be19d987daf5bcc2833f2
--- /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() {}
+
+void URLLoaderFactoryGetter::Initialize(
+ mojom::URLLoaderFactoryPtr network_factory) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this,
+ network_factory.PassInterface()));
+}
+
+mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ 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(
+ BrowserThread::IO, FROM_HERE,
+ base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread,
+ this, test_factory.PassInterface()));
+}
+
+URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {}
+
+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
« no previous file with comments | « content/browser/url_loader_factory_getter.h ('k') | content/browser/webui/web_ui_url_loader_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698