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

Unified Diff: chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h

Issue 178473022: MTP Streaming: Readahead Buffer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months 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: chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h
diff --git a/chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h b/chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..972fd2a2b8dce71bb5bfba73f3828e0af4ae95ff
--- /dev/null
+++ b/chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h
@@ -0,0 +1,75 @@
+// Copyright 2014 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 CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H_
+#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H_
+
+#include <queue>
+
+#include "base/memory/weak_ptr.h"
+#include "net/base/io_buffer.h"
+#include "webkit/browser/blob/file_stream_reader.h"
+
+// Wraps an underlying FileStreamReader with a readahead buffer.
+class ReadaheadFileStreamReader
+ : public NON_EXPORTED_BASE(webkit_blob::FileStreamReader) {
+ public:
+ // Takes ownership of |underlying|.
+ ReadaheadFileStreamReader(webkit_blob::FileStreamReader* underlying);
vandebo (ex-Chrome) 2014/03/03 22:24:54 explicit
vandebo (ex-Chrome) 2014/03/03 22:24:54 nit: underlying -> source ? (throughout)
tommycli 2014/03/04 00:39:40 Done.
tommycli 2014/03/04 00:39:40 Done.
+
+ virtual ~ReadaheadFileStreamReader();
+
+ // FileStreamReader overrides.
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback) OVERRIDE;
+ virtual int64 GetLength(
+ const net::Int64CompletionCallback& callback) OVERRIDE;
+
+ private:
+ // Represents an outstanding read request, waiting for the buffer to be filled
+ // from the underlying FileStreamReader.
+ struct Request {
+ Request(net::IOBuffer* buf, int buf_len,
+ const net::CompletionCallback& callback);
+ ~Request();
+
+ scoped_refptr<net::IOBuffer> buf;
+ const int buf_len;
+ const net::CompletionCallback callback;
+ };
+
+ // Returns the number of bytes consumed from the interal buffer into |buf|.
+ int ConsumeFromBuffer(net::IOBuffer* buf, int buf_len);
+
+ // Reads into a new buffer from the underlying reader. This calls
+ // OnFinishReadFromUnderlying when it completes (either synchronously or
+ // asynchronously).
+ void ReadFromUnderlying();
+ void OnFinishReadFromUnderlying(net::IOBuffer* buffer, int result);
+
+ // This is reset to NULL upon encountering a read error or EOF.
+ scoped_ptr<webkit_blob::FileStreamReader> underlying_;
+
+ // This stores the error or EOF from the underlying FileStreamReader. Its
+ // value is undefined if |underlying_| is non-NULL.
+ int underlying_error_;
+
+ int64 current_offset_;
+
+ // This contains a queue of buffers filled from |underlying_|, waiting to be
+ // consumed.
+ std::queue<scoped_refptr<net::DrainableIOBuffer>> buffers_;
+
+ // The read request waiting for the underlying FileStreamReader to finish
+ // reading and fill a buffer.
+ scoped_ptr<Request> pending_read_;
vandebo (ex-Chrome) 2014/03/03 22:24:54 Since you only have a pointer to Request, can you
tommycli 2014/03/04 00:39:40 Done.
+
+ bool underlying_has_pending_read_;
+
+ base::WeakPtrFactory<ReadaheadFileStreamReader> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadaheadFileStreamReader);
+};
+
+#endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H_

Powered by Google App Engine
This is Rietveld 408576698