| 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 "webkit/browser/appcache/appcache_url_request_job.h" | 5 #include "webkit/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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 // Read the script data, truncating if its too large. | 182 // Read the script data, truncating if its too large. |
| 183 // NOTE: we just issue one read and don't bother chaining if the resource | 183 // NOTE: we just issue one read and don't bother chaining if the resource |
| 184 // is very (very) large, close enough for now. | 184 // is very (very) large, close enough for now. |
| 185 const int64 kLimit = 500 * 1000; | 185 const int64 kLimit = 500 * 1000; |
| 186 handler_source_buffer_ = new net::GrowableIOBuffer(); | 186 handler_source_buffer_ = new net::GrowableIOBuffer(); |
| 187 handler_source_buffer_->SetCapacity(kLimit); | 187 handler_source_buffer_->SetCapacity(kLimit); |
| 188 handler_source_reader_.reset(storage_->CreateResponseReader( | 188 handler_source_reader_.reset(storage_->CreateResponseReader( |
| 189 manifest_url_, group_id_, entry_.response_id())); | 189 manifest_url_, group_id_, entry_.response_id())); |
| 190 handler_source_reader_->ReadData( | 190 handler_source_reader_->ReadData( |
| 191 handler_source_buffer_, kLimit, | 191 handler_source_buffer_.get(), |
| 192 kLimit, |
| 192 base::Bind(&AppCacheURLRequestJob::OnExecutableSourceLoaded, | 193 base::Bind(&AppCacheURLRequestJob::OnExecutableSourceLoaded, |
| 193 base::Unretained(this))); | 194 base::Unretained(this))); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void AppCacheURLRequestJob::OnExecutableSourceLoaded(int result) { | 197 void AppCacheURLRequestJob::OnExecutableSourceLoaded(int result) { |
| 197 DCHECK(!has_been_killed()); | 198 DCHECK(!has_been_killed()); |
| 198 handler_source_reader_.reset(); | 199 handler_source_reader_.reset(); |
| 199 if (result < 0) { | 200 if (result < 0) { |
| 200 BeginErrorDelivery("script source load failed"); | 201 BeginErrorDelivery("script source load failed"); |
| 201 return; | 202 return; |
| 202 } | 203 } |
| 203 | 204 |
| 204 handler_source_buffer_->SetCapacity(result); // Free up some memory. | 205 handler_source_buffer_->SetCapacity(result); // Free up some memory. |
| 205 | 206 |
| 206 AppCacheExecutableHandler* handler = cache_->GetOrCreateExecutableHandler( | 207 AppCacheExecutableHandler* handler = cache_->GetOrCreateExecutableHandler( |
| 207 entry_.response_id(), handler_source_buffer_); | 208 entry_.response_id(), handler_source_buffer_.get()); |
| 208 handler_source_buffer_ = NULL; // not needed anymore | 209 handler_source_buffer_ = NULL; // not needed anymore |
| 209 if (handler) { | 210 if (handler) { |
| 210 InvokeExecutableHandler(handler); | 211 InvokeExecutableHandler(handler); |
| 211 return; | 212 return; |
| 212 } | 213 } |
| 213 | 214 |
| 214 BeginErrorDelivery("factory failed to produce a handler"); | 215 BeginErrorDelivery("factory failed to produce a handler"); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void AppCacheURLRequestJob::InvokeExecutableHandler( | 218 void AppCacheURLRequestJob::InvokeExecutableHandler( |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 return; | 436 return; |
| 436 } | 437 } |
| 437 | 438 |
| 438 // If multiple ranges are requested, we play dumb and | 439 // If multiple ranges are requested, we play dumb and |
| 439 // return the entire response with 200 OK. | 440 // return the entire response with 200 OK. |
| 440 if (ranges.size() == 1U) | 441 if (ranges.size() == 1U) |
| 441 range_requested_ = ranges[0]; | 442 range_requested_ = ranges[0]; |
| 442 } | 443 } |
| 443 | 444 |
| 444 } // namespace appcache | 445 } // namespace appcache |
| OLD | NEW |