OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 /// @return An int32_t containing a bit field combination of | 106 /// @return An int32_t containing a bit field combination of |
107 /// <code>PP_CompletionCallback_Flag</code> flags. | 107 /// <code>PP_CompletionCallback_Flag</code> flags. |
108 int32_t flags() const { return cc_.flags; } | 108 int32_t flags() const { return cc_.flags; } |
109 | 109 |
110 /// MayForce() is used when implementing functions taking callbacks. | 110 /// MayForce() is used when implementing functions taking callbacks. |
111 /// If the callback is required and <code>result</code> indicates that it has | 111 /// If the callback is required and <code>result</code> indicates that it has |
112 /// not been scheduled, it will be forced on the main thread. | 112 /// not been scheduled, it will be forced on the main thread. |
113 /// | 113 /// |
114 /// <strong>Example:</strong> | 114 /// <strong>Example:</strong> |
115 /// | 115 /// |
116 /// @code | 116 /// <code> |
117 /// | 117 /// |
118 /// int32_t OpenURL(pp::URLLoader* loader, | 118 /// int32_t OpenURL(pp::URLLoader* loader, |
119 /// pp::URLRequestInfo* url_request_info, | 119 /// pp::URLRequestInfo* url_request_info, |
120 /// const CompletionCallback& cc) { | 120 /// const CompletionCallback& cc) { |
121 /// if (loader == NULL || url_request_info == NULL) | 121 /// if (loader == NULL || url_request_info == NULL) |
122 /// return cc.MayForce(PP_ERROR_BADRESOURCE); | 122 /// return cc.MayForce(PP_ERROR_BADRESOURCE); |
123 /// return loader->Open(*loader, *url_request_info, cc); | 123 /// return loader->Open(*loader, *url_request_info, cc); |
124 /// } | 124 /// } |
125 /// | 125 /// |
126 /// @endcode | 126 /// </code> |
127 /// | 127 /// |
128 /// @param[in] result PP_OK_COMPLETIONPENDING or the result of the completed | 128 /// @param[in] result PP_OK_COMPLETIONPENDING or the result of the completed |
129 /// operation to be passed to the callback function. PP_OK_COMPLETIONPENDING | 129 /// operation to be passed to the callback function. PP_OK_COMPLETIONPENDING |
130 /// indicates that the callback has already been scheduled. Other | 130 /// indicates that the callback has already been scheduled. Other |
131 /// non-positive values correspond to error codes from | 131 /// non-positive values correspond to error codes from |
132 /// <code>pp_errors.h</code>. Positive values indicate additional information | 132 /// <code>pp_errors.h</code>. Positive values indicate additional information |
133 /// such as bytes read. | 133 /// such as bytes read. |
134 /// | 134 /// |
135 /// @return <code>PP_OK_COMPLETIONPENDING</code> if the callback has been | 135 /// @return <code>PP_OK_COMPLETIONPENDING</code> if the callback has been |
136 /// forced, result parameter otherwise. | 136 /// forced, result parameter otherwise. |
(...skipping 28 matching lines...) Expand all Loading... |
165 /// thread safe, but you can make it more thread-friendly by passing a | 165 /// thread safe, but you can make it more thread-friendly by passing a |
166 /// thread-safe refcounting class as the second template element. However, it | 166 /// thread-safe refcounting class as the second template element. However, it |
167 /// only guarantees safety for creating a callback from another thread, the | 167 /// only guarantees safety for creating a callback from another thread, the |
168 /// callback itself needs to execute on the same thread as the thread that | 168 /// callback itself needs to execute on the same thread as the thread that |
169 /// creates/destroys the factory. With this restriction, it is safe to create | 169 /// creates/destroys the factory. With this restriction, it is safe to create |
170 /// the <code>CompletionCallbackFactory</code> on the main thread, create | 170 /// the <code>CompletionCallbackFactory</code> on the main thread, create |
171 /// callbacks from any thread and pass them to CallOnMainThread(). | 171 /// callbacks from any thread and pass them to CallOnMainThread(). |
172 /// | 172 /// |
173 /// <strong>Example: </strong> | 173 /// <strong>Example: </strong> |
174 /// | 174 /// |
175 /// @code | 175 /// <code> |
176 /// | 176 /// |
177 /// class MyHandler { | 177 /// class MyHandler { |
178 /// public: | 178 /// public: |
179 /// MyHandler() : factory_(this), offset_(0) { | 179 /// MyHandler() : factory_(this), offset_(0) { |
180 /// } | 180 /// } |
181 /// | 181 /// |
182 /// void ProcessFile(const FileRef& file) { | 182 /// void ProcessFile(const FileRef& file) { |
183 /// CompletionCallback cc = factory_.NewRequiredCallback( | 183 /// CompletionCallback cc = factory_.NewRequiredCallback( |
184 /// &MyHandler::DidOpen); | 184 /// &MyHandler::DidOpen); |
185 /// int32_t rv = fio_.Open(file, PP_FileOpenFlag_Read, cc); | 185 /// int32_t rv = fio_.Open(file, PP_FileOpenFlag_Read, cc); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 /// void ProcessBytes(const char* bytes, int32_t length) { | 224 /// void ProcessBytes(const char* bytes, int32_t length) { |
225 /// // Do work ... | 225 /// // Do work ... |
226 /// } | 226 /// } |
227 /// | 227 /// |
228 /// pp::CompletionCallbackFactory<MyHandler> factory_; | 228 /// pp::CompletionCallbackFactory<MyHandler> factory_; |
229 /// pp::FileIO fio_; | 229 /// pp::FileIO fio_; |
230 /// char buf_[4096]; | 230 /// char buf_[4096]; |
231 /// int64_t offset_; | 231 /// int64_t offset_; |
232 /// }; | 232 /// }; |
233 /// | 233 /// |
234 /// @endcode | 234 /// </code> |
235 /// | 235 /// |
236 template <typename T, typename RefCount = NonThreadSafeRefCount> | 236 template <typename T, typename RefCount = NonThreadSafeRefCount> |
237 class CompletionCallbackFactory { | 237 class CompletionCallbackFactory { |
238 public: | 238 public: |
239 | 239 |
240 /// This constructor creates a <code>CompletionCallbackFactory</code> | 240 /// This constructor creates a <code>CompletionCallbackFactory</code> |
241 /// bound to an object. If the constructor is called without an argument, | 241 /// bound to an object. If the constructor is called without an argument, |
242 /// the default value of <code>NULL</code> is used. The user then must call | 242 /// the default value of <code>NULL</code> is used. The user then must call |
243 /// Initialize() to initialize the object. | 243 /// Initialize() to initialize the object. |
244 /// | 244 /// |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 CompletionCallbackFactory(const CompletionCallbackFactory&); | 590 CompletionCallbackFactory(const CompletionCallbackFactory&); |
591 CompletionCallbackFactory& operator=(const CompletionCallbackFactory&); | 591 CompletionCallbackFactory& operator=(const CompletionCallbackFactory&); |
592 | 592 |
593 T* object_; | 593 T* object_; |
594 BackPointer* back_pointer_; | 594 BackPointer* back_pointer_; |
595 }; | 595 }; |
596 | 596 |
597 } // namespace pp | 597 } // namespace pp |
598 | 598 |
599 #endif // PPAPI_CPP_COMPLETION_CALLBACK_H_ | 599 #endif // PPAPI_CPP_COMPLETION_CALLBACK_H_ |
OLD | NEW |