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

Unified Diff: chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h

Issue 502973005: [fsp] Buffer consecutive Write() calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a comment. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
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..34f0245bfc1a5e5c55768a3801baa0167c5e80f5
--- /dev/null
+++ b/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_writer.h
@@ -0,0 +1,98 @@
+// 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 "storage/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 inner 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
+// synchronously. Instead, results must be returned by a callback, including
+// errors. Moreover, partial writes are *not* supported.
+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;
hashimoto 2014/10/16 21:39:03 nit: override should be small-cased now.
mtomasz 2014/10/17 00:26:07 Done.
+
+ private:
+ // Copies |buffer_length| bytes of data from the |buffer| starting at
+ // |buffer_offset| position to the current position of the intermediate
+ // buffer.
+ void CopyToIntermediateBuffer(scoped_refptr<net::IOBuffer> buffer,
+ int buffer_offset,
+ int buffer_length);
+
+ // Flushes all of the bytes in the intermediate buffer to the inner 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_

Powered by Google App Engine
This is Rietveld 408576698