OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_FILEAPI_FILE_WRITER_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_WRITER_H_ |
6 #define WEBKIT_FILEAPI_FILE_WRITER_H_ | 6 #define WEBKIT_FILEAPI_FILE_WRITER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 class IOBuffer; | 13 class IOBuffer; |
14 } | 14 } |
15 | 15 |
16 namespace fileapi { | 16 namespace fileapi { |
17 | 17 |
18 // A generic interface for writing to a file-like object. | 18 // A generic interface for writing to a file-like object. |
| 19 // |
| 20 // TODO(kinuko): Consider better naming. (http://crbug.com/128483) |
| 21 // Note: this does not directly correspond to FileWriter in File API (which |
| 22 // is implemented by WebCore::FileWriter), though this class is used to |
| 23 // implement a part of it. FileWriterDelegate is NOT a delegate of this |
| 24 // class either. |
19 class FileWriter { | 25 class FileWriter { |
20 public: | 26 public: |
21 // Closes the file. If there's an in-flight operation, it is canceled (i.e., | 27 // Closes the file. If there's an in-flight operation, it is canceled (i.e., |
22 // the callback function associated with the operation is not called). | 28 // the callback function associated with the operation is not called). |
23 virtual ~FileWriter() {} | 29 virtual ~FileWriter() {} |
24 | 30 |
25 // Writes to the current cursor position asynchronously. | 31 // Writes to the current cursor position asynchronously. |
26 // | 32 // |
27 // Up to buf_len bytes will be written. (In other words, partial | 33 // Up to buf_len bytes will be written. (In other words, partial |
28 // writes are allowed.) If the write completed synchronously, it returns | 34 // writes are allowed.) If the write completed synchronously, it returns |
29 // the number of bytes written. If the operation could not be performed, it | 35 // the number of bytes written. If the operation could not be performed, it |
30 // returns an error code. Otherwise, net::ERR_IO_PENDING is returned, and the | 36 // returns an error code. Otherwise, net::ERR_IO_PENDING is returned, and the |
31 // callback will be run on the thread where Write() was called when the write | 37 // callback will be run on the thread where Write() was called when the write |
32 // has completed. | 38 // has completed. |
33 // | 39 // |
| 40 // This errors out (either synchronously or via callback) with: |
| 41 // net::ERR_FILE_NOT_FOUND: When the target file is not found. |
| 42 // net::ERR_ACCESS_DENIED: When the target file is a directory or |
| 43 // the writer has no permission on the file. |
| 44 // net::ERR_FILE_NO_SPACE: When the write will result in out of quota |
| 45 // or there is not enough room left on the disk. |
| 46 // |
34 // It is invalid to call Write while there is an in-flight async operation. | 47 // It is invalid to call Write while there is an in-flight async operation. |
35 virtual int Write(net::IOBuffer* buf, int buf_len, | 48 virtual int Write(net::IOBuffer* buf, int buf_len, |
36 const net::CompletionCallback& callback) = 0; | 49 const net::CompletionCallback& callback) = 0; |
37 | 50 |
38 // Cancels an in-flight async operation. | 51 // Cancels an in-flight async operation. |
39 // | 52 // |
40 // If the cancel is finished synchronously, it returns net::OK. If the | 53 // If the cancel is finished synchronously, it returns net::OK. If the |
41 // cancel could not be performed, it returns an error code. Especially when | 54 // cancel could not be performed, it returns an error code. Especially when |
42 // there is no in-flight operation, net::ERR_UNEXPECTED is returned. | 55 // there is no in-flight operation, net::ERR_UNEXPECTED is returned. |
43 // Otherwise, net::ERR_IO_PENDING is returned, and the callback will be run on | 56 // Otherwise, net::ERR_IO_PENDING is returned, and the callback will be run on |
44 // the thread where Cancel() was called when the cancel has completed. It is | 57 // the thread where Cancel() was called when the cancel has completed. It is |
45 // invalid to call Cancel() more than once on the same async operation. | 58 // invalid to call Cancel() more than once on the same async operation. |
46 // | 59 // |
47 // In either case, the callback function passed to the in-flight async | 60 // In either case, the callback function passed to the in-flight async |
48 // operation is dismissed immediately when Cancel() is called, and thus | 61 // operation is dismissed immediately when Cancel() is called, and thus |
49 // will never be called. | 62 // will never be called. |
50 virtual int Cancel(const net::CompletionCallback& callback) = 0; | 63 virtual int Cancel(const net::CompletionCallback& callback) = 0; |
51 }; | 64 }; |
52 | 65 |
53 } // namespace fileapi | 66 } // namespace fileapi |
54 | 67 |
55 #endif // WEBKIT_FILEAPI_FILE_WRITER_H_ | 68 #endif // WEBKIT_FILEAPI_FILE_WRITER_H_ |
56 | |
OLD | NEW |