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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H_
7
8 #include <queue>
9
10 #include "base/memory/weak_ptr.h"
11 #include "net/base/io_buffer.h"
12 #include "webkit/browser/blob/file_stream_reader.h"
13
14 // Wraps a source FileStreamReader with a readahead buffer.
15 class ReadaheadFileStreamReader
16 : public NON_EXPORTED_BASE(webkit_blob::FileStreamReader) {
17 public:
18 // Takes ownership of |source|.
19 explicit ReadaheadFileStreamReader(webkit_blob::FileStreamReader* source);
20
21 virtual ~ReadaheadFileStreamReader();
22
23 // FileStreamReader overrides.
24 virtual int Read(net::IOBuffer* buf, int buf_len,
25 const net::CompletionCallback& callback) OVERRIDE;
26 virtual int64 GetLength(
27 const net::Int64CompletionCallback& callback) OVERRIDE;
28
29 private:
30 struct Request;
31
32 // Returns the number of bytes consumed from the interal buffer into |buf|.
33 int ConsumeFromBuffer(net::IOBuffer* buf, int buf_len);
vandebo (ex-Chrome) 2014/03/04 18:51:32 Out of the context of this comment, this name is c
tommycli 2014/03/04 21:14:58 Done.
34
35 // Reads into a new buffer from the source reader. This calls
36 // OnFinishReadFromUnderlying when it completes (either synchronously or
vandebo (ex-Chrome) 2014/03/04 18:51:32 nit: ...FromSource
tommycli 2014/03/04 21:14:58 Done.
37 // asynchronously).
38 void ReadFromSource();
39 void OnFinishReadFromSource(net::IOBuffer* buffer, int result);
40
41 // This is reset to NULL upon encountering a read error or EOF.
42 scoped_ptr<webkit_blob::FileStreamReader> source_;
43
44 // This stores the error or EOF from the source FileStreamReader. Its
45 // value is undefined if |source_| is non-NULL.
46 int source_error_;
47
48 int64 current_offset_;
49
50 // This contains a queue of buffers filled from |source_|, waiting to be
51 // consumed.
52 std::queue<scoped_refptr<net::DrainableIOBuffer>> buffers_;
53
54 // The read request waiting for the source FileStreamReader to finish
55 // reading and fill a buffer.
56 scoped_ptr<Request> pending_read_;
57
58 bool source_has_pending_read_;
59
60 base::WeakPtrFactory<ReadaheadFileStreamReader> weak_factory_;
61
62 DISALLOW_COPY_AND_ASSIGN(ReadaheadFileStreamReader);
63 };
64
65 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698