| Index: net/base/upload_disk_cache_entry_element_reader.cc
|
| diff --git a/net/base/upload_disk_cache_entry_element_reader.cc b/net/base/upload_disk_cache_entry_element_reader.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0141b177870c52ed8c10ee8f98ae25c46a4b2325
|
| --- /dev/null
|
| +++ b/net/base/upload_disk_cache_entry_element_reader.cc
|
| @@ -0,0 +1,84 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "net/base/upload_disk_cache_entry_element_reader.h"
|
| +
|
| +#include "net/base/io_buffer.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "net/disk_cache/disk_cache.h"
|
| +
|
| +namespace net {
|
| +
|
| +UploadDiskCacheEntryElementReader::UploadDiskCacheEntryElementReader(
|
| + disk_cache::Entry* disk_cache_entry,
|
| + int disk_cache_stream_index,
|
| + int range_offset,
|
| + int range_length)
|
| + : disk_cache_entry_(disk_cache_entry),
|
| + disk_cache_stream_index_(disk_cache_stream_index),
|
| + range_offset_(range_offset),
|
| + range_length_(range_length),
|
| + offset_(range_offset_),
|
| + weak_factory_(this) {
|
| + DCHECK_LE(range_offset_ + range_length,
|
| + disk_cache_entry_->GetDataSize(disk_cache_stream_index_));
|
| +}
|
| +
|
| +UploadDiskCacheEntryElementReader::~UploadDiskCacheEntryElementReader() {
|
| +}
|
| +
|
| +const UploadDiskCacheEntryElementReader*
|
| +UploadDiskCacheEntryElementReader::AsDiskCacheEntryReader() const {
|
| + return this;
|
| +}
|
| +
|
| +int UploadDiskCacheEntryElementReader::Init(
|
| + const CompletionCallback& callback) {
|
| + weak_factory_.InvalidateWeakPtrs();
|
| + offset_ = range_offset_;
|
| + return OK;
|
| +}
|
| +
|
| +uint64_t UploadDiskCacheEntryElementReader::GetContentLength() const {
|
| + return range_length_;
|
| +}
|
| +
|
| +uint64_t UploadDiskCacheEntryElementReader::BytesRemaining() const {
|
| + const int amount_read = offset_ - range_offset_;
|
| + return range_length_ - amount_read;
|
| +}
|
| +
|
| +bool UploadDiskCacheEntryElementReader::IsInMemory() const {
|
| + return false;
|
| +}
|
| +
|
| +int UploadDiskCacheEntryElementReader::Read(
|
| + IOBuffer* buf,
|
| + int buf_length,
|
| + const CompletionCallback& callback) {
|
| + const int bytes_to_read =
|
| + std::min(buf_length, static_cast<int>(BytesRemaining()));
|
| +
|
| + CompletionCallback new_callback =
|
| + base::Bind(&UploadDiskCacheEntryElementReader::OnReadCompleted,
|
| + weak_factory_.GetWeakPtr(), callback);
|
| +
|
| + const int result = disk_cache_entry_->ReadData(
|
| + disk_cache_stream_index_, offset_, buf, bytes_to_read, new_callback);
|
| + if (result == ERR_IO_PENDING)
|
| + return ERR_IO_PENDING;
|
| + if (result > 0)
|
| + offset_ += result;
|
| + return result;
|
| +}
|
| +
|
| +void UploadDiskCacheEntryElementReader::OnReadCompleted(
|
| + const CompletionCallback& callback,
|
| + int result) {
|
| + if (result > 0)
|
| + offset_ += result;
|
| + callback.Run(result);
|
| +}
|
| +
|
| +} // namespace net
|
|
|