Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: ppapi/shared_impl/tracked_callback.h

Issue 10910099: PPAPI: Make CompletionCallbacks work right on background threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ppb_message_loop_shared.cc/.h Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/condition_variable.h" 14 #include "base/synchronization/condition_variable.h"
15 #include "ppapi/c/pp_completion_callback.h" 15 #include "ppapi/c/pp_completion_callback.h"
16 #include "ppapi/c/pp_instance.h" 16 #include "ppapi/c/pp_instance.h"
17 #include "ppapi/c/pp_resource.h" 17 #include "ppapi/c/pp_resource.h"
18 #include "ppapi/shared_impl/ppapi_shared_export.h" 18 #include "ppapi/shared_impl/ppapi_shared_export.h"
19 #include "ppapi/shared_impl/ppb_message_loop_shared.h"
19 20
20 namespace ppapi { 21 namespace ppapi {
21 22
22 class CallbackTracker; 23 class CallbackTracker;
24 class MessageLoopShared;
23 class Resource; 25 class Resource;
24 26
25 namespace thunk { 27 namespace thunk {
26 namespace subtle { 28 namespace subtle {
27 // For a friend declaration below. 29 // For a friend declaration below.
28 class EnterBase; 30 class EnterBase;
29 } 31 }
30 } 32 }
31 33
32 // |TrackedCallback| represents a tracked Pepper callback (from the browser to 34 // |TrackedCallback| represents a tracked Pepper callback (from the browser to
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 void Abort(); 71 void Abort();
70 void PostAbort(); 72 void PostAbort();
71 73
72 // Run the callback with the given result. If the callback had previously been 74 // Run the callback with the given result. If the callback had previously been
73 // marked as to be aborted (by |PostAbort()|), |result| will be ignored and 75 // marked as to be aborted (by |PostAbort()|), |result| will be ignored and
74 // the callback will be run with result |PP_ERROR_ABORTED|. 76 // the callback will be run with result |PP_ERROR_ABORTED|.
75 // 77 //
76 // Run() will invoke the call immediately, if invoked from the target thread 78 // Run() will invoke the call immediately, if invoked from the target thread
77 // (as determined by target_loop_). If invoked on a different thread, the 79 // (as determined by target_loop_). If invoked on a different thread, the
78 // callback will be scheduled to run later on target_loop_. 80 // callback will be scheduled to run later on target_loop_.
79 // TODO(dmichael): Make the above part about different threads actually true.
80 void Run(int32_t result); 81 void Run(int32_t result);
81 // PostRun is like Run(), except it guarantees that the callback will be run 82 // PostRun is like Run(), except it guarantees that the callback will be run
82 // later. In particular, if you invoke PostRun on the same thread on which the 83 // later. In particular, if you invoke PostRun on the same thread on which the
83 // callback is targeted to run, it will *not* be run immediately. 84 // callback is targeted to run, it will *not* be run immediately.
84 void PostRun(int32_t result); 85 void PostRun(int32_t result);
85 86
86 void BlockUntilRun(); 87 void BlockUntilRun();
87 88
88 // Returns the ID of the resource which "owns" the callback, or 0 if the 89 // Returns the ID of the resource which "owns" the callback, or 0 if the
89 // callback is not associated with any resource. 90 // callback is not associated with any resource.
(...skipping 19 matching lines...) Expand all
109 return !callback_.func; 110 return !callback_.func;
110 } 111 }
111 bool is_required() { 112 bool is_required() {
112 return (callback_.func && 113 return (callback_.func &&
113 !(callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL)); 114 !(callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL));
114 } 115 }
115 bool is_optional() { 116 bool is_optional() {
116 return (callback_.func && 117 return (callback_.func &&
117 (callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL)); 118 (callback_.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL));
118 } 119 }
120 bool has_null_target_loop() const {
121 return target_loop_ == NULL;
122 }
119 123
120 private: 124 private:
121 // TrackedCallback and EnterBase manage dealing with how to invoke callbacks 125 // TrackedCallback and EnterBase manage dealing with how to invoke callbacks
122 // appropriately. Pepper interface implementations and proxies should not have 126 // appropriately. Pepper interface implementations and proxies should not have
123 // to check the type of callback, block, or mark them complete explicitly. 127 // to check the type of callback, block, or mark them complete explicitly.
124 friend class ppapi::thunk::subtle::EnterBase; 128 friend class ppapi::thunk::subtle::EnterBase;
125 129
126 // Block until the associated operation has completed. Returns the result. 130 // Block until the associated operation has completed. Returns the result.
127 // This must only be called on a non-main thread on a blocking callback. 131 // This must only be called on a non-main thread on a blocking callback.
128 int32_t BlockUntilComplete(); 132 int32_t BlockUntilComplete();
(...skipping 10 matching lines...) Expand all
139 // Flag used by |PostAbort()| and |PostRun()| to check that we don't schedule 143 // Flag used by |PostAbort()| and |PostRun()| to check that we don't schedule
140 // the callback more than once. 144 // the callback more than once.
141 bool is_scheduled_; 145 bool is_scheduled_;
142 146
143 scoped_refptr<CallbackTracker> tracker_; 147 scoped_refptr<CallbackTracker> tracker_;
144 PP_Resource resource_id_; 148 PP_Resource resource_id_;
145 bool completed_; 149 bool completed_;
146 bool aborted_; 150 bool aborted_;
147 PP_CompletionCallback callback_; 151 PP_CompletionCallback callback_;
148 152
153 // The MessageLoopShared on which this callback should be run. This will be
154 // NULL if we're in-process.
155 scoped_refptr<MessageLoopShared> target_loop_;
156
149 int32_t result_for_blocked_callback_; 157 int32_t result_for_blocked_callback_;
150 // Used for pausing/waking the blocked thread if this is a blocking completion 158 // Used for pausing/waking the blocked thread if this is a blocking completion
151 // callback. Note that in-process, there is no lock, blocking callbacks are 159 // callback. Note that in-process, there is no lock, blocking callbacks are
152 // not allowed, and therefore this pointer will be NULL. 160 // not allowed, and therefore this pointer will be NULL.
153 scoped_ptr<base::ConditionVariable> operation_completed_condvar_; 161 scoped_ptr<base::ConditionVariable> operation_completed_condvar_;
154 162
155 DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback); 163 DISALLOW_IMPLICIT_CONSTRUCTORS(TrackedCallback);
156 }; 164 };
157 165
158 } // namespace ppapi 166 } // namespace ppapi
159 167
160 #endif // PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_ 168 #endif // PPAPI_SHARED_IMPL_TRACKED_CALLBACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698