| Index: storage/browser/blob/blob_reader.h
|
| diff --git a/storage/browser/blob/blob_reader.h b/storage/browser/blob/blob_reader.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5925e9550879efa0ab28d4653954b4d4d825e9b0
|
| --- /dev/null
|
| +++ b/storage/browser/blob/blob_reader.h
|
| @@ -0,0 +1,165 @@
|
| +// 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.
|
| +
|
| +#ifndef STORAGE_BROWSER_BLOB_BLOB_READER_H_
|
| +#define STORAGE_BROWSER_BLOB_BLOB_READER_H_
|
| +
|
| +#include <stdint.h>
|
| +#include <map>
|
| +#include <vector>
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "net/base/completion_callback.h"
|
| +#include "net/http/http_byte_range.h"
|
| +#include "net/http/http_status_code.h"
|
| +#include "storage/browser/storage_browser_export.h"
|
| +
|
| +class GURL;
|
| +
|
| +namespace base {
|
| +class FilePath;
|
| +class SingleThreadTaskRunner;
|
| +class TaskRunner;
|
| +class Time;
|
| +}
|
| +
|
| +namespace net {
|
| +class DrainableIOBuffer;
|
| +class IOBuffer;
|
| +}
|
| +
|
| +namespace storage {
|
| +class BlobDataItem;
|
| +class BlobDataHandle;
|
| +class BlobDataSnapshot;
|
| +class FileStreamReader;
|
| +class FileSystemContext;
|
| +
|
| +// The blob reader is used to read a blob. There can only be one read happening
|
| +// at a time per reader.
|
| +class STORAGE_EXPORT BlobReader {
|
| + public:
|
| + class FileStreamReaderProvider {
|
| + public:
|
| + virtual ~FileStreamReaderProvider();
|
| +
|
| + virtual FileStreamReader* CreateForLocalFile(
|
| + base::TaskRunner* task_runner,
|
| + const base::FilePath& file_path,
|
| + int64_t initial_offset,
|
| + const base::Time& expected_modification_time) = 0;
|
| +
|
| + virtual FileStreamReader* CreateFileStreamReader(
|
| + const GURL& filesystem_url,
|
| + int64_t offset,
|
| + int64_t max_bytes_to_read,
|
| + const base::Time& expected_modification_time) = 0;
|
| + };
|
| + enum class Status { NET_ERROR, PENDING_IO, DONE };
|
| + virtual ~BlobReader();
|
| +
|
| + // Done is only called if net::IO_PENDING is returned.
|
| + // This calculates the total size of the blob, and initializes the reading
|
| + // cursor. This can only be called once on the reader.
|
| + Status CalculateSize(net::CompletionCallback done);
|
| +
|
| + // Used to set the read position.
|
| + Status SetReadRange(uint64_t position, uint64_t length);
|
| +
|
| + // Done is called only if net::IO_PENDING is returned.
|
| + // Reads a portion of the data.
|
| + Status Read(net::IOBuffer* buffer,
|
| + size_t dest_size,
|
| + int* bytes_read,
|
| + net::CompletionCallback done);
|
| +
|
| + void Kill();
|
| +
|
| + bool IsInMemory() const;
|
| +
|
| + uint64_t remaining_bytes() const { return remaining_bytes_; }
|
| +
|
| + int net_error() const { return net_error_; }
|
| +
|
| + bool total_size_calculated() const { return total_size_calculated_; }
|
| +
|
| + uint64_t total_size() const { return total_size_; }
|
| +
|
| + protected:
|
| + friend class BlobDataHandle;
|
| + friend class BlobReaderTest;
|
| + BlobReader(const BlobDataHandle* blob_handle,
|
| + scoped_ptr<FileStreamReaderProvider> file_stream_provider,
|
| + base::SingleThreadTaskRunner* file_task_runner);
|
| +
|
| + private:
|
| + Status ReportError(int net_error);
|
| + void InvalidateCallbacksAndDone(int net_error, net::CompletionCallback done);
|
| +
|
| + bool AddItemLength(size_t index, uint64_t length);
|
| + bool ResolveFileItemLength(const BlobDataItem& item,
|
| + int64_t total_length,
|
| + uint64_t* output_length);
|
| + void DidGetFileItemLength(size_t index, int64_t result);
|
| + void DidCountSize();
|
| +
|
| + // For reading the blob.
|
| + // Returns if we're done, PENDING_IO if we're waiting on async.
|
| + Status ReadLoop(int* bytes_read);
|
| + void ContinueAsyncReadLoop();
|
| + // PENDING_IO means we're waiting on async.
|
| + Status ReadItem();
|
| + void AdvanceItem();
|
| + void AdvanceBytesRead(int result);
|
| + void ReadBytesItem(const BlobDataItem& item, int bytes_to_read);
|
| + BlobReader::Status ReadFileItem(FileStreamReader* reader, int bytes_to_read);
|
| + void DidReadFile(int result);
|
| + void DeleteCurrentFileReader();
|
| + BlobReader::Status ReadDiskCacheEntryItem(const BlobDataItem& item,
|
| + int bytes_to_read);
|
| + void DidReadDiskCacheEntry(int result);
|
| + int ComputeBytesToRead() const;
|
| + int BytesReadCompleted();
|
| +
|
| + // Returns a FileStreamReader for a blob item at |index|.
|
| + // If the item at |index| is not of file this returns NULL.
|
| + FileStreamReader* FileReaderAtIndex(size_t index);
|
| + void SetFileReaderAtIndex(size_t index, FileStreamReader* reader);
|
| + // Creates a FileStreamReader for the item with additional_offset.
|
| + FileStreamReader* CreateFileStreamReader(const BlobDataItem& item,
|
| + uint64_t additional_offset);
|
| +
|
| + const BlobDataHandle* blob_handle_;
|
| + scoped_ptr<BlobDataSnapshot> blob_data_;
|
| + scoped_ptr<FileStreamReaderProvider> file_stream_provider_;
|
| + scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
|
| +
|
| + int net_error_;
|
| + bool item_list_populated_;
|
| + std::vector<uint64_t> item_length_list_;
|
| +
|
| + scoped_refptr<net::DrainableIOBuffer> read_buf_;
|
| +
|
| + bool total_size_calculated_;
|
| + uint64_t total_size_;
|
| + uint64_t remaining_bytes_;
|
| + size_t pending_get_file_info_count_;
|
| + std::map<size_t, FileStreamReader*> index_to_reader_;
|
| + size_t current_item_index_;
|
| + uint64_t current_item_offset_;
|
| +
|
| + bool io_pending_;
|
| + bool read_is_async_;
|
| +
|
| + net::CompletionCallback size_done_;
|
| + net::CompletionCallback read_done_;
|
| +
|
| + base::WeakPtrFactory<BlobReader> weak_factory_;
|
| + DISALLOW_COPY_AND_ASSIGN(BlobReader);
|
| +};
|
| +
|
| +} // namespace storage
|
| +#endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_
|
|
|