Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: storage/browser/blob/blob_reader.h

Issue 1513783005: [Blob] Fix for resetting reader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: storage/browser/blob/blob_reader.h
diff --git a/storage/browser/blob/blob_reader.h b/storage/browser/blob/blob_reader.h
index 54b262f3ef3e910dfcf932c37a87d8b9e85ab8b7..6a68af8ef7c1ca5dbb91d79a16777e5d44d03af6 100644
--- a/storage/browser/blob/blob_reader.h
+++ b/storage/browser/blob/blob_reader.h
@@ -13,6 +13,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "net/base/completion_callback.h"
+#include "net/base/net_errors.h"
#include "storage/browser/storage_browser_export.h"
class GURL;
@@ -41,6 +42,7 @@ class FileSystemContext;
// * There can only be one read happening at a time per reader.
// * If a status of Status::NET_ERROR is returned, that means there was an
// error and the net_error() variable contains the error code.
+// * To reuse a reader on the same blob, call the Reset() function.
// Use a BlobDataHandle to create an instance.
class STORAGE_EXPORT BlobReader {
public:
@@ -65,7 +67,8 @@ class STORAGE_EXPORT BlobReader {
// This calculates the total size of the blob, and initializes the reading
// cursor.
- // * This should only be called once per reader.
+ // * This should only be called once per reader, unless 'Reset' has been
+ // called.
// * Status::Done means that the total_size() value is populated and you can
// continue to SetReadRange or Read.
// * The 'done' callback is only called if Status::IO_PENDING is returned.
@@ -95,6 +98,10 @@ class STORAGE_EXPORT BlobReader {
// after this call.
void Kill();
+ // This resets the reader so we can use it again. Usually used in conjunction
+ // with reader_used(). This will invalidate all callbacks.
+ void Reset();
+
// Returns if all of the blob's items are in memory.
bool IsInMemory() const;
@@ -109,6 +116,9 @@ class STORAGE_EXPORT BlobReader {
// is called.
uint64_t total_size() const { return total_size_; }
+ // Returns if this reader has been used yet.
+ bool reader_used() const { return reader_used_; }
+
protected:
friend class BlobDataHandle;
friend class BlobReaderTest;
@@ -163,17 +173,17 @@ class STORAGE_EXPORT BlobReader {
scoped_ptr<FileStreamReaderProvider> file_stream_provider_;
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
- int net_error_;
- bool item_list_populated_ = false;
+ int net_error_ = net::OK;
std::vector<uint64_t> item_length_list_;
scoped_refptr<net::DrainableIOBuffer> read_buf_;
+ bool reader_used_ = false;
bool total_size_calculated_ = false;
uint64_t total_size_ = 0;
uint64_t remaining_bytes_ = 0;
size_t pending_get_file_info_count_ = 0;
- std::map<size_t, FileStreamReader*> index_to_reader_;
+ std::map<size_t, scoped_ptr<FileStreamReader>> index_to_reader_;
size_t current_item_index_ = 0;
uint64_t current_item_offset_ = 0;

Powered by Google App Engine
This is Rietveld 408576698