| 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 #ifndef CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ | 5 #ifndef CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ |
| 6 #define CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ | 6 #define CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 11 #include "content/common/url_loader_factory.mojom.h" | 11 #include "content/common/url_loader_factory.mojom.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class ChromeAppCacheService; |
| 17 |
| 16 // Holds on to URLLoaderFactory for a given StoragePartition and allows code | 18 // Holds on to URLLoaderFactory for a given StoragePartition and allows code |
| 17 // running on the IO thread to access them. Note these are the factories used by | 19 // running on the IO thread to access them. Note these are the factories used by |
| 18 // the browser process for frame requests. | 20 // the browser process for frame requests. |
| 19 class URLLoaderFactoryGetter | 21 class URLLoaderFactoryGetter |
| 20 : public base::RefCountedThreadSafe<URLLoaderFactoryGetter, | 22 : public base::RefCountedThreadSafe<URLLoaderFactoryGetter, |
| 21 BrowserThread::DeleteOnIOThread> { | 23 BrowserThread::DeleteOnIOThread> { |
| 22 public: | 24 public: |
| 23 URLLoaderFactoryGetter(); | 25 URLLoaderFactoryGetter(); |
| 24 | 26 |
| 25 // Initializes this object on the UI thread. | 27 // Initializes this object on the UI thread. The |appcache_service| |
| 26 void Initialize(mojom::URLLoaderFactoryPtr network_factory); | 28 // parameter is used to initialize the AppCache URLLoaderFactory. This is |
| 29 // owned by the storage partition. |
| 30 void Initialize(mojom::URLLoaderFactoryPtr network_factory, |
| 31 ChromeAppCacheService* appcache_service); |
| 27 | 32 |
| 28 // Called on the IO thread to get the URLLoaderFactory to the network service. | 33 // Called on the IO thread to get the URLLoaderFactory to the network service. |
| 29 // The pointer shouldn't be cached. | 34 // The pointer shouldn't be cached. |
| 30 mojom::URLLoaderFactoryPtr* GetNetworkFactory(); | 35 mojom::URLLoaderFactoryPtr* GetNetworkFactory(); |
| 31 | 36 |
| 32 // Overrides the network URLLoaderFactory for subsequent requests. Passing a | 37 // Overrides the network URLLoaderFactory for subsequent requests. Passing a |
| 33 // null pointer will restore the default behavior. | 38 // null pointer will restore the default behavior. |
| 34 // This is called on the UI thread. | 39 // This is called on the UI thread. |
| 35 CONTENT_EXPORT void SetNetworkFactoryForTesting( | 40 CONTENT_EXPORT void SetNetworkFactoryForTesting( |
| 36 mojom::URLLoaderFactoryPtr test_factory); | 41 mojom::URLLoaderFactoryPtr test_factory); |
| 37 | 42 |
| 43 // Called on the IO thread to get the URLLoaderFactory for AppCache. The |
| 44 // pointer should not be cached. |
| 45 mojom::URLLoaderFactoryPtr* GetAppCacheFactory(); |
| 46 |
| 38 private: | 47 private: |
| 39 friend class base::DeleteHelper<URLLoaderFactoryGetter>; | 48 friend class base::DeleteHelper<URLLoaderFactoryGetter>; |
| 40 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; | 49 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 41 | 50 |
| 42 CONTENT_EXPORT ~URLLoaderFactoryGetter(); | 51 CONTENT_EXPORT ~URLLoaderFactoryGetter(); |
| 43 void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory); | 52 void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory, |
| 53 ChromeAppCacheService* appcache_service); |
| 44 void SetTestNetworkFactoryOnIOThread( | 54 void SetTestNetworkFactoryOnIOThread( |
| 45 mojom::URLLoaderFactoryPtrInfo test_factory); | 55 mojom::URLLoaderFactoryPtrInfo test_factory); |
| 46 | 56 |
| 47 // Only accessed on IO thread. | 57 // Only accessed on IO thread. |
| 48 mojom::URLLoaderFactoryPtr network_factory_; | 58 mojom::URLLoaderFactoryPtr network_factory_; |
| 49 mojom::URLLoaderFactoryPtr test_factory_; | 59 mojom::URLLoaderFactoryPtr test_factory_; |
| 60 mojom::URLLoaderFactoryPtr appcache_factory_; |
| 50 | 61 |
| 51 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter); | 62 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryGetter); |
| 52 }; | 63 }; |
| 53 | 64 |
| 54 } // namespace content | 65 } // namespace content |
| 55 | 66 |
| 56 #endif // CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ | 67 #endif // CONTENT_BROWSER_URL_LOADER_FACTORY_GETTER_H_ |
| OLD | NEW |