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 "storage/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 inner file stream writer in chunks of size at least | |
23 // |intermediate_buffer_length| bytes (or less for the last chunk, or when | |
24 // Flush() is explicitely called). | |
25 // | |
26 // The underlying inner file stream writer *must not* return any values | |
27 // synchronously. Instead, results must be returned by a callback, including | |
28 // errors. Moreover, partial writes are *not* supported. | |
29 class BufferingFileStreamWriter : public storage::FileStreamWriter { | |
30 public: | |
31 BufferingFileStreamWriter( | |
32 scoped_ptr<storage::FileStreamWriter> file_stream_writer, | |
33 int intermediate_buffer_length); | |
34 | |
35 virtual ~BufferingFileStreamWriter(); | |
36 | |
37 // storage::FileStreamWriter overrides. | |
38 virtual int Write(net::IOBuffer* buf, | |
39 int buf_len, | |
40 const net::CompletionCallback& callback) OVERRIDE; | |
41 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; | |
42 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.
| |
43 | |
44 private: | |
45 // Copies |buffer_length| bytes of data from the |buffer| starting at | |
46 // |buffer_offset| position to the current position of the intermediate | |
47 // buffer. | |
48 void CopyToIntermediateBuffer(scoped_refptr<net::IOBuffer> buffer, | |
49 int buffer_offset, | |
50 int buffer_length); | |
51 | |
52 // Flushes all of the bytes in the intermediate buffer to the inner file | |
53 // stream writer. | |
54 void FlushIntermediateBuffer(const net::CompletionCallback& callback); | |
55 | |
56 // Called when flushing the intermediate buffer is completed with either | |
57 // a success or an error. | |
58 void OnFlushIntermediateBufferCompleted( | |
59 int length, | |
60 const net::CompletionCallback& callback, | |
61 int result); | |
62 | |
63 // Called when flushing the intermediate buffer for direct write is completed | |
64 // with either a success or an error. | |
65 void OnFlushIntermediateBufferForDirectWriteCompleted( | |
66 scoped_refptr<net::IOBuffer> buffer, | |
67 int length, | |
68 const net::CompletionCallback& callback, | |
69 int result); | |
70 | |
71 // Called when flushing the intermediate buffer for a buffered write is | |
72 // completed with either a success or an error. | |
73 void OnFlushIntermediateBufferForBufferedWriteCompleted( | |
74 scoped_refptr<net::IOBuffer> buffer, | |
75 int buffered_bytes, | |
76 int bytes_left, | |
77 const net::CompletionCallback& callback, | |
78 int result); | |
79 | |
80 // Called when flushing the intermediate buffer for a flush call is completed | |
81 // with either a success or an error. | |
82 void OnFlushIntermediateBufferForFlushCompleted( | |
83 const net::CompletionCallback& callback, | |
84 int result); | |
85 | |
86 scoped_ptr<storage::FileStreamWriter> file_stream_writer_; | |
87 int intermediate_buffer_length_; | |
88 scoped_refptr<net::IOBuffer> intermediate_buffer_; | |
89 int buffered_bytes_; | |
90 | |
91 base::WeakPtrFactory<BufferingFileStreamWriter> weak_ptr_factory_; | |
92 DISALLOW_COPY_AND_ASSIGN(BufferingFileStreamWriter); | |
93 }; | |
94 | |
95 } // namespace file_system_provider | |
96 } // namespace chromeos | |
97 | |
98 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_S TREAM_WRITER_H_ | |
OLD | NEW |