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, it will not issue the callback on your | |
105 /// class if it goes out of scope, BUT the callback factory can NOT cancel | |
bbudge
2012/10/12 01:27:06
This sentance is hard to understand, as 'it' is am
| |
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 from that class and never make | |
112 /// any copies, this will be fine: the resource will be destroyed when your | |
113 /// class is. But keep in mind that copying a pp::FileIO object just | |
114 /// creates a second reference to the original resource and the resource | |
115 /// (and any pending Read calls) will still be pending. This creates the | |
116 /// possibility for writing into invalid memory. | |
bbudge
2012/10/12 01:27:06
I may lack some understanding here. I get how the
| |
89 /// | 117 /// |
90 /// @param[in] offset The offset into the file. | 118 /// @param[in] offset The offset into the file. |
91 /// @param[in] buffer The buffer to hold the specified number of bytes read. | 119 /// @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 | 120 /// @param[in] bytes_to_read The number of bytes to read from |
93 /// <code>offset</code>. | 121 /// <code>offset</code>. |
94 /// @param[in] cc A <code>CompletionCallback</code> to be called upon | 122 /// @param[in] cc A <code>CompletionCallback</code> to be called upon |
95 /// completion of Read(). | 123 /// completion of Read(). |
96 /// | 124 /// |
97 /// @return An The number of bytes read an error code from | 125 /// @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 | 126 /// <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 /// | 179 /// |
152 /// <strong>Note:</strong> If the FileIO object is destroyed, and it is still | 180 /// <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 | 181 /// open, then it will be implicitly closed, so you are not required to call |
154 /// Close(). | 182 /// Close(). |
155 void Close(); | 183 void Close(); |
156 }; | 184 }; |
157 | 185 |
158 } // namespace pp | 186 } // namespace pp |
159 | 187 |
160 #endif // PPAPI_CPP_FILE_IO_H_ | 188 #endif // PPAPI_CPP_FILE_IO_H_ |
OLD | NEW |