| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "webkit/appcache/appcache_url_request_job.h" | 7 #include "webkit/appcache/appcache_url_request_job.h" |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
| 13 #include "net/http/http_request_headers.h" | 13 #include "net/http/http_request_headers.h" |
| 14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 15 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 18 | 18 |
| 19 namespace appcache { | 19 namespace appcache { |
| 20 | 20 |
| 21 AppCacheURLRequestJob::AppCacheURLRequestJob( | 21 AppCacheURLRequestJob::AppCacheURLRequestJob( |
| 22 URLRequest* request, AppCacheStorage* storage) | 22 URLRequest* request, AppCacheStorage* storage) |
| 23 : URLRequestJob(request), storage_(storage), | 23 : URLRequestJob(request), storage_(storage), |
| 24 has_been_started_(false), has_been_killed_(false), | 24 has_been_started_(false), has_been_killed_(false), |
| 25 delivery_type_(AWAITING_DELIVERY_ORDERS), | 25 delivery_type_(AWAITING_DELIVERY_ORDERS), |
| 26 cache_id_(kNoCacheId), | 26 cache_id_(kNoCacheId), is_fallback_(false), |
| 27 is_fallback_(false), | 27 cache_entry_not_found_(false), |
| 28 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 28 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( |
| 29 this, &AppCacheURLRequestJob::OnReadComplete)) { | 29 this, &AppCacheURLRequestJob::OnReadComplete)) { |
| 30 DCHECK(storage_); | 30 DCHECK(storage_); |
| 31 } | 31 } |
| 32 | 32 |
| 33 AppCacheURLRequestJob::~AppCacheURLRequestJob() { | 33 AppCacheURLRequestJob::~AppCacheURLRequestJob() { |
| 34 if (storage_) | 34 if (storage_) |
| 35 storage_->CancelDelegateCallbacks(this); | 35 storage_->CancelDelegateCallbacks(this); |
| 36 } | 36 } |
| 37 | 37 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (response_info) { | 115 if (response_info) { |
| 116 info_ = response_info; | 116 info_ = response_info; |
| 117 reader_.reset( | 117 reader_.reset( |
| 118 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); | 118 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); |
| 119 | 119 |
| 120 if (is_range_request()) | 120 if (is_range_request()) |
| 121 SetupRangeResponse(); | 121 SetupRangeResponse(); |
| 122 | 122 |
| 123 NotifyHeadersComplete(); | 123 NotifyHeadersComplete(); |
| 124 } else { | 124 } else { |
| 125 NotifyStartError( | 125 // A resource that is expected to be in the appcache is missing. |
| 126 URLRequestStatus(URLRequestStatus::FAILED, net::ERR_FAILED)); | 126 // See http://code.google.com/p/chromium/issues/detail?id=50657 |
| 127 // Instead of failing the request, we restart the request. The retry |
| 128 // attempt will fallthru to the network instead of trying to load |
| 129 // from the appcache. |
| 130 cache_entry_not_found_ = true; |
| 131 NotifyRestartRequired(); |
| 127 } | 132 } |
| 128 storage_ = NULL; // no longer needed | 133 storage_ = NULL; // no longer needed |
| 129 } | 134 } |
| 130 | 135 |
| 131 const net::HttpResponseInfo* AppCacheURLRequestJob::http_info() const { | 136 const net::HttpResponseInfo* AppCacheURLRequestJob::http_info() const { |
| 132 if (!info_.get()) | 137 if (!info_.get()) |
| 133 return NULL; | 138 return NULL; |
| 134 if (range_response_info_.get()) | 139 if (range_response_info_.get()) |
| 135 return range_response_info_.get(); | 140 return range_response_info_.get(); |
| 136 return info_->http_response_info(); | 141 return info_->http_response_info(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 271 } |
| 267 | 272 |
| 268 // If multiple ranges are requested, we play dumb and | 273 // If multiple ranges are requested, we play dumb and |
| 269 // return the entire response with 200 OK. | 274 // return the entire response with 200 OK. |
| 270 if (ranges.size() == 1U) | 275 if (ranges.size() == 1U) |
| 271 range_requested_ = ranges[0]; | 276 range_requested_ = ranges[0]; |
| 272 } | 277 } |
| 273 | 278 |
| 274 } // namespace appcache | 279 } // namespace appcache |
| 275 | 280 |
| OLD | NEW |