Chromium Code Reviews| 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 "net/base/io_buffer.h" | |
|
hashimoto
2014/06/05 03:18:36
nit: forward declaration is enough.
mtomasz
2014/06/05 09:22:27
Done.
| |
| 13 #include "webkit/browser/blob/file_stream_reader.h" | |
| 14 | |
| 15 namespace fileapi { | |
| 16 class AsyncFileUtil; | |
|
hashimoto
2014/06/05 03:18:36
nit: unused forward declaration.
mtomasz
2014/06/05 09:22:27
Done.
| |
| 17 } // namespace fileapi | |
| 18 | |
| 19 namespace chromeos { | |
| 20 namespace file_system_provider { | |
| 21 | |
| 22 // Wraps the file stream reader implementation with a prefetching buffer. This | |
| 23 // limits number of IPC to providing extensions significantly. For remote (HTTP | |
| 24 // base) file systems, this also reduces overhead when creating HTTP requests | |
| 25 // for each chunk. The chunks are bigger, so number of requests is smaller. | |
| 26 class BufferingFileStreamReader : public webkit_blob::FileStreamReader { | |
| 27 public: | |
| 28 explicit BufferingFileStreamReader( | |
|
hashimoto
2014/06/05 03:18:36
nit: "explicit" unneeded.
mtomasz
2014/06/05 09:22:27
Done.
| |
| 29 scoped_ptr<webkit_blob::FileStreamReader> file_stream_reader, | |
| 30 int buffer_size); | |
| 31 | |
| 32 virtual ~BufferingFileStreamReader(); | |
| 33 | |
| 34 // webkit_blob::FileStreamReader overrides. | |
| 35 virtual int Read(net::IOBuffer* buf, | |
| 36 int buf_len, | |
| 37 const net::CompletionCallback& callback) OVERRIDE; | |
| 38 virtual int64 GetLength( | |
| 39 const net::Int64CompletionCallback& callback) OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 // Copies data from the preloading buffer and updates the internal iterator. | |
| 43 // Returns number of bytes successfully copied. | |
| 44 int CopyFromBuffer(scoped_refptr<net::IOBuffer> buffer, int buffer_length); | |
| 45 | |
| 46 // Preloads data from the internal stream reader and calls the |callback|. | |
| 47 void Preload(const net::CompletionCallback& callback); | |
| 48 | |
| 49 // Called when preloading of a buffer chunk is finished. Updates state of the | |
| 50 // preloading buffer and copied requested data to the |buffer|. | |
| 51 void OnPreloadCompleted(scoped_refptr<net::IOBuffer> buffer, | |
| 52 int buffer_length, | |
| 53 const net::CompletionCallback& callback, | |
| 54 int result); | |
| 55 | |
| 56 scoped_ptr<webkit_blob::FileStreamReader> file_stream_reader_; | |
| 57 int buffer_size_; | |
| 58 scoped_refptr<net::IOBuffer> preloading_buffer_; | |
|
hashimoto
2014/06/05 03:18:36
How about using DrainableIOBuffer?
mtomasz
2014/06/05 09:22:27
Net::DrainableIOBuffer works well if the buffer is
hashimoto
2014/06/05 10:07:10
I meant by using DrailableIOBuffer there is no nee
mtomasz
2014/06/05 11:27:43
This won't work since the buffer is not always ful
hashimoto
2014/06/05 12:31:09
You don't need BytesRemaining().
What I suggested
mtomasz
2014/06/06 01:31:02
DrailableIOBuffer is designed for fully filled out
| |
| 59 int preloading_buffer_offset_; | |
| 60 int buffered_bytes_; | |
| 61 | |
| 62 base::WeakPtrFactory<BufferingFileStreamReader> weak_ptr_factory_; | |
| 63 DISALLOW_COPY_AND_ASSIGN(BufferingFileStreamReader); | |
| 64 }; | |
| 65 | |
| 66 } // namespace file_system_provider | |
| 67 } // namespace chromeos | |
| 68 | |
| 69 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_S TREAM_READER_H_ | |
| OLD | NEW |