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_APPCACHE_APPCACHE_URL_LOADER_FACTORY_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_FACTORY_H_ |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_FACTORY_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_FACTORY_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "content/common/url_loader_factory.mojom.h" | 9 #include "content/common/url_loader_factory.mojom.h" |
10 #include "mojo/public/cpp/bindings/strong_binding_set.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 class ChromeAppCacheService; | 14 |
| 15 class AppCacheJob; |
| 16 class AppCacheServiceImpl; |
15 class URLLoaderFactoryGetter; | 17 class URLLoaderFactoryGetter; |
16 | 18 |
17 // Implements the URLLoaderFactory mojom for AppCache requests. | 19 // Implements the URLLoaderFactory mojom for AppCache requests. |
18 class AppCacheURLLoaderFactory : public mojom::URLLoaderFactory { | 20 class AppCacheURLLoaderFactory : public mojom::URLLoaderFactory { |
19 public: | 21 public: |
20 ~AppCacheURLLoaderFactory() override; | 22 ~AppCacheURLLoaderFactory() override; |
21 | 23 |
22 // Factory function to create an instance of the factory. | 24 // Factory function to create an instance of the factory. |
23 // The |appcache_service| parameter is used to query the underlying | 25 // 1. The |factory_getter| parameter is used to query the network service |
24 // AppCacheStorage instance to check if we can service requests from the | 26 // to pass network requests to. |
25 // AppCache. We pass unhandled requests to the network service retrieved from | 27 // 2. The |url_loader_job| is valid only for navigation requests. |
26 // the |factory_getter|. | 28 // Returns a URLLoaderFactoryPtr instance which controls the lifetime of the |
27 static void CreateURLLoaderFactory(mojom::URLLoaderFactoryRequest request, | 29 // factory. |
28 ChromeAppCacheService* appcache_service, | 30 static mojom::URLLoaderFactoryPtr |
29 URLLoaderFactoryGetter* factory_getter); | 31 CreateURLLoaderFactory(URLLoaderFactoryGetter* factory_getter, |
| 32 AppCacheJob* url_loader_job); |
30 | 33 |
31 // mojom::URLLoaderFactory implementation. | 34 // mojom::URLLoaderFactory implementation. |
32 void CreateLoaderAndStart( | 35 void CreateLoaderAndStart( |
33 mojom::URLLoaderAssociatedRequest url_loader_request, | 36 mojom::URLLoaderAssociatedRequest url_loader_request, |
34 int32_t routing_id, | 37 int32_t routing_id, |
35 int32_t request_id, | 38 int32_t request_id, |
36 uint32_t options, | 39 uint32_t options, |
37 const ResourceRequest& request, | 40 const ResourceRequest& request, |
38 mojom::URLLoaderClientPtr client) override; | 41 mojom::URLLoaderClientPtr client) override; |
39 void SyncLoad(int32_t routing_id, | 42 void SyncLoad(int32_t routing_id, |
40 int32_t request_id, | 43 int32_t request_id, |
41 const ResourceRequest& request, | 44 const ResourceRequest& request, |
42 SyncLoadCallback callback) override; | 45 SyncLoadCallback callback) override; |
43 | 46 |
44 private: | 47 private: |
45 AppCacheURLLoaderFactory(ChromeAppCacheService* appcache_service, | 48 AppCacheURLLoaderFactory(mojom::URLLoaderFactoryRequest request, |
46 URLLoaderFactoryGetter* factory_getter); | 49 URLLoaderFactoryGetter* factory_getter, |
| 50 AppCacheJob* url_loader_job); |
47 | 51 |
48 // Used to query AppCacheStorage to see if a request can be served out of the | 52 void OnConnectionError(); |
49 /// AppCache. | 53 |
50 scoped_refptr<ChromeAppCacheService> appcache_service_; | 54 // Mojo binding. |
| 55 mojo::Binding<mojom::URLLoaderFactory> binding_; |
51 | 56 |
52 // Used to retrieve the network service factory to pass unhandled requests to | 57 // Used to retrieve the network service factory to pass unhandled requests to |
53 // the network service. | 58 // the network service. |
54 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; | 59 scoped_refptr<URLLoaderFactoryGetter> factory_getter_; |
55 | 60 |
56 mojo::StrongBindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; | 61 // Only set for navigation requests. We release ownership when the client |
| 62 // binds to us. |
| 63 std::unique_ptr<AppCacheJob> url_loader_job_; |
57 | 64 |
58 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderFactory); | 65 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderFactory); |
59 }; | 66 }; |
60 | 67 |
61 } // namespace content | 68 } // namespace content |
62 | 69 |
63 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_FACTORY_H_ | 70 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_FACTORY_H_ |
OLD | NEW |