Chromium Code Reviews| 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 URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {} | |
| 14 | |
| 15 void URLLoaderFactoryGetter::Initialize( | |
| 16 mojom::URLLoaderFactoryPtr network_factory) { | |
| 17 BrowserThread::PostTask( | |
| 18 BrowserThread::IO, FROM_HERE, | |
| 19 base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this, | |
| 20 std::move(network_factory.PassInterface()))); | |
| 21 } | |
| 22 | |
| 23 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() { | |
| 24 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.
| |
| 25 return test_factory_.is_bound() ? &test_factory_ : &network_factory_; | |
| 26 } | |
| 27 | |
| 28 void URLLoaderFactoryGetter::SetNetworkFactoryForTesting( | |
| 29 mojom::URLLoaderFactoryPtr test_factory) { | |
| 30 // Since the URLLoaderFactory pointers are bound on the IO thread, and this | |
| 31 // method is called on the UI thread, we are not able to unbind and return the | |
| 32 // old value. As such this class keeps two separate pointers, one for test. | |
| 33 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 :)
| |
| 34 BrowserThread::IO, FROM_HERE, | |
| 35 base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread, | |
| 36 this, std::move(test_factory.PassInterface()))); | |
| 37 } | |
| 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 |