| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/appcache/appcache_url_request_job.h" | 5 #include "content/browser/appcache/appcache_url_request_job.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 AppCacheURLRequestJob::AppCacheURLRequestJob( | 34 AppCacheURLRequestJob::AppCacheURLRequestJob( |
| 35 net::URLRequest* request, | 35 net::URLRequest* request, |
| 36 net::NetworkDelegate* network_delegate, | 36 net::NetworkDelegate* network_delegate, |
| 37 AppCacheStorage* storage, | 37 AppCacheStorage* storage, |
| 38 AppCacheHost* host, | 38 AppCacheHost* host, |
| 39 bool is_main_resource, | 39 bool is_main_resource, |
| 40 const OnPrepareToRestartCallback& restart_callback) | 40 const OnPrepareToRestartCallback& restart_callback) |
| 41 : net::URLRequestJob(request, network_delegate), | 41 : net::URLRequestJob(request, network_delegate), |
| 42 host_(host), | 42 host_(host), |
| 43 storage_(storage), | 43 storage_(storage), |
| 44 has_been_started_(false), has_been_killed_(false), | 44 has_been_started_(false), |
| 45 has_been_killed_(false), |
| 45 delivery_type_(AWAITING_DELIVERY_ORDERS), | 46 delivery_type_(AWAITING_DELIVERY_ORDERS), |
| 46 group_id_(0), cache_id_(kAppCacheNoCacheId), is_fallback_(false), | 47 cache_id_(kAppCacheNoCacheId), |
| 48 is_fallback_(false), |
| 47 is_main_resource_(is_main_resource), | 49 is_main_resource_(is_main_resource), |
| 48 cache_entry_not_found_(false), | 50 cache_entry_not_found_(false), |
| 49 on_prepare_to_restart_callback_(restart_callback), | 51 on_prepare_to_restart_callback_(restart_callback), |
| 50 weak_factory_(this) { | 52 weak_factory_(this) { |
| 51 DCHECK(storage_); | 53 DCHECK(storage_); |
| 52 } | 54 } |
| 53 | 55 |
| 54 AppCacheURLRequestJob::~AppCacheURLRequestJob() { | 56 AppCacheURLRequestJob::~AppCacheURLRequestJob() { |
| 55 if (storage_) | 57 if (storage_) |
| 56 storage_->CancelDelegateCallbacks(this); | 58 storage_->CancelDelegateCallbacks(this); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url, | 61 void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url, |
| 60 int64_t group_id, | |
| 61 int64_t cache_id, | 62 int64_t cache_id, |
| 62 const AppCacheEntry& entry, | 63 const AppCacheEntry& entry, |
| 63 bool is_fallback) { | 64 bool is_fallback) { |
| 64 DCHECK(!has_delivery_orders()); | 65 DCHECK(!has_delivery_orders()); |
| 65 DCHECK(entry.has_response_id()); | 66 DCHECK(entry.has_response_id()); |
| 66 delivery_type_ = APPCACHED_DELIVERY; | 67 delivery_type_ = APPCACHED_DELIVERY; |
| 67 manifest_url_ = manifest_url; | 68 manifest_url_ = manifest_url; |
| 68 group_id_ = group_id; | |
| 69 cache_id_ = cache_id; | 69 cache_id_ = cache_id; |
| 70 entry_ = entry; | 70 entry_ = entry; |
| 71 is_fallback_ = is_fallback; | 71 is_fallback_ = is_fallback; |
| 72 MaybeBeginDelivery(); | 72 MaybeBeginDelivery(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void AppCacheURLRequestJob::DeliverNetworkResponse() { | 75 void AppCacheURLRequestJob::DeliverNetworkResponse() { |
| 76 DCHECK(!has_delivery_orders()); | 76 DCHECK(!has_delivery_orders()); |
| 77 delivery_type_ = NETWORK_DELIVERY; | 77 delivery_type_ = NETWORK_DELIVERY; |
| 78 storage_ = NULL; // not needed | 78 storage_ = NULL; // not needed |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 if (entry_.IsExecutable()) { | 130 if (entry_.IsExecutable()) { |
| 131 BeginExecutableHandlerDelivery(); | 131 BeginExecutableHandlerDelivery(); |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 AppCacheHistograms::AddAppCacheJobStartDelaySample( | 134 AppCacheHistograms::AddAppCacheJobStartDelaySample( |
| 135 base::TimeTicks::Now() - start_time_tick_); | 135 base::TimeTicks::Now() - start_time_tick_); |
| 136 request()->net_log().AddEvent( | 136 request()->net_log().AddEvent( |
| 137 is_fallback_ ? | 137 is_fallback_ ? |
| 138 net::NetLog::TYPE_APPCACHE_DELIVERING_FALLBACK_RESPONSE : | 138 net::NetLog::TYPE_APPCACHE_DELIVERING_FALLBACK_RESPONSE : |
| 139 net::NetLog::TYPE_APPCACHE_DELIVERING_CACHED_RESPONSE); | 139 net::NetLog::TYPE_APPCACHE_DELIVERING_CACHED_RESPONSE); |
| 140 storage_->LoadResponseInfo( | 140 storage_->LoadResponseInfo(manifest_url_, entry_.response_id(), this); |
| 141 manifest_url_, group_id_, entry_.response_id(), this); | |
| 142 break; | 141 break; |
| 143 | 142 |
| 144 default: | 143 default: |
| 145 NOTREACHED(); | 144 NOTREACHED(); |
| 146 break; | 145 break; |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 void AppCacheURLRequestJob::BeginExecutableHandlerDelivery() { | 149 void AppCacheURLRequestJob::BeginExecutableHandlerDelivery() { |
| 151 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 150 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // NOTE: This is not ideal since multiple jobs may be doing this, | 193 // NOTE: This is not ideal since multiple jobs may be doing this, |
| 195 // concurrently but close enough for now, the first to load the script | 194 // concurrently but close enough for now, the first to load the script |
| 196 // will win. | 195 // will win. |
| 197 | 196 |
| 198 // Read the script data, truncating if its too large. | 197 // Read the script data, truncating if its too large. |
| 199 // NOTE: we just issue one read and don't bother chaining if the resource | 198 // NOTE: we just issue one read and don't bother chaining if the resource |
| 200 // is very (very) large, close enough for now. | 199 // is very (very) large, close enough for now. |
| 201 const int64_t kLimit = 500 * 1000; | 200 const int64_t kLimit = 500 * 1000; |
| 202 handler_source_buffer_ = new net::GrowableIOBuffer(); | 201 handler_source_buffer_ = new net::GrowableIOBuffer(); |
| 203 handler_source_buffer_->SetCapacity(kLimit); | 202 handler_source_buffer_->SetCapacity(kLimit); |
| 204 handler_source_reader_.reset(storage_->CreateResponseReader( | 203 handler_source_reader_.reset( |
| 205 manifest_url_, group_id_, entry_.response_id())); | 204 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); |
| 206 handler_source_reader_->ReadData( | 205 handler_source_reader_->ReadData( |
| 207 handler_source_buffer_.get(), | 206 handler_source_buffer_.get(), |
| 208 kLimit, | 207 kLimit, |
| 209 base::Bind(&AppCacheURLRequestJob::OnExecutableSourceLoaded, | 208 base::Bind(&AppCacheURLRequestJob::OnExecutableSourceLoaded, |
| 210 base::Unretained(this))); | 209 base::Unretained(this))); |
| 211 } | 210 } |
| 212 | 211 |
| 213 void AppCacheURLRequestJob::OnExecutableSourceLoaded(int result) { | 212 void AppCacheURLRequestJob::OnExecutableSourceLoaded(int result) { |
| 214 DCHECK(!has_been_killed()); | 213 DCHECK(!has_been_killed()); |
| 215 handler_source_reader_.reset(); | 214 handler_source_reader_.reset(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 storage_ = NULL; | 275 storage_ = NULL; |
| 277 BeginDelivery(); | 276 BeginDelivery(); |
| 278 } | 277 } |
| 279 | 278 |
| 280 void AppCacheURLRequestJob::OnResponseInfoLoaded( | 279 void AppCacheURLRequestJob::OnResponseInfoLoaded( |
| 281 AppCacheResponseInfo* response_info, | 280 AppCacheResponseInfo* response_info, |
| 282 int64_t response_id) { | 281 int64_t response_id) { |
| 283 DCHECK(is_delivering_appcache_response()); | 282 DCHECK(is_delivering_appcache_response()); |
| 284 if (response_info) { | 283 if (response_info) { |
| 285 info_ = response_info; | 284 info_ = response_info; |
| 286 reader_.reset(storage_->CreateResponseReader( | 285 reader_.reset( |
| 287 manifest_url_, group_id_, entry_.response_id())); | 286 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); |
| 288 | 287 |
| 289 if (is_range_request()) | 288 if (is_range_request()) |
| 290 SetupRangeResponse(); | 289 SetupRangeResponse(); |
| 291 | 290 |
| 292 NotifyHeadersComplete(); | 291 NotifyHeadersComplete(); |
| 293 } else { | 292 } else { |
| 294 if (storage_->service()->storage() == storage_) { | 293 if (storage_->service()->storage() == storage_) { |
| 295 // A resource that is expected to be in the appcache is missing. | 294 // A resource that is expected to be in the appcache is missing. |
| 296 // See http://code.google.com/p/chromium/issues/detail?id=50657 | 295 // See http://code.google.com/p/chromium/issues/detail?id=50657 |
| 297 // Instead of failing the request, we restart the request. The retry | 296 // Instead of failing the request, we restart the request. The retry |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (ranges.size() == 1U) | 452 if (ranges.size() == 1U) |
| 454 range_requested_ = ranges[0]; | 453 range_requested_ = ranges[0]; |
| 455 } | 454 } |
| 456 | 455 |
| 457 void AppCacheURLRequestJob::NotifyRestartRequired() { | 456 void AppCacheURLRequestJob::NotifyRestartRequired() { |
| 458 on_prepare_to_restart_callback_.Run(); | 457 on_prepare_to_restart_callback_.Run(); |
| 459 URLRequestJob::NotifyRestartRequired(); | 458 URLRequestJob::NotifyRestartRequired(); |
| 460 } | 459 } |
| 461 | 460 |
| 462 } // namespace content | 461 } // namespace content |
| OLD | NEW |