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 #include "webkit/browser/appcache/appcache_request_handler.h" | 5 #include "webkit/browser/appcache/appcache_request_handler.h" |
6 | 6 |
7 #include "net/url_request/url_request.h" | 7 #include "net/url_request/url_request.h" |
8 #include "net/url_request/url_request_job.h" | 8 #include "net/url_request/url_request_job.h" |
9 #include "webkit/browser/appcache/appcache.h" | 9 #include "webkit/browser/appcache/appcache.h" |
| 10 #include "webkit/browser/appcache/appcache_backend_impl.h" |
10 #include "webkit/browser/appcache/appcache_policy.h" | 11 #include "webkit/browser/appcache/appcache_policy.h" |
11 #include "webkit/browser/appcache/appcache_url_request_job.h" | 12 #include "webkit/browser/appcache/appcache_url_request_job.h" |
12 | 13 |
13 namespace appcache { | 14 namespace appcache { |
14 | 15 |
15 AppCacheRequestHandler::AppCacheRequestHandler( | 16 AppCacheRequestHandler::AppCacheRequestHandler( |
16 AppCacheHost* host, ResourceType::Type resource_type) | 17 AppCacheHost* host, ResourceType::Type resource_type) |
17 : host_(host), resource_type_(resource_type), | 18 : host_(host), resource_type_(resource_type), |
18 is_waiting_for_cache_selection_(false), found_group_id_(0), | 19 is_waiting_for_cache_selection_(false), found_group_id_(0), |
19 found_cache_id_(0), found_network_namespace_(false), | 20 found_cache_id_(0), found_network_namespace_(false), |
20 cache_entry_not_found_(false), maybe_load_resource_executed_(false) { | 21 cache_entry_not_found_(false), maybe_load_resource_executed_(false) { |
21 DCHECK(host_); | 22 DCHECK(host_); |
22 host_->AddObserver(this); | 23 host_->AddObserver(this); |
23 } | 24 } |
24 | 25 |
25 AppCacheRequestHandler::~AppCacheRequestHandler() { | 26 AppCacheRequestHandler::~AppCacheRequestHandler() { |
26 if (host_) { | 27 if (host_) { |
27 storage()->CancelDelegateCallbacks(this); | 28 storage()->CancelDelegateCallbacks(this); |
28 host_->RemoveObserver(this); | 29 host_->RemoveObserver(this); |
29 } | 30 } |
30 } | 31 } |
31 | 32 |
32 AppCacheStorage* AppCacheRequestHandler::storage() const { | 33 AppCacheStorage* AppCacheRequestHandler::storage() const { |
33 DCHECK(host_); | 34 DCHECK(host_); |
34 return host_->storage(); | 35 return host_->storage(); |
35 } | 36 } |
36 | 37 |
37 void AppCacheRequestHandler::GetExtraResponseInfo( | |
38 int64* cache_id, GURL* manifest_url) { | |
39 if (job_.get() && job_->is_delivering_appcache_response()) { | |
40 *cache_id = job_->cache_id(); | |
41 *manifest_url = job_->manifest_url(); | |
42 } | |
43 } | |
44 | |
45 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( | 38 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( |
46 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 39 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
47 maybe_load_resource_executed_ = true; | 40 maybe_load_resource_executed_ = true; |
48 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 41 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
49 return NULL; | 42 return NULL; |
50 | 43 |
51 // This method can get called multiple times over the life | 44 // This method can get called multiple times over the life |
52 // of a request. The case we detect here is having scheduled | 45 // of a request. The case we detect here is having scheduled |
53 // delivery of a "network response" using a job setup on an | 46 // delivery of a "network response" using a job setup on an |
54 // earlier call thru this method. To send the request thru | 47 // earlier call thru this method. To send the request thru |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // 6.9.6, step 4: If this results in a 4xx or 5xx status code | 156 // 6.9.6, step 4: If this results in a 4xx or 5xx status code |
164 // or there were network errors, get the resource of the fallback entry. | 157 // or there were network errors, get the resource of the fallback entry. |
165 job_ = new AppCacheURLRequestJob(request, network_delegate, | 158 job_ = new AppCacheURLRequestJob(request, network_delegate, |
166 storage(), host_); | 159 storage(), host_); |
167 DeliverAppCachedResponse( | 160 DeliverAppCachedResponse( |
168 found_fallback_entry_, found_cache_id_, found_group_id_, | 161 found_fallback_entry_, found_cache_id_, found_group_id_, |
169 found_manifest_url_, true, found_namespace_entry_url_); | 162 found_manifest_url_, true, found_namespace_entry_url_); |
170 return job_.get(); | 163 return job_.get(); |
171 } | 164 } |
172 | 165 |
| 166 void AppCacheRequestHandler::GetExtraResponseInfo( |
| 167 int64* cache_id, GURL* manifest_url) { |
| 168 if (job_.get() && job_->is_delivering_appcache_response()) { |
| 169 *cache_id = job_->cache_id(); |
| 170 *manifest_url = job_->manifest_url(); |
| 171 } |
| 172 } |
| 173 |
| 174 void AppCacheRequestHandler::PrepareForCrossSiteTransfer(int old_process_id) { |
| 175 if (!host_) |
| 176 return; |
| 177 AppCacheBackendImpl* backend = host_->service()->GetBackend(old_process_id); |
| 178 host_for_cross_site_transfer_ = backend->TransferHostOut(host_->host_id()); |
| 179 DCHECK_EQ(host_, host_for_cross_site_transfer_.get()); |
| 180 } |
| 181 |
| 182 void AppCacheRequestHandler::CompleteCrossSiteTransfer( |
| 183 int new_process_id, int new_host_id) { |
| 184 if (!host_for_cross_site_transfer_.get()) |
| 185 return; |
| 186 DCHECK_EQ(host_, host_for_cross_site_transfer_.get()); |
| 187 AppCacheBackendImpl* backend = host_->service()->GetBackend(new_process_id); |
| 188 backend->TransferHostIn(new_host_id, host_for_cross_site_transfer_.Pass()); |
| 189 } |
| 190 |
173 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { | 191 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { |
174 storage()->CancelDelegateCallbacks(this); | 192 storage()->CancelDelegateCallbacks(this); |
175 host_ = NULL; // no need to RemoveObserver, the host is being deleted | 193 host_ = NULL; // no need to RemoveObserver, the host is being deleted |
176 | 194 |
177 // Since the host is being deleted, we don't have to complete any job | 195 // Since the host is being deleted, we don't have to complete any job |
178 // that is current running. It's destined for the bit bucket anyway. | 196 // that is current running. It's destined for the bit bucket anyway. |
179 if (job_.get()) { | 197 if (job_.get()) { |
180 job_->Kill(); | 198 job_->Kill(); |
181 job_ = NULL; | 199 job_ = NULL; |
182 } | 200 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (!host_->associated_cache() || | 389 if (!host_->associated_cache() || |
372 !host_->associated_cache()->is_complete()) { | 390 !host_->associated_cache()->is_complete()) { |
373 DeliverNetworkResponse(); | 391 DeliverNetworkResponse(); |
374 return; | 392 return; |
375 } | 393 } |
376 | 394 |
377 ContinueMaybeLoadSubResource(); | 395 ContinueMaybeLoadSubResource(); |
378 } | 396 } |
379 | 397 |
380 } // namespace appcache | 398 } // namespace appcache |
OLD | NEW |