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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/url_loader_factory_getter.h"
6
7 #include "base/bind.h"
8
9 namespace content {
10
11 URLLoaderFactoryGetter::URLLoaderFactoryGetter() {}
12
13 void URLLoaderFactoryGetter::Initialize(
14 mojom::URLLoaderFactoryPtr network_factory) {
15 BrowserThread::PostTask(
16 BrowserThread::IO, FROM_HERE,
17 base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this,
18 network_factory.PassInterface()));
19 }
20
21 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() {
22 DCHECK_CURRENTLY_ON(BrowserThread::IO);
23 return test_factory_.is_bound() ? &test_factory_ : &network_factory_;
24 }
25
26 void URLLoaderFactoryGetter::SetNetworkFactoryForTesting(
27 mojom::URLLoaderFactoryPtr test_factory) {
28 // Since the URLLoaderFactory pointers are bound on the IO thread, and this
29 // method is called on the UI thread, we are not able to unbind and return the
30 // old value. As such this class keeps two separate pointers, one for test.
31 BrowserThread::PostTask(
32 BrowserThread::IO, FROM_HERE,
33 base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread,
34 this, test_factory.PassInterface()));
35 }
36
37 URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {}
38
39 void URLLoaderFactoryGetter::InitializeOnIOThread(
40 mojom::URLLoaderFactoryPtrInfo network_factory) {
41 network_factory_.Bind(std::move(network_factory));
42 }
43
44 void URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread(
45 mojom::URLLoaderFactoryPtrInfo test_factory) {
46 test_factory_.Bind(std::move(test_factory));
47 }
48
49 } // namespace content
OLDNEW
« 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