| 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 <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/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 13 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
| 15 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
| 16 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_util.h" | 19 #include "net/http/http_util.h" |
| 18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 20 #include "webkit/appcache/appcache_service.h" | 22 #include "webkit/appcache/appcache_service.h" |
| 21 | 23 |
| 22 namespace appcache { | 24 namespace appcache { |
| 23 | 25 |
| 24 AppCacheURLRequestJob::AppCacheURLRequestJob( | 26 AppCacheURLRequestJob::AppCacheURLRequestJob( |
| 25 net::URLRequest* request, AppCacheStorage* storage) | 27 net::URLRequest* request, AppCacheStorage* storage) |
| 26 : net::URLRequestJob(request), storage_(storage), | 28 : net::URLRequestJob(request), storage_(storage), |
| 27 has_been_started_(false), has_been_killed_(false), | 29 has_been_started_(false), has_been_killed_(false), |
| 28 delivery_type_(AWAITING_DELIVERY_ORDERS), | 30 delivery_type_(AWAITING_DELIVERY_ORDERS), |
| 29 group_id_(0), cache_id_(kNoCacheId), is_fallback_(false), | 31 group_id_(0), cache_id_(kNoCacheId), is_fallback_(false), |
| 30 cache_entry_not_found_(false), | 32 cache_entry_not_found_(false), |
| 31 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | |
| 32 this, &AppCacheURLRequestJob::OnReadComplete)), | |
| 33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 34 DCHECK(storage_); | 34 DCHECK(storage_); |
| 35 } | 35 } |
| 36 | 36 |
| 37 AppCacheURLRequestJob::~AppCacheURLRequestJob() { | 37 AppCacheURLRequestJob::~AppCacheURLRequestJob() { |
| 38 if (storage_) | 38 if (storage_) |
| 39 storage_->CancelDelegateCallbacks(this); | 39 storage_->CancelDelegateCallbacks(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void AppCacheURLRequestJob::DeliverAppCachedResponse( | 42 void AppCacheURLRequestJob::DeliverAppCachedResponse( |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 return -1; | 261 return -1; |
| 262 return http_info()->headers->response_code(); | 262 return http_info()->headers->response_code(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size, | 265 bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 266 int *bytes_read) { | 266 int *bytes_read) { |
| 267 DCHECK(is_delivering_appcache_response()); | 267 DCHECK(is_delivering_appcache_response()); |
| 268 DCHECK_NE(buf_size, 0); | 268 DCHECK_NE(buf_size, 0); |
| 269 DCHECK(bytes_read); | 269 DCHECK(bytes_read); |
| 270 DCHECK(!reader_->IsReadPending()); | 270 DCHECK(!reader_->IsReadPending()); |
| 271 reader_->ReadData(buf, buf_size, &read_callback_); | 271 reader_->ReadData( |
| 272 buf, buf_size, base::Bind(&AppCacheURLRequestJob::OnReadComplete, |
| 273 base::Unretained(this))); |
| 272 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 274 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 273 return false; | 275 return false; |
| 274 } | 276 } |
| 275 | 277 |
| 276 void AppCacheURLRequestJob::SetExtraRequestHeaders( | 278 void AppCacheURLRequestJob::SetExtraRequestHeaders( |
| 277 const net::HttpRequestHeaders& headers) { | 279 const net::HttpRequestHeaders& headers) { |
| 278 std::string value; | 280 std::string value; |
| 279 std::vector<net::HttpByteRange> ranges; | 281 std::vector<net::HttpByteRange> ranges; |
| 280 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || | 282 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || |
| 281 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { | 283 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { |
| 282 return; | 284 return; |
| 283 } | 285 } |
| 284 | 286 |
| 285 // If multiple ranges are requested, we play dumb and | 287 // If multiple ranges are requested, we play dumb and |
| 286 // return the entire response with 200 OK. | 288 // return the entire response with 200 OK. |
| 287 if (ranges.size() == 1U) | 289 if (ranges.size() == 1U) |
| 288 range_requested_ = ranges[0]; | 290 range_requested_ = ranges[0]; |
| 289 } | 291 } |
| 290 | 292 |
| 291 } // namespace appcache | 293 } // namespace appcache |
| OLD | NEW |