| 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_SHARED_IMPL_TRACKED_CALLBACK_H_ | 5 #ifndef PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ |
| 6 #define PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ | 6 #define PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 PP_Resource resource_id() const { return resource_id_; } | 91 PP_Resource resource_id() const { return resource_id_; } |
| 92 | 92 |
| 93 // Returns true if the callback was completed (possibly aborted). | 93 // Returns true if the callback was completed (possibly aborted). |
| 94 bool completed() const { return completed_; } | 94 bool completed() const { return completed_; } |
| 95 | 95 |
| 96 // Returns true if the callback was or should be aborted; this will be the | 96 // Returns true if the callback was or should be aborted; this will be the |
| 97 // case whenever |Abort()| or |PostAbort()| is called before a non-abortive | 97 // case whenever |Abort()| or |PostAbort()| is called before a non-abortive |
| 98 // completion. | 98 // completion. |
| 99 bool aborted() const { return aborted_; } | 99 bool aborted() const { return aborted_; } |
| 100 | 100 |
| 101 // Returns true if this is a blocking callback. |
| 102 bool is_blocking() { |
| 103 return !callback_.func; |
| 104 } |
| 105 |
| 101 // Determines if the given callback is pending. A callback is pending if it | 106 // Determines if the given callback is pending. A callback is pending if it |
| 102 // has not completed and has not been aborted. When receiving a plugin call, | 107 // has not completed and has not been aborted. When receiving a plugin call, |
| 103 // use this to detect if |callback| represents an operation in progress. When | 108 // use this to detect if |callback| represents an operation in progress. When |
| 104 // finishing a plugin call, use this to determine whether to write 'out' | 109 // finishing a plugin call, use this to determine whether to write 'out' |
| 105 // params and Run |callback|. | 110 // params and Run |callback|. |
| 106 // NOTE: an aborted callback has not necessarily completed, so a false result | 111 // NOTE: an aborted callback has not necessarily completed, so a false result |
| 107 // doesn't imply that the callback has completed. | 112 // doesn't imply that the callback has completed. |
| 108 // As a convenience, if |callback| is null, this returns false. | 113 // As a convenience, if |callback| is null, this returns false. |
| 109 static bool IsPending(const scoped_refptr<TrackedCallback>& callback); | 114 static bool IsPending(const scoped_refptr<TrackedCallback>& callback); |
| 110 | 115 |
| 111 // Helper to determine if the given callback is scheduled to run on another | 116 // Helper to determine if the given callback is scheduled to run on another |
| 112 // message loop. | 117 // message loop. |
| 113 static bool IsScheduledToRun(const scoped_refptr<TrackedCallback>& callback); | 118 static bool IsScheduledToRun(const scoped_refptr<TrackedCallback>& callback); |
| 114 | 119 |
| 115 protected: | 120 protected: |
| 116 bool is_blocking() { | |
| 117 return !callback_.func; | |
| 118 } | |
| 119 | |
| 120 bool is_required() { | 121 bool is_required() { |
| 121 return (callback_.func && | 122 return (callback_.func && |
| 122 !(callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL)); | 123 !(callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL)); |
| 123 } | 124 } |
| 124 bool is_optional() { | 125 bool is_optional() { |
| 125 return (callback_.func && | 126 return (callback_.func && |
| 126 (callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL)); | 127 (callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL)); |
| 127 } | 128 } |
| 128 bool has_null_target_loop() const { return target_loop_.get() == NULL; } | 129 bool has_null_target_loop() const { return target_loop_.get() == NULL; } |
| 129 | 130 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // callback. Note that in-process, there is no lock, blocking callbacks are | 166 // callback. Note that in-process, there is no lock, blocking callbacks are |
| 166 // not allowed, and therefore this pointer will be NULL. | 167 // not allowed, and therefore this pointer will be NULL. |
| 167 scoped_ptr<base::ConditionVariable> operation_completed_condvar_; | 168 scoped_ptr<base::ConditionVariable> operation_completed_condvar_; |
| 168 | 169 |
| 169 DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback); | 170 DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback); |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 } // namespace ppapi | 173 } // namespace ppapi |
| 173 | 174 |
| 174 #endif // PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ | 175 #endif // PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ |
| OLD | NEW |