| 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_MESSAGE_LOOP_H_ | 5 #ifndef PPAPI_CPP_MESSAGE_LOOP_H_ |
| 6 #define PPAPI_CPP_MESSAGE_LOOP_H_ | 6 #define PPAPI_CPP_MESSAGE_LOOP_H_ |
| 7 | 7 |
| 8 #include "ppapi/cpp/resource.h" | 8 #include "ppapi/cpp/resource.h" |
| 9 | 9 |
| 10 namespace pp { | 10 namespace pp { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 /// callback. This is true even for callbacks with the "required" flag set, | 111 /// callback. This is true even for callbacks with the "required" flag set, |
| 112 /// since the system may not even know what thread to issue the error callback | 112 /// since the system may not even know what thread to issue the error callback |
| 113 /// on. | 113 /// on. |
| 114 /// | 114 /// |
| 115 /// Therefore, you should check for errors from PostWork and destroy any | 115 /// Therefore, you should check for errors from PostWork and destroy any |
| 116 /// associated memory to avoid leaks. If you're using the C++ | 116 /// associated memory to avoid leaks. If you're using the C++ |
| 117 /// CompletionCallbackFactory, use the following pattern: | 117 /// CompletionCallbackFactory, use the following pattern: |
| 118 /// | 118 /// |
| 119 /// pp::CompletionCallback callback = factory_.NewOptionalCallback(...); | 119 /// pp::CompletionCallback callback = factory_.NewOptionalCallback(...); |
| 120 /// int32_t result = message_loop.PostWork(callback); | 120 /// int32_t result = message_loop.PostWork(callback); |
| 121 /// if (result != PP_OK_COMPLETIONPENDING) | 121 /// if (result != PP_OK) |
| 122 /// callback.Run(result); | 122 /// callback.Run(result); |
| 123 /// | 123 /// |
| 124 /// This will run the callback with an error value, and assumes that the | 124 /// This will run the callback with an error value, and assumes that the |
| 125 /// implementation of your callback checks the "result" argument and returns | 125 /// implementation of your callback checks the "result" argument and returns |
| 126 /// immediately on error. | 126 /// immediately on error. |
| 127 class MessageLoop : public Resource { | 127 class MessageLoop : public Resource { |
| 128 public: | 128 public: |
| 129 /// Creates an is_null() MessageLoop resource. | 129 /// Creates an is_null() MessageLoop resource. |
| 130 MessageLoop(); | 130 MessageLoop(); |
| 131 | 131 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 /// free this or manually run the callback. See "Desctruction and error | 217 /// free this or manually run the callback. See "Desctruction and error |
| 218 /// handling" above. | 218 /// handling" above. |
| 219 /// | 219 /// |
| 220 /// | 220 /// |
| 221 /// You can call this function before the message loop has started and the | 221 /// You can call this function before the message loop has started and the |
| 222 /// work will get queued until the message loop is run. You can also post | 222 /// work will get queued until the message loop is run. You can also post |
| 223 /// work after the message loop has exited as long as should_destroy was | 223 /// work after the message loop has exited as long as should_destroy was |
| 224 /// PP_FALSE. It will be queued until the next invocation of Run(). | 224 /// PP_FALSE. It will be queued until the next invocation of Run(). |
| 225 /// | 225 /// |
| 226 /// @return | 226 /// @return |
| 227 /// - PP_OK_COMPLETIONPENDING: The work was posted to the message loop's | 227 /// - PP_OK: The work was posted to the message loop's queue. As described |
| 228 /// queue. As described above, this does not mean that the work has been | 228 /// above, this does not mean that the work has been or will be executed |
| 229 /// or will be executed (if you never run the message loop after posting). | 229 /// (if you never run the message loop after posting). |
| 230 /// - PP_ERROR_BADRESOURCE: The given message loop resource is invalid. | 230 /// - PP_ERROR_BADRESOURCE: The given message loop resource is invalid. |
| 231 /// - PP_ERROR_BADARGUMENT: The function pointer for the completion callback | 231 /// - PP_ERROR_BADARGUMENT: The function pointer for the completion callback |
| 232 /// is null (this will be the case if you pass PP_BlockUntilComplete()). | 232 /// is null (this will be the case if you pass PP_BlockUntilComplete()). |
| 233 /// - PP_ERROR_FAILED: The message loop has been destroyed. | 233 /// - PP_ERROR_FAILED: The message loop has been destroyed. |
| 234 int32_t PostWork(const CompletionCallback& callback, | 234 int32_t PostWork(const CompletionCallback& callback, |
| 235 int64_t delay_ms = 0); | 235 int64_t delay_ms = 0); |
| 236 | 236 |
| 237 /// Posts a quit message to the given message loop's work queue. Work posted | 237 /// Posts a quit message to the given message loop's work queue. Work posted |
| 238 /// before that point will be processed before quitting. | 238 /// before that point will be processed before quitting. |
| 239 /// | 239 /// |
| (...skipping 13 matching lines...) Expand all Loading... |
| 253 /// - PP_ERROR_BADRESOURCE: The message loop was invalid. | 253 /// - PP_ERROR_BADRESOURCE: The message loop was invalid. |
| 254 /// - PP_ERROR_WRONG_THREAD: You are attempting to quit the main thread. | 254 /// - PP_ERROR_WRONG_THREAD: You are attempting to quit the main thread. |
| 255 /// The main thread's message loop is managed by the system and can't be | 255 /// The main thread's message loop is managed by the system and can't be |
| 256 /// quit. | 256 /// quit. |
| 257 int32_t PostQuit(bool should_destroy); | 257 int32_t PostQuit(bool should_destroy); |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 } // namespace pp | 260 } // namespace pp |
| 261 | 261 |
| 262 #endif // PPAPI_CPP_MESSAGE_LOOP_H_ | 262 #endif // PPAPI_CPP_MESSAGE_LOOP_H_ |
| OLD | NEW |