| 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/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/resource.h" | 10 #include "ppapi/cpp/resource.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 /// So you must ensure that your buffer outlives the FileIO resource. If you | 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 | 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 | 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 | 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 | 114 /// object just creates a second reference to the original resource. For |
| 115 /// example, if you have a function like this: | 115 /// example, if you have a function like this: |
| 116 /// pp::FileIO MyClass::GetFileIO(); | 116 /// pp::FileIO MyClass::GetFileIO(); |
| 117 /// where a copy of your FileIO resource could outlive your class, the | 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 | 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 | 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 | 120 /// keep your FileIO resource and any output buffers tightly controlled in |
| 121 /// the same scope. | 121 /// the same scope. |
| 122 /// | 122 /// |
| 123 /// <strong>Caveat:</strong> This Read() is potentially unsafe if you're using | 123 /// <strong>Caveat:</strong> This Read() is potentially unsafe if you're using |
| 124 /// a CompletionCallbackFactory to scope callbacks to the lifetime of your | 124 /// a CompletionCallbackFactory to scope callbacks to the lifetime of your |
| 125 /// class. When your class goes out of scope, the callback factory will not | 125 /// class. When your class goes out of scope, the callback factory will not |
| 126 /// actually cancel the callback, but will rather just skip issuing the | 126 /// actually cancel the callback, but will rather just skip issuing the |
| 127 /// callback on your class. This means that if the FileIO object outlives | 127 /// callback on your class. This means that if the FileIO object outlives |
| 128 /// your class (if you made a copy saved somewhere else, for example), then | 128 /// your class (if you made a copy saved somewhere else, for example), then |
| 129 /// the browser will still try to write into your buffer when the | 129 /// the browser will still try to write into your buffer when the |
| 130 /// asynchronous read completes, potentially causing a crash. | 130 /// asynchronous read completes, potentially causing a crash. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 /// Close(). | 222 /// Close(). |
| 223 void Close(); | 223 void Close(); |
| 224 | 224 |
| 225 private: | 225 private: |
| 226 struct CallbackData1_0 { | 226 struct CallbackData1_0 { |
| 227 PP_ArrayOutput output; | 227 PP_ArrayOutput output; |
| 228 char* temp_buffer; | 228 char* temp_buffer; |
| 229 PP_CompletionCallback original_callback; | 229 PP_CompletionCallback original_callback; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 // Provide backwards-compatability for older Read versions. Converts the | 232 // Provide backwards-compatibility for older Read versions. Converts the |
| 233 // old-style "char*" output buffer of 1.0 to the new "PP_ArrayOutput" | 233 // old-style "char*" output buffer of 1.0 to the new "PP_ArrayOutput" |
| 234 // interface in 1.1. | 234 // interface in 1.1. |
| 235 // | 235 // |
| 236 // This takes a heap-allocated CallbackData1_0 struct passed as the user data | 236 // This takes a heap-allocated CallbackData1_0 struct passed as the user data |
| 237 // and deletes it when the call completes. | 237 // and deletes it when the call completes. |
| 238 static void CallbackConverter(void* user_data, int32_t result); | 238 static void CallbackConverter(void* user_data, int32_t result); |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 } // namespace pp | 241 } // namespace pp |
| 242 | 242 |
| 243 #endif // PPAPI_CPP_FILE_IO_H_ | 243 #endif // PPAPI_CPP_FILE_IO_H_ |
| OLD | NEW |