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_COMPLETION_CALLBACK_H_ | 5 #ifndef PPAPI_CPP_COMPLETION_CALLBACK_H_ |
6 #define PPAPI_CPP_COMPLETION_CALLBACK_H_ | 6 #define PPAPI_CPP_COMPLETION_CALLBACK_H_ |
7 | 7 |
8 #include "ppapi/c/pp_completion_callback.h" | 8 #include "ppapi/c/pp_completion_callback.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/cpp/logging.h" | 10 #include "ppapi/cpp/logging.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 /// IsOptional() is used to determine the setting of the | 92 /// IsOptional() is used to determine the setting of the |
93 /// <code>PP_COMPLETIONCALLBACK_FLAG_OPTIONAL</code> flag. This flag allows | 93 /// <code>PP_COMPLETIONCALLBACK_FLAG_OPTIONAL</code> flag. This flag allows |
94 /// any method taking such callback to complete synchronously | 94 /// any method taking such callback to complete synchronously |
95 /// and not call the callback if the operation would not block. This is useful | 95 /// and not call the callback if the operation would not block. This is useful |
96 /// when performance is an issue, and the operation bandwidth should not be | 96 /// when performance is an issue, and the operation bandwidth should not be |
97 /// limited to the processing speed of the message loop. | 97 /// limited to the processing speed of the message loop. |
98 /// | 98 /// |
99 /// On synchronous method completion, the completion result will be returned | 99 /// On synchronous method completion, the completion result will be returned |
100 /// by the method itself. Otherwise, the method will return | 100 /// by the method itself. Otherwise, the method will return |
101 /// PP_OK_COMPLETIONPENDING, and the callback will be invoked asynchronously | 101 /// PP_OK_COMPLETIONPENDING, and the callback will be invoked asynchronously |
102 /// on the main thread of Pepper execution. | 102 /// on the same thread where the PPB method was invoked. |
103 /// | 103 /// |
104 /// @return true if this callback is optional, otherwise false. | 104 /// @return true if this callback is optional, otherwise false. |
105 bool IsOptional() const { | 105 bool IsOptional() const { |
106 return (cc_.func == NULL || | 106 return (cc_.func == NULL || |
107 (cc_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL) != 0); | 107 (cc_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL) != 0); |
108 } | 108 } |
109 | 109 |
110 /// The pp_completion_callback() function returns the underlying | 110 /// The pp_completion_callback() function returns the underlying |
111 /// <code>PP_CompletionCallback</code> | 111 /// <code>PP_CompletionCallback</code> |
112 /// | 112 /// |
(...skipping 30 matching lines...) Expand all Loading... |
143 /// indicates that the callback has already been scheduled. Other | 143 /// indicates that the callback has already been scheduled. Other |
144 /// non-positive values correspond to error codes from | 144 /// non-positive values correspond to error codes from |
145 /// <code>pp_errors.h</code>. Positive values indicate additional information | 145 /// <code>pp_errors.h</code>. Positive values indicate additional information |
146 /// such as bytes read. | 146 /// such as bytes read. |
147 /// | 147 /// |
148 /// @return <code>PP_OK_COMPLETIONPENDING</code> if the callback has been | 148 /// @return <code>PP_OK_COMPLETIONPENDING</code> if the callback has been |
149 /// forced, result parameter otherwise. | 149 /// forced, result parameter otherwise. |
150 int32_t MayForce(int32_t result) const { | 150 int32_t MayForce(int32_t result) const { |
151 if (result == PP_OK_COMPLETIONPENDING || IsOptional()) | 151 if (result == PP_OK_COMPLETIONPENDING || IsOptional()) |
152 return result; | 152 return result; |
| 153 // FIXME(dmichael): Use pp::MessageLoop here once it's out of Dev. |
153 Module::Get()->core()->CallOnMainThread(0, *this, result); | 154 Module::Get()->core()->CallOnMainThread(0, *this, result); |
154 return PP_OK_COMPLETIONPENDING; | 155 return PP_OK_COMPLETIONPENDING; |
155 } | 156 } |
156 | 157 |
157 protected: | 158 protected: |
158 PP_CompletionCallback cc_; | 159 PP_CompletionCallback cc_; |
159 }; | 160 }; |
160 | 161 |
161 /// A CompletionCallbackWithOutput defines a completion callback that | 162 /// A CompletionCallbackWithOutput defines a completion callback that |
162 /// additionally stores a pointer to some output data. Some C++ wrappers | 163 /// additionally stores a pointer to some output data. Some C++ wrappers |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 /// @return A <code>CompletionCallback</code> corresponding to a NULL callback. | 258 /// @return A <code>CompletionCallback</code> corresponding to a NULL callback. |
258 inline CompletionCallback BlockUntilComplete() { | 259 inline CompletionCallback BlockUntilComplete() { |
259 // Note: Explicitly inlined to avoid link errors when included into | 260 // Note: Explicitly inlined to avoid link errors when included into |
260 // ppapi_proxy and ppapi_cpp_objects. | 261 // ppapi_proxy and ppapi_cpp_objects. |
261 return CompletionCallback(); | 262 return CompletionCallback(); |
262 } | 263 } |
263 | 264 |
264 } // namespace pp | 265 } // namespace pp |
265 | 266 |
266 #endif // PPAPI_CPP_COMPLETION_CALLBACK_H_ | 267 #endif // PPAPI_CPP_COMPLETION_CALLBACK_H_ |
OLD | NEW |