OLD | NEW |
| (Empty) |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_NETWORK_SERVICE_HANDLER_ | |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_NETWORK_SERVICE_HANDLER_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "content/browser/appcache/appcache_service_impl.h" | |
12 #include "content/browser/appcache/appcache_storage.h" | |
13 #include "content/common/content_export.h" | |
14 #include "content/common/url_loader_factory.mojom.h" | |
15 #include "content/public/common/resource_type.h" | |
16 | |
17 namespace content { | |
18 class AppCacheEntry; | |
19 class AppCacheHost; | |
20 class AppCacheNavigationHandleCore; | |
21 class AppCacheStorage; | |
22 class ResourceContext; | |
23 struct ResourceRequest; | |
24 | |
25 // This class is instantiated during navigation, to check if the URL being | |
26 // navigated to can be served out of the AppCache. | |
27 // The AppCacheRequestHandler class provides this functionality as well. | |
28 // However it is tightly coupled with the underlying job and the lifetime | |
29 // of that class gets a touch complicated. The AppCacheRequestHandler is | |
30 // generally associated with a request and it dies when the request goes away. | |
31 // For this case, we are just checking if the URL can be served out of the | |
32 // cache. If yes, then the plan is to create a URLLoaderFactory which can serve | |
33 // URL requests from the cache. | |
34 // TODO(ananta) | |
35 // Look into whether we can get rid of this class when the overall picture of | |
36 // how AppCache interacts with the network service gets clearer. | |
37 class CONTENT_EXPORT AppCacheNetworkServiceHandler | |
38 : public AppCacheStorage::Delegate { | |
39 public: | |
40 AppCacheNetworkServiceHandler( | |
41 std::unique_ptr<ResourceRequest> resource_request, | |
42 AppCacheNavigationHandleCore* navigation_handle_core, | |
43 base::Callback<void(mojom::URLLoaderFactoryPtrInfo, | |
44 std::unique_ptr<ResourceRequest>)> callback); | |
45 | |
46 ~AppCacheNetworkServiceHandler() override; | |
47 | |
48 // Called to start the process of looking up the URL in the AppCache | |
49 // database, | |
50 void Start(); | |
51 | |
52 // AppCacheStorage::Delegate methods | |
53 // The AppCacheNetworkServiceHandler instance is deleted on return from this | |
54 // function. | |
55 void OnMainResponseFound(const GURL& url, | |
56 const AppCacheEntry& entry, | |
57 const GURL& fallback_url, | |
58 const AppCacheEntry& fallback_entry, | |
59 int64_t cache_id, | |
60 int64_t group_id, | |
61 const GURL& mainfest_url) override; | |
62 | |
63 private: | |
64 std::unique_ptr<ResourceRequest> resource_request_; | |
65 | |
66 // Callback to invoke when we make a determination on whether the request is | |
67 // to be served from the cache or network. | |
68 base::Callback<void(mojom::URLLoaderFactoryPtrInfo, | |
69 std::unique_ptr<ResourceRequest>)> callback_; | |
70 | |
71 AppCacheStorage* storage_; | |
72 | |
73 // The precreated host pointer from the AppCacheNavigationHandleCore class. | |
74 // The ownership of this pointer stays with the AppCacheNavigationHandleCore | |
75 // class. | |
76 AppCacheHost* host_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(AppCacheNetworkServiceHandler); | |
79 }; | |
80 | |
81 } // namespace content | |
82 | |
83 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_NETWORK_SERVICE_HANDLER_ | |
OLD | NEW |