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 PPAPI_CPP_FILE_IO_H_ | 5 #ifndef PPAPI_CPP_FILE_IO_H_ |
6 #define PPAPI_CPP_FILE_IO_H_ | 6 #define PPAPI_CPP_FILE_IO_H_ |
7 | 7 |
8 #include "ppapi/c/pp_time.h" | 8 #include "ppapi/c/pp_time.h" |
9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 /// @param[in] other A pointer to a <code>FileIO</code>. | 38 /// @param[in] other A pointer to a <code>FileIO</code>. |
39 FileIO(const FileIO& other); | 39 FileIO(const FileIO& other); |
40 | 40 |
41 /// Open() opens the specified regular file for I/O according to the given | 41 /// Open() opens the specified regular file for I/O according to the given |
42 /// open flags, which is a bit-mask of the PP_FileOpenFlags values. Upon | 42 /// open flags, which is a bit-mask of the PP_FileOpenFlags values. Upon |
43 /// success, the corresponding file is classified as "in use" by this FileIO | 43 /// success, the corresponding file is classified as "in use" by this FileIO |
44 /// object until such time as the FileIO object is closed or destroyed. | 44 /// object until such time as the FileIO object is closed or destroyed. |
45 /// | 45 /// |
46 /// @param[in] file_ref A <code>PP_Resource</code> corresponding to a file | 46 /// @param[in] file_ref A <code>PP_Resource</code> corresponding to a file |
47 /// reference. | 47 /// reference. |
| 48 /// |
48 /// @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> | 49 /// @param[in] open_flags A bit-mask of the <code>PP_FileOpenFlags</code> |
49 /// values. | 50 /// values. Valid values are: |
| 51 /// - PP_FILEOPENFLAG_READ |
| 52 /// - PP_FILEOPENFLAG_WRITE |
| 53 /// - PP_FILEOPENFLAG_CREATE |
| 54 /// - PP_FILEOPENFLAG_TRUNCATE |
| 55 /// - PP_FILEOPENFLAG_EXCLUSIVE |
| 56 /// See <code>PP_FileOpenFlags</code> in <code>ppb_file_io.h</code> for more |
| 57 /// details on these flags. |
| 58 /// |
50 /// @param[in] cc A <code>CompletionCallback</code> to be called upon | 59 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
51 /// completion of Open(). | 60 /// completion of Open(). |
52 /// | 61 /// |
53 /// @return An int32_t containing an error code from | 62 /// @return An int32_t containing an error code from |
54 /// <code>pp_errors.h</code>. | 63 /// <code>pp_errors.h</code>. |
55 int32_t Open(const FileRef& file_ref, | 64 int32_t Open(const FileRef& file_ref, |
56 int32_t open_flags, | 65 int32_t open_flags, |
57 const CompletionCallback& cc); | 66 const CompletionCallback& cc); |
58 | 67 |
59 /// Query() queries info about the file opened by this FileIO object. This | 68 /// Query() queries info about the file opened by this FileIO object. This |
(...skipping 16 matching lines...) Expand all Loading... |
76 /// @param[in] last_modified_time The last time the FileIO was modified. | 85 /// @param[in] last_modified_time The last time the FileIO was modified. |
77 /// @param[in] cc A <code>CompletionCallback</code> to be called upon | 86 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
78 /// completion of Touch(). | 87 /// completion of Touch(). |
79 /// | 88 /// |
80 /// @return An int32_t containing an error code from | 89 /// @return An int32_t containing an error code from |
81 /// <code>pp_errors.h</code>. | 90 /// <code>pp_errors.h</code>. |
82 int32_t Touch(PP_Time last_access_time, | 91 int32_t Touch(PP_Time last_access_time, |
83 PP_Time last_modified_time, | 92 PP_Time last_modified_time, |
84 const CompletionCallback& cc); | 93 const CompletionCallback& cc); |
85 | 94 |
86 /// Read() reads from an offset in the file. The size of the buffer must be | 95 /// Reads from an offset in the file. |
87 /// large enough to hold the specified number of bytes to read. This | 96 /// |
88 /// function might perform a partial read. | 97 /// The size of the buffer must be large enough to hold the specified number |
| 98 /// of bytes to read. This function might perform a partial read, meaning |
| 99 /// that all the requested bytes might not be returned, even if the end of the |
| 100 /// file has not been reached. |
| 101 /// |
| 102 /// This function reads into a buffer that the caller supplies. This buffer |
| 103 /// must remain valid as long as the FileIO resource is alive. If you use |
| 104 /// a completion callback factory and it goes out of scope, it will not issue |
| 105 /// the callback on your class, BUT the callback factory can NOT cancel |
| 106 /// the request from the browser's perspective. This means that the browser |
| 107 /// will still try to write to your buffer even if the callback factory is |
| 108 /// destroyed! |
| 109 /// |
| 110 /// So you must ensure that your buffer outlives the FileIO resource. If you |
| 111 /// have one class and use the FileIO resource exclusively from that class |
| 112 /// and never make any copies, this will be fine: the resource will be |
| 113 /// destroyed when your class is. But keep in mind that copying a pp::FileIO |
| 114 /// object just creates a second reference to the original resource. For |
| 115 /// example, if you have a function like this: |
| 116 /// pp::FileIO MyClass::GetFileIO(); |
| 117 /// where a copy of your FileIO resource could outlive your class, the |
| 118 /// callback will still be pending when your class goes out of scope, creating |
| 119 /// the possibility of writing into invalid memory. So it's recommended to |
| 120 /// keep your FileIO resource and any oubput buffers tightly controlled in |
| 121 /// the same scope. |
89 /// | 122 /// |
90 /// @param[in] offset The offset into the file. | 123 /// @param[in] offset The offset into the file. |
91 /// @param[in] buffer The buffer to hold the specified number of bytes read. | 124 /// @param[in] buffer The buffer to hold the specified number of bytes read. |
92 /// @param[in] bytes_to_read The number of bytes to read from | 125 /// @param[in] bytes_to_read The number of bytes to read from |
93 /// <code>offset</code>. | 126 /// <code>offset</code>. |
94 /// @param[in] cc A <code>CompletionCallback</code> to be called upon | 127 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
95 /// completion of Read(). | 128 /// completion of Read(). |
96 /// | 129 /// |
97 /// @return An The number of bytes read an error code from | 130 /// @return An The number of bytes read an error code from |
98 /// <code>pp_errors.h</code>. If the return value is 0, then end-of-file was | 131 /// <code>pp_errors.h</code>. If the return value is 0, then end-of-file was |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 /// | 184 /// |
152 /// <strong>Note:</strong> If the FileIO object is destroyed, and it is still | 185 /// <strong>Note:</strong> If the FileIO object is destroyed, and it is still |
153 /// open, then it will be implicitly closed, so you are not required to call | 186 /// open, then it will be implicitly closed, so you are not required to call |
154 /// Close(). | 187 /// Close(). |
155 void Close(); | 188 void Close(); |
156 }; | 189 }; |
157 | 190 |
158 } // namespace pp | 191 } // namespace pp |
159 | 192 |
160 #endif // PPAPI_CPP_FILE_IO_H_ | 193 #endif // PPAPI_CPP_FILE_IO_H_ |
OLD | NEW |