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_WRITER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STRE AM_WRITER_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/fileapi/file_stream_writer.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 writer implementation with an intermediate buffer. | |
| 22 // Writes data from the internal file stream writer in chunks of size at least | |
| 23 // |intermediate_buffer_length| bytes (or less for the last chunk, or when | |
| 24 // Flush() | |
| 25 // is explicitely called). | |
| 26 // | |
| 27 // The underlying inner file stream writer *must not* return any values | |
|
hashimoto
2014/09/11 07:52:16
nit: Sometimes the writer is referred as "inner" w
mtomasz
2014/09/17 04:59:40
Done.
| |
| 28 // synchronously. Instead, results must be returned by a callback, including | |
| 29 // errors. Moreover, partial writes are *not* supported. | |
| 30 // | |
| 31 // Flush() must be called on completion to ensure that all bytes are written | |
|
hashimoto
2014/09/11 07:52:16
This description should be put in storage::FileStr
mtomasz
2014/09/17 04:59:40
I tried a CHECK() and I think this is not the best
hashimoto
2014/09/22 12:10:31
You can replace CHECK with something harmless like
mtomasz
2014/09/24 01:45:31
That's possible, but I think flushing from the des
hashimoto
2014/09/26 07:05:55
Flush() in the dtor requires the provider process
| |
| 32 // successfully. | |
| 33 class BufferingFileStreamWriter : public storage::FileStreamWriter { | |
| 34 public: | |
| 35 BufferingFileStreamWriter( | |
| 36 scoped_ptr<storage::FileStreamWriter> file_stream_writer, | |
| 37 int intermediate_buffer_length); | |
| 38 | |
| 39 virtual ~BufferingFileStreamWriter(); | |
| 40 | |
| 41 // storage::FileStreamWriter overrides. | |
| 42 virtual int Write(net::IOBuffer* buf, | |
| 43 int buf_len, | |
| 44 const net::CompletionCallback& callback) OVERRIDE; | |
| 45 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; | |
| 46 virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; | |
| 47 | |
| 48 private: | |
| 49 // Copies |length| bytes of data from the |buffer| starting at |offset| | |
| 50 // position to the current position of the intermediate buffer. | |
| 51 void CopyToIntermediateBuffer(scoped_refptr<net::IOBuffer> buffer, | |
| 52 int offset, | |
| 53 int length); | |
| 54 | |
| 55 // Flushes all of the bytes in the intermediate buffer to the internal | |
| 56 // file stream writer. | |
| 57 void FlushIntermediateBuffer(const net::CompletionCallback& callback); | |
| 58 | |
| 59 // Called when flushing the intermediate buffer is completed with either | |
| 60 // a success or an error. | |
| 61 void OnFlushIntermediateBufferCompleted( | |
| 62 int length, | |
| 63 const net::CompletionCallback& callback, | |
| 64 int result); | |
| 65 | |
| 66 // Called when flushing the intermediate buffer for direct write is completed | |
| 67 // with either a success or an error. | |
| 68 void OnFlushIntermediateBufferForDirectWriteCompleted( | |
| 69 scoped_refptr<net::IOBuffer> buffer, | |
| 70 int length, | |
| 71 const net::CompletionCallback& callback, | |
| 72 int result); | |
| 73 | |
| 74 // Called when flushing the intermediate buffer for a buffered write is | |
| 75 // completed with either a success or an error. | |
| 76 void OnFlushIntermediateBufferForBufferedWriteCompleted( | |
| 77 scoped_refptr<net::IOBuffer> buffer, | |
| 78 int buffered_bytes, | |
| 79 int bytes_left, | |
| 80 const net::CompletionCallback& callback, | |
| 81 int result); | |
| 82 | |
| 83 // Called when flushing the intermediate buffer for a flush call is completed | |
| 84 // with either a success or an error. | |
| 85 void OnFlushIntermediateBufferForFlushCompleted( | |
| 86 const net::CompletionCallback& callback, | |
| 87 int result); | |
| 88 | |
| 89 scoped_ptr<storage::FileStreamWriter> file_stream_writer_; | |
| 90 int intermediate_buffer_length_; | |
| 91 scoped_refptr<net::IOBuffer> intermediate_buffer_; | |
| 92 int buffered_bytes_; | |
| 93 | |
| 94 base::WeakPtrFactory<BufferingFileStreamWriter> weak_ptr_factory_; | |
| 95 DISALLOW_COPY_AND_ASSIGN(BufferingFileStreamWriter); | |
| 96 }; | |
| 97 | |
| 98 } // namespace file_system_provider | |
| 99 } // namespace chromeos | |
| 100 | |
| 101 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_S TREAM_WRITER_H_ | |
| OLD | NEW |