Chromium Code Reviews| Index: chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h |
| diff --git a/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h b/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b1a2c48b6c5a884bd87b23a3f09a26d19fb6063 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STREAM_WRITER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STREAM_WRITER_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "webkit/browser/fileapi/file_stream_writer.h" |
| + |
| +namespace net { |
| +class IOBuffer; |
| +} // namespace net |
| + |
| +namespace chromeos { |
| +namespace file_system_provider { |
| + |
| +// Wraps the file stream writer implementation with an intermediate buffer. |
| +// Writes data from the internal file stream writer in chunks of size at least |
| +// |intermediate_buffer_length| bytes (or less for the last chunk, or when |
| +// Flush() |
| +// is explicitely called). |
| +// |
| +// 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.
|
| +// synchronously. Instead, results must be returned by a callback, including |
| +// errors. Moreover, partial writes are *not* supported. |
| +// |
| +// 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
|
| +// successfully. |
| +class BufferingFileStreamWriter : public storage::FileStreamWriter { |
| + public: |
| + BufferingFileStreamWriter( |
| + scoped_ptr<storage::FileStreamWriter> file_stream_writer, |
| + int intermediate_buffer_length); |
| + |
| + virtual ~BufferingFileStreamWriter(); |
| + |
| + // storage::FileStreamWriter overrides. |
| + virtual int Write(net::IOBuffer* buf, |
| + int buf_len, |
| + const net::CompletionCallback& callback) OVERRIDE; |
| + virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; |
| + virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; |
| + |
| + private: |
| + // Copies |length| bytes of data from the |buffer| starting at |offset| |
| + // position to the current position of the intermediate buffer. |
| + void CopyToIntermediateBuffer(scoped_refptr<net::IOBuffer> buffer, |
| + int offset, |
| + int length); |
| + |
| + // Flushes all of the bytes in the intermediate buffer to the internal |
| + // file stream writer. |
| + void FlushIntermediateBuffer(const net::CompletionCallback& callback); |
| + |
| + // Called when flushing the intermediate buffer is completed with either |
| + // a success or an error. |
| + void OnFlushIntermediateBufferCompleted( |
| + int length, |
| + const net::CompletionCallback& callback, |
| + int result); |
| + |
| + // Called when flushing the intermediate buffer for direct write is completed |
| + // with either a success or an error. |
| + void OnFlushIntermediateBufferForDirectWriteCompleted( |
| + scoped_refptr<net::IOBuffer> buffer, |
| + int length, |
| + const net::CompletionCallback& callback, |
| + int result); |
| + |
| + // Called when flushing the intermediate buffer for a buffered write is |
| + // completed with either a success or an error. |
| + void OnFlushIntermediateBufferForBufferedWriteCompleted( |
| + scoped_refptr<net::IOBuffer> buffer, |
| + int buffered_bytes, |
| + int bytes_left, |
| + const net::CompletionCallback& callback, |
| + int result); |
| + |
| + // Called when flushing the intermediate buffer for a flush call is completed |
| + // with either a success or an error. |
| + void OnFlushIntermediateBufferForFlushCompleted( |
| + const net::CompletionCallback& callback, |
| + int result); |
| + |
| + scoped_ptr<storage::FileStreamWriter> file_stream_writer_; |
| + int intermediate_buffer_length_; |
| + scoped_refptr<net::IOBuffer> intermediate_buffer_; |
| + int buffered_bytes_; |
| + |
| + base::WeakPtrFactory<BufferingFileStreamWriter> weak_ptr_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(BufferingFileStreamWriter); |
| +}; |
| + |
| +} // namespace file_system_provider |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STREAM_WRITER_H_ |