OLD | NEW |
(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_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STRE
AM_READER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STRE
AM_READER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "webkit/browser/blob/file_stream_reader.h" |
| 13 |
| 14 namespace net { |
| 15 class IOBuffer; |
| 16 } // namespace net |
| 17 |
| 18 namespace chromeos { |
| 19 namespace file_system_provider { |
| 20 |
| 21 // Wraps the file stream reader implementation with a prefetching buffer. This |
| 22 // limits number of IPC to providing extensions significantly. For remote (HTTP |
| 23 // base) file systems, this also reduces overhead when creating HTTP requests |
| 24 // for each chunk. The chunks are bigger, so number of requests is smaller. |
| 25 class BufferingFileStreamReader : public webkit_blob::FileStreamReader { |
| 26 public: |
| 27 BufferingFileStreamReader( |
| 28 scoped_ptr<webkit_blob::FileStreamReader> file_stream_reader, |
| 29 int buffer_size); |
| 30 |
| 31 virtual ~BufferingFileStreamReader(); |
| 32 |
| 33 // webkit_blob::FileStreamReader overrides. |
| 34 virtual int Read(net::IOBuffer* buf, |
| 35 int buf_len, |
| 36 const net::CompletionCallback& callback) OVERRIDE; |
| 37 virtual int64 GetLength( |
| 38 const net::Int64CompletionCallback& callback) OVERRIDE; |
| 39 |
| 40 private: |
| 41 // Copies data from the preloading buffer and updates the internal iterator. |
| 42 // Returns number of bytes successfully copied. |
| 43 int CopyFromBuffer(scoped_refptr<net::IOBuffer> buffer, int buffer_length); |
| 44 |
| 45 // Preloads data from the internal stream reader and calls the |callback|. |
| 46 void Preload(const net::CompletionCallback& callback); |
| 47 |
| 48 // Called when preloading of a buffer chunk is finished. Updates state of the |
| 49 // preloading buffer and copied requested data to the |buffer|. |
| 50 void OnPreloadCompleted(scoped_refptr<net::IOBuffer> buffer, |
| 51 int buffer_length, |
| 52 const net::CompletionCallback& callback, |
| 53 int result); |
| 54 |
| 55 scoped_ptr<webkit_blob::FileStreamReader> file_stream_reader_; |
| 56 int buffer_size_; |
| 57 scoped_refptr<net::IOBuffer> preloading_buffer_; |
| 58 int preloading_buffer_offset_; |
| 59 int buffered_bytes_; |
| 60 |
| 61 base::WeakPtrFactory<BufferingFileStreamReader> weak_ptr_factory_; |
| 62 DISALLOW_COPY_AND_ASSIGN(BufferingFileStreamReader); |
| 63 }; |
| 64 |
| 65 } // namespace file_system_provider |
| 66 } // namespace chromeos |
| 67 |
| 68 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_S
TREAM_READER_H_ |
OLD | NEW |