| OLD | NEW |
| (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 |
| OLD | NEW |