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 | 5 |
6 /** | 6 /** |
7 * This file defines the API to create and run a callback. | 7 * This file defines the API to create and run a callback. |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 * <code>PP_CompletionCallback</code> is a common mechanism for supporting | 63 * <code>PP_CompletionCallback</code> is a common mechanism for supporting |
64 * potentially asynchronous calls in browser interfaces. Any method that takes a | 64 * potentially asynchronous calls in browser interfaces. Any method that takes a |
65 * <code>PP_CompletionCallback</code> can be used in one of three different | 65 * <code>PP_CompletionCallback</code> can be used in one of three different |
66 * ways: | 66 * ways: |
67 * - Required: The callback will always be invoked asynchronously on the | 67 * - Required: The callback will always be invoked asynchronously on the |
68 * thread where the associated PPB method was invoked. The method | 68 * thread where the associated PPB method was invoked. The method |
69 * will always return PP_OK_COMPLETIONPENDING when a required | 69 * will always return PP_OK_COMPLETIONPENDING when a required |
70 * callback, and the callback will be invoked later (barring | 70 * callback, and the callback will be invoked later (barring |
71 * system or thread shutdown; see PPB_MessageLoop for details). | 71 * system or thread shutdown; see PPB_MessageLoop for details). |
72 * Required callbacks are the default. | 72 * Required callbacks are the default. |
73 * | 73 * <br /><br /> |
74 * NOTE: If you use a required callback on a background thread, | 74 * NOTE: If you use a required callback on a background thread, |
75 * you must have created and attached a PPB_MessageLoop. | 75 * you must have created and attached a PPB_MessageLoop. |
76 * Otherwise, the system can not run your callback on that thread, | 76 * Otherwise, the system can not run your callback on that thread, |
77 * and will instead emit a log message and crash your plugin to | 77 * and will instead emit a log message and crash your plugin to |
78 * make the problem more obvious. | 78 * make the problem more obvious. |
79 * | 79 * |
80 * - Optional: The callback may be invoked asynchronously, or the PPB method | 80 * - Optional: The callback may be invoked asynchronously, or the PPB method |
81 * may complete synchronously if it can do so without blocking. | 81 * may complete synchronously if it can do so without blocking. |
82 * If the method will complete asynchronously, it will return | 82 * If the method will complete asynchronously, it will return |
83 * PP_OK_COMPLETIONPENDING. Otherwise, it will complete | 83 * PP_OK_COMPLETIONPENDING. Otherwise, it will complete |
84 * synchronously and return an appropriate code (see below for | 84 * synchronously and return an appropriate code (see below for |
85 * more information on the return code). Optional callbacks are | 85 * more information on the return code). Optional callbacks are |
86 * generally more difficult to use correctly than Required | 86 * generally more difficult to use correctly than Required |
87 * callbacks, but can provide better performance for some APIs | 87 * callbacks, but can provide better performance for some APIs |
88 * (especially APIs with buffered reads, such as PPB_URLLoader or | 88 * (especially APIs with buffered reads, such as PPB_URLLoader or |
89 * PPB_FileIO). | 89 * PPB_FileIO). |
90 * | 90 * <br /><br /> |
91 * NOTE: If you use an optional callback on a background thread, | 91 * NOTE: If you use an optional callback on a background thread, |
92 * and you have not created and attached a PPB_MessageLoop, then | 92 * and you have not created and attached a PPB_MessageLoop, then |
93 * the method you invoke will fail without running and return | 93 * the method you invoke will fail without running and return |
94 * PP_ERROR_NO_MESSAGE_LOOP. | 94 * PP_ERROR_NO_MESSAGE_LOOP. |
95 * | 95 * |
96 * - Blocking: In this case, the callback's function pointer is NULL, and the | 96 * - Blocking: In this case, the callback's function pointer is NULL, and the |
97 * invoked method must complete synchronously. The method will | 97 * invoked method must complete synchronously. The method will |
98 * run to completion and return an appropriate code when finished | 98 * run to completion and return an appropriate code when finished |
99 * (see below for more information). Blocking completion | 99 * (see below for more information). Blocking completion |
100 * callbacks are only supported on background threads. | 100 * callbacks are only supported on background threads. |
101 * | 101 * <br /><br /> |
102 * <code>PP_BlockUntilComplete()</code> provides a convenient way | 102 * <code>PP_BlockUntilComplete()</code> provides a convenient way |
103 * to specify blocking behavior. Refer to | 103 * to specify blocking behavior. Refer to |
104 * <code>PP_BlockUntilComplete</code> for more information. | 104 * <code>PP_BlockUntilComplete</code> for more information. |
105 * | 105 * |
106 * When the callback is run asynchronously, the result parameter passed to | 106 * When the callback is run asynchronously, the result parameter passed to |
107 * <code>func</code> is an int32_t that, if negative indicates an error code | 107 * <code>func</code> is an int32_t that, if negative indicates an error code |
108 * whose meaning is specific to the calling method (refer to | 108 * whose meaning is specific to the calling method (refer to |
109 * <code>pp_error.h</code> for further information). A positive or 0 value is a | 109 * <code>pp_error.h</code> for further information). A positive or 0 value is a |
110 * return result indicating success whose meaning depends on the calling method | 110 * return result indicating success whose meaning depends on the calling method |
111 * (e.g. number of bytes read). | 111 * (e.g. number of bytes read). |
112 */ | 112 */ |
113 [passByValue] struct PP_CompletionCallback { | 113 [passByValue] struct PP_CompletionCallback { |
114 /** | 114 /** |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 struct PP_CompletionCallback temp = *cc; | 253 struct PP_CompletionCallback temp = *cc; |
254 *cc = PP_BlockUntilComplete(); | 254 *cc = PP_BlockUntilComplete(); |
255 PP_RunCompletionCallback(&temp, res); | 255 PP_RunCompletionCallback(&temp, res); |
256 } | 256 } |
257 /** | 257 /** |
258 * @} | 258 * @} |
259 */ | 259 */ |
260 | 260 |
261 #endinl | 261 #endinl |
262 | 262 |
OLD | NEW |