| 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_response.h" | 5 #include "content/browser/appcache/appcache_response.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 ~WrappedPickleIOBuffer() override {} | 40 ~WrappedPickleIOBuffer() override {} |
| 41 | 41 |
| 42 scoped_ptr<const base::Pickle> pickle_; | 42 scoped_ptr<const base::Pickle> pickle_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 } // anon namespace | 45 } // anon namespace |
| 46 | 46 |
| 47 | 47 |
| 48 // AppCacheResponseInfo ---------------------------------------------- | 48 // AppCacheResponseInfo ---------------------------------------------- |
| 49 | 49 |
| 50 AppCacheResponseInfo::AppCacheResponseInfo( | 50 AppCacheResponseInfo::AppCacheResponseInfo(AppCacheStorage* storage, |
| 51 AppCacheStorage* storage, const GURL& manifest_url, | 51 const GURL& manifest_url, |
| 52 int64 response_id, net::HttpResponseInfo* http_info, | 52 int64_t response_id, |
| 53 int64 response_data_size) | 53 net::HttpResponseInfo* http_info, |
| 54 : manifest_url_(manifest_url), response_id_(response_id), | 54 int64_t response_data_size) |
| 55 http_response_info_(http_info), response_data_size_(response_data_size), | 55 : manifest_url_(manifest_url), |
| 56 response_id_(response_id), |
| 57 http_response_info_(http_info), |
| 58 response_data_size_(response_data_size), |
| 56 storage_(storage) { | 59 storage_(storage) { |
| 57 DCHECK(http_info); | 60 DCHECK(http_info); |
| 58 DCHECK(response_id != kAppCacheNoResponseId); | 61 DCHECK(response_id != kAppCacheNoResponseId); |
| 59 storage_->working_set()->AddResponseInfo(this); | 62 storage_->working_set()->AddResponseInfo(this); |
| 60 } | 63 } |
| 61 | 64 |
| 62 AppCacheResponseInfo::~AppCacheResponseInfo() { | 65 AppCacheResponseInfo::~AppCacheResponseInfo() { |
| 63 storage_->working_set()->RemoveResponseInfo(this); | 66 storage_->working_set()->RemoveResponseInfo(this); |
| 64 } | 67 } |
| 65 | 68 |
| 66 // HttpResponseInfoIOBuffer ------------------------------------------ | 69 // HttpResponseInfoIOBuffer ------------------------------------------ |
| 67 | 70 |
| 68 HttpResponseInfoIOBuffer::HttpResponseInfoIOBuffer() | 71 HttpResponseInfoIOBuffer::HttpResponseInfoIOBuffer() |
| 69 : response_data_size(kUnkownResponseDataSize) {} | 72 : response_data_size(kUnkownResponseDataSize) {} |
| 70 | 73 |
| 71 HttpResponseInfoIOBuffer::HttpResponseInfoIOBuffer(net::HttpResponseInfo* info) | 74 HttpResponseInfoIOBuffer::HttpResponseInfoIOBuffer(net::HttpResponseInfo* info) |
| 72 : http_info(info), response_data_size(kUnkownResponseDataSize) {} | 75 : http_info(info), response_data_size(kUnkownResponseDataSize) {} |
| 73 | 76 |
| 74 HttpResponseInfoIOBuffer::~HttpResponseInfoIOBuffer() {} | 77 HttpResponseInfoIOBuffer::~HttpResponseInfoIOBuffer() {} |
| 75 | 78 |
| 76 // AppCacheResponseIO ---------------------------------------------- | 79 // AppCacheResponseIO ---------------------------------------------- |
| 77 | 80 |
| 78 AppCacheResponseIO::AppCacheResponseIO( | 81 AppCacheResponseIO::AppCacheResponseIO(int64_t response_id, |
| 79 int64 response_id, int64 group_id, AppCacheDiskCacheInterface* disk_cache) | 82 int64_t group_id, |
| 83 AppCacheDiskCacheInterface* disk_cache) |
| 80 : response_id_(response_id), | 84 : response_id_(response_id), |
| 81 group_id_(group_id), | 85 group_id_(group_id), |
| 82 disk_cache_(disk_cache), | 86 disk_cache_(disk_cache), |
| 83 entry_(NULL), | 87 entry_(NULL), |
| 84 buffer_len_(0), | 88 buffer_len_(0), |
| 85 weak_factory_(this) { | 89 weak_factory_(this) {} |
| 86 } | |
| 87 | 90 |
| 88 AppCacheResponseIO::~AppCacheResponseIO() { | 91 AppCacheResponseIO::~AppCacheResponseIO() { |
| 89 if (entry_) | 92 if (entry_) |
| 90 entry_->Close(); | 93 entry_->Close(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void AppCacheResponseIO::ScheduleIOCompletionCallback(int result) { | 96 void AppCacheResponseIO::ScheduleIOCompletionCallback(int result) { |
| 94 base::ThreadTaskRunnerHandle::Get()->PostTask( | 97 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 95 FROM_HERE, base::Bind(&AppCacheResponseIO::OnIOComplete, | 98 FROM_HERE, base::Bind(&AppCacheResponseIO::OnIOComplete, |
| 96 weak_factory_.GetWeakPtr(), result)); | 99 weak_factory_.GetWeakPtr(), result)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 166 } |
| 164 open_callback_.Reset(); | 167 open_callback_.Reset(); |
| 165 } | 168 } |
| 166 OnOpenEntryComplete(); | 169 OnOpenEntryComplete(); |
| 167 } | 170 } |
| 168 | 171 |
| 169 | 172 |
| 170 // AppCacheResponseReader ---------------------------------------------- | 173 // AppCacheResponseReader ---------------------------------------------- |
| 171 | 174 |
| 172 AppCacheResponseReader::AppCacheResponseReader( | 175 AppCacheResponseReader::AppCacheResponseReader( |
| 173 int64 response_id, | 176 int64_t response_id, |
| 174 int64 group_id, | 177 int64_t group_id, |
| 175 AppCacheDiskCacheInterface* disk_cache) | 178 AppCacheDiskCacheInterface* disk_cache) |
| 176 : AppCacheResponseIO(response_id, group_id, disk_cache), | 179 : AppCacheResponseIO(response_id, group_id, disk_cache), |
| 177 range_offset_(0), | 180 range_offset_(0), |
| 178 range_length_(kint32max), | 181 range_length_(std::numeric_limits<int32_t>::max()), |
| 179 read_position_(0), | 182 read_position_(0), |
| 180 reading_metadata_size_(0), | 183 reading_metadata_size_(0), |
| 181 weak_factory_(this) { | 184 weak_factory_(this) {} |
| 182 } | |
| 183 | 185 |
| 184 AppCacheResponseReader::~AppCacheResponseReader() { | 186 AppCacheResponseReader::~AppCacheResponseReader() { |
| 185 } | 187 } |
| 186 | 188 |
| 187 void AppCacheResponseReader::ReadInfo(HttpResponseInfoIOBuffer* info_buf, | 189 void AppCacheResponseReader::ReadInfo(HttpResponseInfoIOBuffer* info_buf, |
| 188 const net::CompletionCallback& callback) { | 190 const net::CompletionCallback& callback) { |
| 189 DCHECK(!callback.is_null()); | 191 DCHECK(!callback.is_null()); |
| 190 DCHECK(!IsReadPending()); | 192 DCHECK(!IsReadPending()); |
| 191 DCHECK(info_buf); | 193 DCHECK(info_buf); |
| 192 DCHECK(!info_buf->http_info.get()); | 194 DCHECK(!info_buf->http_info.get()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 return; | 261 return; |
| 260 } | 262 } |
| 261 DCHECK(!response_truncated); | 263 DCHECK(!response_truncated); |
| 262 info_buffer_->http_info.reset(info.release()); | 264 info_buffer_->http_info.reset(info.release()); |
| 263 | 265 |
| 264 // Also return the size of the response body | 266 // Also return the size of the response body |
| 265 DCHECK(entry_); | 267 DCHECK(entry_); |
| 266 info_buffer_->response_data_size = | 268 info_buffer_->response_data_size = |
| 267 entry_->GetSize(kResponseContentIndex); | 269 entry_->GetSize(kResponseContentIndex); |
| 268 | 270 |
| 269 int64 metadata_size = entry_->GetSize(kResponseMetadataIndex); | 271 int64_t metadata_size = entry_->GetSize(kResponseMetadataIndex); |
| 270 if (metadata_size > 0) { | 272 if (metadata_size > 0) { |
| 271 reading_metadata_size_ = metadata_size; | 273 reading_metadata_size_ = metadata_size; |
| 272 info_buffer_->http_info->metadata = new net::IOBufferWithSize( | 274 info_buffer_->http_info->metadata = new net::IOBufferWithSize( |
| 273 base::CheckedNumeric<size_t>(metadata_size).ValueOrDie()); | 275 base::CheckedNumeric<size_t>(metadata_size).ValueOrDie()); |
| 274 ReadRaw(kResponseMetadataIndex, 0, | 276 ReadRaw(kResponseMetadataIndex, 0, |
| 275 info_buffer_->http_info->metadata.get(), metadata_size); | 277 info_buffer_->http_info->metadata.get(), metadata_size); |
| 276 return; | 278 return; |
| 277 } | 279 } |
| 278 } else { | 280 } else { |
| 279 read_position_ += result; | 281 read_position_ += result; |
| 280 } | 282 } |
| 281 } | 283 } |
| 282 InvokeUserCompletionCallback(result); | 284 InvokeUserCompletionCallback(result); |
| 283 } | 285 } |
| 284 | 286 |
| 285 void AppCacheResponseReader::OnOpenEntryComplete() { | 287 void AppCacheResponseReader::OnOpenEntryComplete() { |
| 286 if (!entry_) { | 288 if (!entry_) { |
| 287 ScheduleIOCompletionCallback(net::ERR_CACHE_MISS); | 289 ScheduleIOCompletionCallback(net::ERR_CACHE_MISS); |
| 288 return; | 290 return; |
| 289 } | 291 } |
| 290 if (info_buffer_.get()) | 292 if (info_buffer_.get()) |
| 291 ContinueReadInfo(); | 293 ContinueReadInfo(); |
| 292 else | 294 else |
| 293 ContinueReadData(); | 295 ContinueReadData(); |
| 294 } | 296 } |
| 295 | 297 |
| 296 // AppCacheResponseWriter ---------------------------------------------- | 298 // AppCacheResponseWriter ---------------------------------------------- |
| 297 | 299 |
| 298 AppCacheResponseWriter::AppCacheResponseWriter( | 300 AppCacheResponseWriter::AppCacheResponseWriter( |
| 299 int64 response_id, int64 group_id, AppCacheDiskCacheInterface* disk_cache) | 301 int64_t response_id, |
| 302 int64_t group_id, |
| 303 AppCacheDiskCacheInterface* disk_cache) |
| 300 : AppCacheResponseIO(response_id, group_id, disk_cache), | 304 : AppCacheResponseIO(response_id, group_id, disk_cache), |
| 301 info_size_(0), | 305 info_size_(0), |
| 302 write_position_(0), | 306 write_position_(0), |
| 303 write_amount_(0), | 307 write_amount_(0), |
| 304 creation_phase_(INITIAL_ATTEMPT), | 308 creation_phase_(INITIAL_ATTEMPT), |
| 305 weak_factory_(this) { | 309 weak_factory_(this) {} |
| 306 } | |
| 307 | 310 |
| 308 AppCacheResponseWriter::~AppCacheResponseWriter() { | 311 AppCacheResponseWriter::~AppCacheResponseWriter() { |
| 309 } | 312 } |
| 310 | 313 |
| 311 void AppCacheResponseWriter::WriteInfo( | 314 void AppCacheResponseWriter::WriteInfo( |
| 312 HttpResponseInfoIOBuffer* info_buf, | 315 HttpResponseInfoIOBuffer* info_buf, |
| 313 const net::CompletionCallback& callback) { | 316 const net::CompletionCallback& callback) { |
| 314 DCHECK(!callback.is_null()); | 317 DCHECK(!callback.is_null()); |
| 315 DCHECK(!IsWritePending()); | 318 DCHECK(!IsWritePending()); |
| 316 DCHECK(info_buf); | 319 DCHECK(info_buf); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 433 |
| 431 if (info_buffer_.get()) | 434 if (info_buffer_.get()) |
| 432 ContinueWriteInfo(); | 435 ContinueWriteInfo(); |
| 433 else | 436 else |
| 434 ContinueWriteData(); | 437 ContinueWriteData(); |
| 435 } | 438 } |
| 436 | 439 |
| 437 // AppCacheResponseMetadataWriter ---------------------------------------------- | 440 // AppCacheResponseMetadataWriter ---------------------------------------------- |
| 438 | 441 |
| 439 AppCacheResponseMetadataWriter::AppCacheResponseMetadataWriter( | 442 AppCacheResponseMetadataWriter::AppCacheResponseMetadataWriter( |
| 440 int64 response_id, | 443 int64_t response_id, |
| 441 int64 group_id, | 444 int64_t group_id, |
| 442 AppCacheDiskCacheInterface* disk_cache) | 445 AppCacheDiskCacheInterface* disk_cache) |
| 443 : AppCacheResponseIO(response_id, group_id, disk_cache), | 446 : AppCacheResponseIO(response_id, group_id, disk_cache), |
| 444 write_amount_(0), | 447 write_amount_(0), |
| 445 weak_factory_(this) { | 448 weak_factory_(this) {} |
| 446 } | |
| 447 | 449 |
| 448 AppCacheResponseMetadataWriter::~AppCacheResponseMetadataWriter() { | 450 AppCacheResponseMetadataWriter::~AppCacheResponseMetadataWriter() { |
| 449 } | 451 } |
| 450 | 452 |
| 451 void AppCacheResponseMetadataWriter::WriteMetadata( | 453 void AppCacheResponseMetadataWriter::WriteMetadata( |
| 452 net::IOBuffer* buf, | 454 net::IOBuffer* buf, |
| 453 int buf_len, | 455 int buf_len, |
| 454 const net::CompletionCallback& callback) { | 456 const net::CompletionCallback& callback) { |
| 455 DCHECK(!callback.is_null()); | 457 DCHECK(!callback.is_null()); |
| 456 DCHECK(!IsIOPending()); | 458 DCHECK(!IsIOPending()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 471 } | 473 } |
| 472 WriteRaw(kResponseMetadataIndex, 0, buffer_.get(), write_amount_); | 474 WriteRaw(kResponseMetadataIndex, 0, buffer_.get(), write_amount_); |
| 473 } | 475 } |
| 474 | 476 |
| 475 void AppCacheResponseMetadataWriter::OnIOComplete(int result) { | 477 void AppCacheResponseMetadataWriter::OnIOComplete(int result) { |
| 476 DCHECK(result < 0 || write_amount_ == result); | 478 DCHECK(result < 0 || write_amount_ == result); |
| 477 InvokeUserCompletionCallback(result); | 479 InvokeUserCompletionCallback(result); |
| 478 } | 480 } |
| 479 | 481 |
| 480 } // namespace content | 482 } // namespace content |
| OLD | NEW |