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