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

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 an underlying FileStreamReader with a readahead buffer.
15 class ReadaheadFileStreamReader
16 : public NON_EXPORTED_BASE(webkit_blob::FileStreamReader) {
17 public:
18 // Takes ownership of |underlying|.
19 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.
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 // Represents an outstanding read request, waiting for the buffer to be filled
31 // from the underlying FileStreamReader.
32 struct Request {
33 Request(net::IOBuffer* buf, int buf_len,
34 const net::CompletionCallback& callback);
35 ~Request();
36
37 scoped_refptr<net::IOBuffer> buf;
38 const int buf_len;
39 const net::CompletionCallback callback;
40 };
41
42 // Returns the number of bytes consumed from the interal buffer into |buf|.
43 int ConsumeFromBuffer(net::IOBuffer* buf, int buf_len);
44
45 // Reads into a new buffer from the underlying reader. This calls
46 // OnFinishReadFromUnderlying when it completes (either synchronously or
47 // asynchronously).
48 void ReadFromUnderlying();
49 void OnFinishReadFromUnderlying(net::IOBuffer* buffer, int result);
50
51 // This is reset to NULL upon encountering a read error or EOF.
52 scoped_ptr<webkit_blob::FileStreamReader> underlying_;
53
54 // This stores the error or EOF from the underlying FileStreamReader. Its
55 // value is undefined if |underlying_| is non-NULL.
56 int underlying_error_;
57
58 int64 current_offset_;
59
60 // This contains a queue of buffers filled from |underlying_|, waiting to be
61 // consumed.
62 std::queue<scoped_refptr<net::DrainableIOBuffer>> buffers_;
63
64 // The read request waiting for the underlying FileStreamReader to finish
65 // reading and fill a buffer.
66 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.
67
68 bool underlying_has_pending_read_;
69
70 base::WeakPtrFactory<ReadaheadFileStreamReader> weak_factory_;
71
72 DISALLOW_COPY_AND_ASSIGN(ReadaheadFileStreamReader);
73 };
74
75 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_READAHEAD_FILE_STREAM_READER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698