| 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" | 8 #include "content/browser/storage_partition_impl.h" |
| 10 #include "content/common/network_service.mojom.h" | 9 #include "content/common/network_service.mojom.h" |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 | 12 |
| 14 URLLoaderFactoryGetter::URLLoaderFactoryGetter() {} | 13 URLLoaderFactoryGetter::URLLoaderFactoryGetter() {} |
| 15 | 14 |
| 16 void URLLoaderFactoryGetter::Initialize(StoragePartitionImpl* partition) { | 15 void URLLoaderFactoryGetter::Initialize(StoragePartitionImpl* partition) { |
| 17 mojom::URLLoaderFactoryPtr network_factory; | 16 mojom::URLLoaderFactoryPtr network_factory; |
| 18 partition->network_context()->CreateURLLoaderFactory( | 17 partition->network_context()->CreateURLLoaderFactory( |
| 19 MakeRequest(&network_factory), 0); | 18 MakeRequest(&network_factory), 0); |
| 20 | 19 |
| 21 mojom::URLLoaderFactoryPtr blob_factory = | 20 mojom::URLLoaderFactoryPtr blob_factory = |
| 22 partition->GetBlobURLLoaderFactory()->CreateFactory(); | 21 partition->GetBlobURLLoaderFactory()->CreateFactory(); |
| 23 | 22 |
| 24 BrowserThread::PostTask( | 23 BrowserThread::PostTask( |
| 25 BrowserThread::IO, FROM_HERE, | 24 BrowserThread::IO, FROM_HERE, |
| 26 base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this, | 25 base::BindOnce(&URLLoaderFactoryGetter::InitializeOnIOThread, this, |
| 27 network_factory.PassInterface(), | 26 network_factory.PassInterface(), |
| 28 blob_factory.PassInterface(), | 27 blob_factory.PassInterface())); |
| 29 scoped_refptr<ChromeAppCacheService>( | |
| 30 partition->GetAppCacheService()))); | |
| 31 } | 28 } |
| 32 | 29 |
| 33 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() { | 30 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetNetworkFactory() { |
| 34 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 31 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 35 return test_factory_.is_bound() ? &test_factory_ : &network_factory_; | 32 return test_factory_.is_bound() ? &test_factory_ : &network_factory_; |
| 36 } | 33 } |
| 37 | 34 |
| 38 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetBlobFactory() { | 35 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetBlobFactory() { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 36 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 40 return &blob_factory_; | 37 return &blob_factory_; |
| 41 } | 38 } |
| 42 | 39 |
| 43 void URLLoaderFactoryGetter::SetNetworkFactoryForTesting( | 40 void URLLoaderFactoryGetter::SetNetworkFactoryForTesting( |
| 44 mojom::URLLoaderFactoryPtr test_factory) { | 41 mojom::URLLoaderFactoryPtr test_factory) { |
| 45 // Since the URLLoaderFactory pointers are bound on the IO thread, and this | 42 // Since the URLLoaderFactory pointers are bound on the IO thread, and this |
| 46 // method is called on the UI thread, we are not able to unbind and return the | 43 // method is called on the UI thread, we are not able to unbind and return the |
| 47 // old value. As such this class keeps two separate pointers, one for test. | 44 // old value. As such this class keeps two separate pointers, one for test. |
| 48 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 49 BrowserThread::IO, FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
| 50 base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread, | 47 base::BindOnce(&URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread, |
| 51 this, test_factory.PassInterface())); | 48 this, test_factory.PassInterface())); |
| 52 } | 49 } |
| 53 | 50 |
| 54 mojom::URLLoaderFactoryPtr* URLLoaderFactoryGetter::GetAppCacheFactory() { | |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 56 return &appcache_factory_; | |
| 57 } | |
| 58 | |
| 59 URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {} | 51 URLLoaderFactoryGetter::~URLLoaderFactoryGetter() {} |
| 60 | 52 |
| 61 void URLLoaderFactoryGetter::InitializeOnIOThread( | 53 void URLLoaderFactoryGetter::InitializeOnIOThread( |
| 62 mojom::URLLoaderFactoryPtrInfo network_factory, | 54 mojom::URLLoaderFactoryPtrInfo network_factory, |
| 63 mojom::URLLoaderFactoryPtrInfo blob_factory, | 55 mojom::URLLoaderFactoryPtrInfo blob_factory) { |
| 64 scoped_refptr<ChromeAppCacheService> appcache_service) { | |
| 65 network_factory_.Bind(std::move(network_factory)); | 56 network_factory_.Bind(std::move(network_factory)); |
| 66 blob_factory_.Bind(std::move(blob_factory)); | 57 blob_factory_.Bind(std::move(blob_factory)); |
| 67 | |
| 68 AppCacheURLLoaderFactory::CreateURLLoaderFactory( | |
| 69 mojo::MakeRequest(&appcache_factory_), appcache_service.get(), this); | |
| 70 } | 58 } |
| 71 | 59 |
| 72 void URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread( | 60 void URLLoaderFactoryGetter::SetTestNetworkFactoryOnIOThread( |
| 73 mojom::URLLoaderFactoryPtrInfo test_factory) { | 61 mojom::URLLoaderFactoryPtrInfo test_factory) { |
| 74 test_factory_.Bind(std::move(test_factory)); | 62 test_factory_.Bind(std::move(test_factory)); |
| 75 } | 63 } |
| 76 | 64 |
| 77 } // namespace content | 65 } // namespace content |
| OLD | NEW |