Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/url_loader_factory_getter.h" | 5 #include "content/browser/url_loader_factory_getter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/browser/appcache/appcache_url_loader_factory.h" | |
| 9 #include "content/browser/storage_partition_impl.h" | |
| 10 #include "content/common/network_service.mojom.h" | |
| 11 | |
| 8 | 12 |
| 9 namespace content { | 13 namespace content { |
| 10 | 14 |
| 11 URLLoaderFactoryGetter::URLLoaderFactoryGetter() {} | 15 URLLoaderFactoryGetter::URLLoaderFactoryGetter() {} |
| 12 | 16 |
| 13 void URLLoaderFactoryGetter::Initialize( | 17 void URLLoaderFactoryGetter::Initialize( |
| 14 mojom::URLLoaderFactoryPtr network_factory) { | 18 StoragePartitionImpl* partition) { |
| 19 mojom::URLLoaderFactoryPtr network_factory; | |
| 20 partition->network_context()->CreateURLLoaderFactory( | |
| 21 MakeRequest(&network_factory), 0); | |
| 22 | |
| 15 BrowserThread::PostTask( | 23 BrowserThread::PostTask( |
| 16 BrowserThread::IO, FROM_HERE, | 24 BrowserThread::IO, FROM_HERE, |
| 17 base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this, | 25 base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this, |
| 18 network_factory.PassInterface())); | 26 network_factory.PassInterface(), |
| 27 scoped_refptr<ChromeAppCacheService>( | |
| 28 partition->GetAppCacheService()))); | |
|
jam
2017/05/18 14:16:14
nit: indentation
ananta
2017/05/18 19:13:52
Done.
| |
| 19 } | 29 } |
| 20 | 30 |
| 21 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() { | 31 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 23 return test_factory_.is_bound() ? &test_factory_ : &network_factory_; | 33 return test_factory_.is_bound() ? &test_factory_ : &network_factory_; |
| 24 } | 34 } |
| 25 | 35 |
| 26 void URLLoaderFactoryGetter::SetNetworkFactoryForTesting( | 36 void URLLoaderFactoryGetter::SetNetworkFactoryForTesting( |
| 27 mojom::URLLoaderFactoryPtr test_factory) { | 37 mojom::URLLoaderFactoryPtr test_factory) { |
| 28 // Since the URLLoaderFactory pointers are bound on the IO thread, and this | 38 // 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 | 39 // 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. | 40 // old value. As such this class keeps two separate pointers, one for test. |
| 31 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
| 32 BrowserThread::IO, FROM_HERE, | 42 BrowserThread::IO, FROM_HERE, |
| 33 base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread, | 43 base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread, |
| 34 this, test_factory.PassInterface())); | 44 this, test_factory.PassInterface())); |
| 35 } | 45 } |
| 36 | 46 |
| 47 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetAppCacheFactory() { | |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 49 return &appcache_factory_; | |
| 50 } | |
| 51 | |
| 37 URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {} | 52 URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {} |
| 38 | 53 |
| 39 void URLLoaderFactoryGetter::InitializeOnIOThread( | 54 void URLLoaderFactoryGetter::InitializeOnIOThread( |
| 40 mojom::URLLoaderFactoryPtrInfo network_factory) { | 55 mojom::URLLoaderFactoryPtrInfo network_factory, |
| 56 scoped_refptr<ChromeAppCacheService> appcache_service) { | |
| 41 network_factory_.Bind(std::move(network_factory)); | 57 network_factory_.Bind(std::move(network_factory)); |
| 58 | |
| 59 AppCacheURLLoaderFactory::CreateURLLoaderFactory( | |
| 60 mojo::MakeRequest(&appcache_factory_), appcache_service.get(), this); | |
| 42 } | 61 } |
| 43 | 62 |
| 44 void URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread( | 63 void URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread( |
| 45 mojom::URLLoaderFactoryPtrInfo test_factory) { | 64 mojom::URLLoaderFactoryPtrInfo test_factory) { |
| 46 test_factory_.Bind(std::move(test_factory)); | 65 test_factory_.Bind(std::move(test_factory)); |
| 47 } | 66 } |
| 48 | 67 |
| 49 } // namespace content | 68 } // namespace content |
| OLD | NEW |