OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
16 #include "content/browser/appcache/appcache_entry.h" | 16 #include "content/browser/appcache/appcache_entry.h" |
17 #include "content/browser/appcache/appcache_host.h" | 17 #include "content/browser/appcache/appcache_host.h" |
18 #include "content/browser/appcache/appcache_service_impl.h" | 18 #include "content/browser/appcache/appcache_service_impl.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "content/public/common/resource_type.h" | 20 #include "content/public/common/resource_type.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 class NetworkDelegate; | 23 class NetworkDelegate; |
24 class URLRequest; | 24 class URLRequest; |
25 } // namespace net | 25 } // namespace net |
26 | 26 |
27 namespace content { | 27 namespace content { |
| 28 class AppCacheJob; |
28 class AppCacheRequest; | 29 class AppCacheRequest; |
29 class AppCacheRequestHandlerTest; | 30 class AppCacheRequestHandlerTest; |
30 class AppCacheURLRequestJob; | 31 class AppCacheURLRequestJob; |
31 | 32 |
32 // An instance is created for each net::URLRequest. The instance survives all | 33 // An instance is created for each net::URLRequest. The instance survives all |
33 // http transactions involved in the processing of its net::URLRequest, and is | 34 // http transactions involved in the processing of its net::URLRequest, and is |
34 // given the opportunity to hijack the request along the way. Callers | 35 // given the opportunity to hijack the request along the way. Callers |
35 // should use AppCacheHost::CreateRequestHandler to manufacture instances | 36 // should use AppCacheHost::CreateRequestHandler to manufacture instances |
36 // that can retrieve resources for a particular host. | 37 // that can retrieve resources for a particular host. |
37 class CONTENT_EXPORT AppCacheRequestHandler | 38 class CONTENT_EXPORT AppCacheRequestHandler |
38 : public base::SupportsUserData::Data, | 39 : public base::SupportsUserData::Data, |
39 public AppCacheHost::Observer, | 40 public AppCacheHost::Observer, |
40 public AppCacheServiceImpl::Observer, | 41 public AppCacheServiceImpl::Observer, |
41 public AppCacheStorage::Delegate { | 42 public AppCacheStorage::Delegate { |
42 public: | 43 public: |
43 ~AppCacheRequestHandler() override; | 44 ~AppCacheRequestHandler() override; |
44 | 45 |
45 // These are called on each request intercept opportunity. | 46 // These are called on each request intercept opportunity. |
46 AppCacheURLRequestJob* MaybeLoadResource( | 47 AppCacheJob* MaybeLoadResource(net::NetworkDelegate* network_delegate); |
47 net::NetworkDelegate* network_delegate); | 48 AppCacheJob* MaybeLoadFallbackForRedirect( |
48 AppCacheURLRequestJob* MaybeLoadFallbackForRedirect( | |
49 net::NetworkDelegate* network_delegate, | 49 net::NetworkDelegate* network_delegate, |
50 const GURL& location); | 50 const GURL& location); |
51 AppCacheURLRequestJob* MaybeLoadFallbackForResponse( | 51 AppCacheJob* MaybeLoadFallbackForResponse( |
52 net::NetworkDelegate* network_delegate); | 52 net::NetworkDelegate* network_delegate); |
53 | 53 |
54 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); | 54 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); |
55 | 55 |
56 // Methods to support cross site navigations. | 56 // Methods to support cross site navigations. |
57 void PrepareForCrossSiteTransfer(int old_process_id); | 57 void PrepareForCrossSiteTransfer(int old_process_id); |
58 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); | 58 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); |
59 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); | 59 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); |
60 | 60 |
61 // Useful for detecting storage partition mismatches in the context | 61 // Useful for detecting storage partition mismatches in the context |
(...skipping 29 matching lines...) Expand all Loading... |
91 const GURL& manifest_url, | 91 const GURL& manifest_url, |
92 bool is_fallback, | 92 bool is_fallback, |
93 const GURL& namespace_entry_url); | 93 const GURL& namespace_entry_url); |
94 void DeliverNetworkResponse(); | 94 void DeliverNetworkResponse(); |
95 void DeliverErrorResponse(); | 95 void DeliverErrorResponse(); |
96 | 96 |
97 // Called just before the request is restarted. Grabs the reason for | 97 // Called just before the request is restarted. Grabs the reason for |
98 // restarting, so can correctly continue to handle the request. | 98 // restarting, so can correctly continue to handle the request. |
99 void OnPrepareToRestart(); | 99 void OnPrepareToRestart(); |
100 | 100 |
101 // Helper method to create an AppCacheURLRequestJob and populate job_. | 101 // Helper method to create an AppCacheJob and populate job_. |
102 // Caller takes ownership of returned value. | 102 // Caller takes ownership of returned value. |
103 std::unique_ptr<AppCacheURLRequestJob> CreateJob( | 103 std::unique_ptr<AppCacheJob> CreateJob( |
104 net::NetworkDelegate* network_delegate); | 104 net::NetworkDelegate* network_delegate); |
105 | 105 |
106 // Helper to retrieve a pointer to the storage object. | 106 // Helper to retrieve a pointer to the storage object. |
107 AppCacheStorage* storage() const; | 107 AppCacheStorage* storage() const; |
108 | 108 |
109 bool is_main_resource() const { | 109 bool is_main_resource() const { |
110 return IsMainResourceType(resource_type_); | 110 return IsMainResourceType(resource_type_); |
111 } | 111 } |
112 | 112 |
113 // Main-resource loading ------------------------------------- | 113 // Main-resource loading ------------------------------------- |
114 // Frame and SharedWorker main resources are handled here. | 114 // Frame and SharedWorker main resources are handled here. |
115 | 115 |
116 std::unique_ptr<AppCacheURLRequestJob> MaybeLoadMainResource( | 116 std::unique_ptr<AppCacheJob> MaybeLoadMainResource( |
117 net::NetworkDelegate* network_delegate); | 117 net::NetworkDelegate* network_delegate); |
118 | 118 |
119 // AppCacheStorage::Delegate methods | 119 // AppCacheStorage::Delegate methods |
120 void OnMainResponseFound(const GURL& url, | 120 void OnMainResponseFound(const GURL& url, |
121 const AppCacheEntry& entry, | 121 const AppCacheEntry& entry, |
122 const GURL& fallback_url, | 122 const GURL& fallback_url, |
123 const AppCacheEntry& fallback_entry, | 123 const AppCacheEntry& fallback_entry, |
124 int64_t cache_id, | 124 int64_t cache_id, |
125 int64_t group_id, | 125 int64_t group_id, |
126 const GURL& mainfest_url) override; | 126 const GURL& mainfest_url) override; |
127 | 127 |
128 // Sub-resource loading ------------------------------------- | 128 // Sub-resource loading ------------------------------------- |
129 // Dedicated worker and all manner of sub-resources are handled here. | 129 // Dedicated worker and all manner of sub-resources are handled here. |
130 | 130 |
131 std::unique_ptr<AppCacheURLRequestJob> MaybeLoadSubResource( | 131 std::unique_ptr<AppCacheJob> MaybeLoadSubResource( |
132 net::NetworkDelegate* network_delegate); | 132 net::NetworkDelegate* network_delegate); |
133 void ContinueMaybeLoadSubResource(); | 133 void ContinueMaybeLoadSubResource(); |
134 | 134 |
135 // AppCacheHost::Observer override | 135 // AppCacheHost::Observer override |
136 void OnCacheSelectionComplete(AppCacheHost* host) override; | 136 void OnCacheSelectionComplete(AppCacheHost* host) override; |
137 | 137 |
138 // Data members ----------------------------------------------- | 138 // Data members ----------------------------------------------- |
139 | 139 |
140 // What host we're servicing a request for. | 140 // What host we're servicing a request for. |
141 AppCacheHost* host_; | 141 AppCacheHost* host_; |
(...skipping 28 matching lines...) Expand all Loading... |
170 // intercept opportunity. | 170 // intercept opportunity. |
171 bool is_delivering_network_response_; | 171 bool is_delivering_network_response_; |
172 | 172 |
173 // True if this->MaybeLoadResource(...) has been called in the past. | 173 // True if this->MaybeLoadResource(...) has been called in the past. |
174 bool maybe_load_resource_executed_; | 174 bool maybe_load_resource_executed_; |
175 | 175 |
176 // The job we use to deliver a response. Only NULL during the following times: | 176 // The job we use to deliver a response. Only NULL during the following times: |
177 // 1) Before request has started a job. | 177 // 1) Before request has started a job. |
178 // 2) Request is not being handled by appcache. | 178 // 2) Request is not being handled by appcache. |
179 // 3) Request has been cancelled, and the job killed. | 179 // 3) Request has been cancelled, and the job killed. |
180 base::WeakPtr<AppCacheURLRequestJob> job_; | 180 base::WeakPtr<AppCacheJob> job_; |
181 | 181 |
182 // During a cross site navigation, we transfer ownership the AppcacheHost | 182 // During a cross site navigation, we transfer ownership the AppcacheHost |
183 // from the old processes structures over to the new structures. | 183 // from the old processes structures over to the new structures. |
184 std::unique_ptr<AppCacheHost> host_for_cross_site_transfer_; | 184 std::unique_ptr<AppCacheHost> host_for_cross_site_transfer_; |
185 int old_process_id_; | 185 int old_process_id_; |
186 int old_host_id_; | 186 int old_host_id_; |
187 | 187 |
188 // Cached information about the response being currently served by the | 188 // Cached information about the response being currently served by the |
189 // AppCache, if there is one. | 189 // AppCache, if there is one. |
190 int cache_id_; | 190 int cache_id_; |
191 GURL manifest_url_; | 191 GURL manifest_url_; |
192 | 192 |
193 // Backptr to the central service object. | 193 // Backptr to the central service object. |
194 AppCacheServiceImpl* service_; | 194 AppCacheServiceImpl* service_; |
195 | 195 |
196 std::unique_ptr<AppCacheRequest> request_; | 196 std::unique_ptr<AppCacheRequest> request_; |
197 | 197 |
198 friend class content::AppCacheRequestHandlerTest; | 198 friend class content::AppCacheRequestHandlerTest; |
199 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); | 199 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); |
200 }; | 200 }; |
201 | 201 |
202 } // namespace content | 202 } // namespace content |
203 | 203 |
204 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 204 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
OLD | NEW |