Chromium Code Reviews| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/synchronization/condition_variable.h" | 15 #include "base/synchronization/condition_variable.h" |
| 15 #include "ppapi/c/pp_completion_callback.h" | 16 #include "ppapi/c/pp_completion_callback.h" |
| 16 #include "ppapi/c/pp_instance.h" | 17 #include "ppapi/c/pp_instance.h" |
| 17 #include "ppapi/c/pp_resource.h" | 18 #include "ppapi/c/pp_resource.h" |
| 18 #include "ppapi/shared_impl/ppapi_shared_export.h" | 19 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 19 #include "ppapi/shared_impl/ppb_message_loop_shared.h" | 20 #include "ppapi/shared_impl/ppb_message_loop_shared.h" |
| 20 | 21 |
| 21 namespace ppapi { | 22 namespace ppapi { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 // | 78 // |
| 78 // Run() will invoke the call immediately, if invoked from the target thread | 79 // Run() will invoke the call immediately, if invoked from the target thread |
| 79 // (as determined by target_loop_). If invoked on a different thread, the | 80 // (as determined by target_loop_). If invoked on a different thread, the |
| 80 // callback will be scheduled to run later on target_loop_. | 81 // callback will be scheduled to run later on target_loop_. |
| 81 void Run(int32_t result); | 82 void Run(int32_t result); |
| 82 // PostRun is like Run(), except it guarantees that the callback will be run | 83 // PostRun is like Run(), except it guarantees that the callback will be run |
| 83 // later. In particular, if you invoke PostRun on the same thread on which the | 84 // later. In particular, if you invoke PostRun on the same thread on which the |
| 84 // callback is targeted to run, it will *not* be run immediately. | 85 // callback is targeted to run, it will *not* be run immediately. |
| 85 void PostRun(int32_t result); | 86 void PostRun(int32_t result); |
| 86 | 87 |
| 87 void BlockUntilRun(); | 88 // Task to perform any cleanup or output before calling back into the plugin. |
|
bbudge
2013/08/07 21:01:54
I should add more comments here:
// Task to perfor
teravest
2013/08/08 16:49:52
Sounds good.
| |
| 89 typedef base::Callback<int32_t(int32_t /* result */)> CompletionTask; | |
| 90 | |
| 91 // Sets a task that is run just before calling back into the plugin. This can | |
| 92 // only be called once. | |
| 93 void SetCompletionTask(const CompletionTask& completion_task); | |
|
yzshen1
2013/08/07 21:09:10
nit: I think it should be named set_completion_tas
bbudge
2013/08/08 18:34:00
Done.
| |
| 88 | 94 |
| 89 // Returns the ID of the resource which "owns" the callback, or 0 if the | 95 // Returns the ID of the resource which "owns" the callback, or 0 if the |
| 90 // callback is not associated with any resource. | 96 // callback is not associated with any resource. |
| 91 PP_Resource resource_id() const { return resource_id_; } | 97 PP_Resource resource_id() const { return resource_id_; } |
| 92 | 98 |
| 93 // Returns true if the callback was completed (possibly aborted). | 99 // Returns true if the callback was completed (possibly aborted). |
| 94 bool completed() const { return completed_; } | 100 bool completed() const { return completed_; } |
| 95 | 101 |
| 96 // Returns true if the callback was or should be aborted; this will be the | 102 // 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 | 103 // case whenever |Abort()| or |PostAbort()| is called before a non-abortive |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 141 |
| 136 // Block until the associated operation has completed. Returns the result. | 142 // Block until the associated operation has completed. Returns the result. |
| 137 // This must only be called on a non-main thread on a blocking callback. | 143 // This must only be called on a non-main thread on a blocking callback. |
| 138 int32_t BlockUntilComplete(); | 144 int32_t BlockUntilComplete(); |
| 139 | 145 |
| 140 // Mark this object as complete and remove it from the tracker. This must only | 146 // Mark this object as complete and remove it from the tracker. This must only |
| 141 // be called once. Note that running this may result in this object being | 147 // be called once. Note that running this may result in this object being |
| 142 // deleted (so keep a reference if it'll still be needed). | 148 // deleted (so keep a reference if it'll still be needed). |
| 143 void MarkAsCompleted(); | 149 void MarkAsCompleted(); |
| 144 | 150 |
| 151 int32_t RunCompletionTask(int32_t result); | |
| 152 | |
| 145 // This class is ref counted. | 153 // This class is ref counted. |
| 146 friend class base::RefCountedThreadSafe<TrackedCallback>; | 154 friend class base::RefCountedThreadSafe<TrackedCallback>; |
| 147 virtual ~TrackedCallback(); | 155 virtual ~TrackedCallback(); |
| 148 | 156 |
| 149 // Flag used by |PostAbort()| and |PostRun()| to check that we don't schedule | 157 // Flag used by |PostAbort()| and |PostRun()| to check that we don't schedule |
| 150 // the callback more than once. | 158 // the callback more than once. |
| 151 bool is_scheduled_; | 159 bool is_scheduled_; |
| 152 | 160 |
| 153 scoped_refptr<CallbackTracker> tracker_; | 161 scoped_refptr<CallbackTracker> tracker_; |
| 154 PP_Resource resource_id_; | 162 PP_Resource resource_id_; |
| 155 bool completed_; | 163 bool completed_; |
| 156 bool aborted_; | 164 bool aborted_; |
| 157 PP_CompletionCallback callback_; | 165 PP_CompletionCallback callback_; |
| 158 | 166 |
| 167 // Task to run just before calling back into the plugin. | |
| 168 CompletionTask completion_task_; | |
| 169 | |
| 159 // The MessageLoopShared on which this callback should be run. This will be | 170 // The MessageLoopShared on which this callback should be run. This will be |
| 160 // NULL if we're in-process. | 171 // NULL if we're in-process. |
| 161 scoped_refptr<MessageLoopShared> target_loop_; | 172 scoped_refptr<MessageLoopShared> target_loop_; |
| 162 | 173 |
| 163 int32_t result_for_blocked_callback_; | 174 int32_t result_for_blocked_callback_; |
| 164 // Used for pausing/waking the blocked thread if this is a blocking completion | 175 // Used for pausing/waking the blocked thread if this is a blocking completion |
| 165 // callback. Note that in-process, there is no lock, blocking callbacks are | 176 // callback. Note that in-process, there is no lock, blocking callbacks are |
| 166 // not allowed, and therefore this pointer will be NULL. | 177 // not allowed, and therefore this pointer will be NULL. |
| 167 scoped_ptr<base::ConditionVariable> operation_completed_condvar_; | 178 scoped_ptr<base::ConditionVariable> operation_completed_condvar_; |
| 168 | 179 |
| 169 DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback); | 180 DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback); |
| 170 }; | 181 }; |
| 171 | 182 |
| 172 } // namespace ppapi | 183 } // namespace ppapi |
| 173 | 184 |
| 174 #endif // PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ | 185 #endif // PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ |
| OLD | NEW |