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