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