| 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 class StoragePartitionImpl; |
| 18 |
| 16 // Holds on to URLLoaderFactory for a given StoragePartition and allows code | 19 // 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 | 20 // running on the IO thread to access them. Note these are the factories used by |
| 18 // the browser process for frame requests. | 21 // the browser process for frame requests. |
| 19 class URLLoaderFactoryGetter | 22 class URLLoaderFactoryGetter |
| 20 : public base::RefCountedThreadSafe<URLLoaderFactoryGetter, | 23 : public base::RefCountedThreadSafe<URLLoaderFactoryGetter, |
| 21 BrowserThread::DeleteOnIOThread> { | 24 BrowserThread::DeleteOnIOThread> { |
| 22 public: | 25 public: |
| 23 URLLoaderFactoryGetter(); | 26 URLLoaderFactoryGetter(); |
| 24 | 27 |
| 25 // Initializes this object on the UI thread. | 28 // Initializes this object on the UI thread. The |partition| is used to |
| 26 void Initialize(mojom::URLLoaderFactoryPtr network_factory); | 29 // initialize the URLLoaderFactories for the network service and AppCache. |
| 30 void Initialize(StoragePartitionImpl* partition); |
| 27 | 31 |
| 28 // Called on the IO thread to get the URLLoaderFactory to the network service. | 32 // Called on the IO thread to get the URLLoaderFactory to the network service. |
| 29 // The pointer shouldn't be cached. | 33 // The pointer shouldn't be cached. |
| 30 mojom::URLLoaderFactoryPtr* GetNetworkFactory(); | 34 mojom::URLLoaderFactoryPtr* GetNetworkFactory(); |
| 31 | 35 |
| 32 // Overrides the network URLLoaderFactory for subsequent requests. Passing a | 36 // Overrides the network URLLoaderFactory for subsequent requests. Passing a |
| 33 // null pointer will restore the default behavior. | 37 // null pointer will restore the default behavior. |
| 34 // This is called on the UI thread. | 38 // This is called on the UI thread. |
| 35 CONTENT_EXPORT void SetNetworkFactoryForTesting( | 39 CONTENT_EXPORT void SetNetworkFactoryForTesting( |
| 36 mojom::URLLoaderFactoryPtr test_factory); | 40 mojom::URLLoaderFactoryPtr test_factory); |
| 37 | 41 |
| 42 // Called on the IO thread to get the URLLoaderFactory for AppCache. The |
| 43 // pointer should not be cached. |
| 44 mojom::URLLoaderFactoryPtr* GetAppCacheFactory(); |
| 45 |
| 38 private: | 46 private: |
| 39 friend class base::DeleteHelper<URLLoaderFactoryGetter>; | 47 friend class base::DeleteHelper<URLLoaderFactoryGetter>; |
| 40 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; | 48 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; |
| 41 | 49 |
| 42 CONTENT_EXPORT ~URLLoaderFactoryGetter(); | 50 CONTENT_EXPORT ~URLLoaderFactoryGetter(); |
| 43 void InitializeOnIOThread(mojom::URLLoaderFactoryPtrInfo network_factory); | 51 void InitializeOnIOThread( |
| 52 mojom::URLLoaderFactoryPtrInfo network_factory, |
| 53 scoped_refptr<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 |