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

Side by Side Diff: ppapi/thunk/enter.h

Issue 9113044: Convert to new enter method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PATCH DESCRIPTIONS ARE A STUPID WASTE OF TIME Created 8 years, 10 months 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
« no previous file with comments | « ppapi/thunk/common.cc ('k') | ppapi/thunk/enter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_THUNK_ENTER_H_ 5 #ifndef PPAPI_THUNK_ENTER_H_
6 #define PPAPI_THUNK_ENTER_H_ 6 #define PPAPI_THUNK_ENTER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "ppapi/c/pp_resource.h" 9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/shared_impl/api_id.h" 10 #include "ppapi/shared_impl/api_id.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // passing both resource_base and object is that we can differentiate "bad 101 // passing both resource_base and object is that we can differentiate "bad
102 // resource ID" from "valid resource ID not of the currect type." 102 // resource ID" from "valid resource ID not of the currect type."
103 // 103 //
104 // This will set retval_ = PP_ERROR_BADRESOURCE if the object is invalid, and 104 // This will set retval_ = PP_ERROR_BADRESOURCE if the object is invalid, and
105 // if report_error is set, log a message to the programmer. 105 // if report_error is set, log a message to the programmer.
106 void SetStateForResourceError(PP_Resource pp_resource, 106 void SetStateForResourceError(PP_Resource pp_resource,
107 Resource* resource_base, 107 Resource* resource_base,
108 void* object, 108 void* object,
109 bool report_error); 109 bool report_error);
110 110
111 // Same as SetStateForResourceError except for function API.
112 void SetStateForFunctionError(PP_Instance pp_instance,
113 void* object,
114 bool report_error);
115
111 private: 116 private:
112 // Holds the callback. The function will only be non-NULL when the 117 // Holds the callback. The function will only be non-NULL when the
113 // callback is requried. Optional callbacks don't require any special 118 // callback is requried. Optional callbacks don't require any special
114 // handling from us at this layer. 119 // handling from us at this layer.
115 PP_CompletionCallback callback_; 120 PP_CompletionCallback callback_;
116 121
117 int32_t retval_; 122 int32_t retval_;
118 }; 123 };
119 124
120 } // namespace subtle 125 } // namespace subtle
121 126
127 // EnterFunction --------------------------------------------------------------
122 128
123 template<typename FunctionsT, bool lock_on_entry = true> 129 template<typename FunctionsT, bool lock_on_entry = true>
124 class EnterFunction : public subtle::EnterBase, 130 class EnterFunction : public subtle::EnterBase,
125 public subtle::LockOnEntry<lock_on_entry> { 131 public subtle::LockOnEntry<lock_on_entry> {
126 public: 132 public:
127 EnterFunction(PP_Instance instance, bool report_error) 133 EnterFunction(PP_Instance instance, bool report_error)
128 : functions_(NULL) { 134 : EnterBase() {
129 FunctionGroupBase* base = GetFunctions(instance, FunctionsT::kApiID); 135 Init(instance, report_error);
130 if (base) 136 }
131 functions_ = base->GetAs<FunctionsT>(); 137 EnterFunction(PP_Instance instance,
132 // TODO(brettw) check error and if report_error is set, do something. 138 const PP_CompletionCallback& callback,
139 bool report_error)
140 : EnterBase(callback) {
141 Init(instance, report_error);
133 } 142 }
134 143
135 ~EnterFunction() {} 144 ~EnterFunction() {}
136 145
137 bool succeeded() const { return !!functions_; } 146 bool succeeded() const { return !!functions_; }
138 bool failed() const { return !functions_; } 147 bool failed() const { return !functions_; }
139 148
140 FunctionsT* functions() { return functions_; } 149 FunctionsT* functions() { return functions_; }
141 150
142 private: 151 private:
152 void Init(PP_Instance instance, bool report_error) {
153 FunctionGroupBase* base = GetFunctions(instance, FunctionsT::kApiID);
154 if (base)
155 functions_ = base->GetAs<FunctionsT>();
156 else
157 functions_ = NULL;
158 SetStateForFunctionError(instance, functions_, report_error);
159 }
160
143 FunctionsT* functions_; 161 FunctionsT* functions_;
144 162
145 DISALLOW_COPY_AND_ASSIGN(EnterFunction); 163 DISALLOW_COPY_AND_ASSIGN(EnterFunction);
146 }; 164 };
147 165
148 // Like EnterFunction but assumes the lock is already held. 166 // Like EnterFunction but assumes the lock is already held.
149 template<typename FunctionsT> 167 template<typename FunctionsT>
150 class EnterFunctionNoLock : public EnterFunction<FunctionsT, false> { 168 class EnterFunctionNoLock : public EnterFunction<FunctionsT, false> {
151 public: 169 public:
152 EnterFunctionNoLock(PP_Instance instance, bool report_error) 170 EnterFunctionNoLock(PP_Instance instance, bool report_error)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 object_ = NULL; 223 object_ = NULL;
206 SetStateForResourceError(resource, resource_, object_, report_error); 224 SetStateForResourceError(resource, resource_, object_, report_error);
207 } 225 }
208 226
209 Resource* resource_; 227 Resource* resource_;
210 ResourceT* object_; 228 ResourceT* object_;
211 229
212 DISALLOW_COPY_AND_ASSIGN(EnterResource); 230 DISALLOW_COPY_AND_ASSIGN(EnterResource);
213 }; 231 };
214 232
233 // ----------------------------------------------------------------------------
234
215 // Like EnterResource but assumes the lock is already held. 235 // Like EnterResource but assumes the lock is already held.
216 template<typename ResourceT> 236 template<typename ResourceT>
217 class EnterResourceNoLock : public EnterResource<ResourceT, false> { 237 class EnterResourceNoLock : public EnterResource<ResourceT, false> {
218 public: 238 public:
219 EnterResourceNoLock(PP_Resource resource, bool report_error) 239 EnterResourceNoLock(PP_Resource resource, bool report_error)
220 : EnterResource<ResourceT, false>(resource, report_error) { 240 : EnterResource<ResourceT, false>(resource, report_error) {
221 } 241 }
222 }; 242 };
223 243
224 // Simpler wrapper to enter the resource creation API. This is used for every 244 // Simpler wrapper to enter the resource creation API. This is used for every
225 // class so we have this helper function to save template instantiations and 245 // class so we have this helper function to save template instantiations and
226 // typing. 246 // typing.
227 class PPAPI_THUNK_EXPORT EnterResourceCreation 247 class PPAPI_THUNK_EXPORT EnterResourceCreation
228 : public EnterFunctionNoLock<ResourceCreationAPI> { 248 : public EnterFunctionNoLock<ResourceCreationAPI> {
229 public: 249 public:
230 EnterResourceCreation(PP_Instance instance); 250 EnterResourceCreation(PP_Instance instance);
231 ~EnterResourceCreation(); 251 ~EnterResourceCreation();
232 }; 252 };
233 253
234 // Simpler wrapper to enter the instance API from proxy code. This is used for 254 // Simpler wrapper to enter the instance API from proxy code. This is used for
235 // many interfaces so we have this helper function to save template 255 // many interfaces so we have this helper function to save template
236 // instantiations and typing. 256 // instantiations and typing.
237 class PPAPI_THUNK_EXPORT EnterInstance 257 class PPAPI_THUNK_EXPORT EnterInstance
238 : public EnterFunctionNoLock<PPB_Instance_FunctionAPI> { 258 : public EnterFunction<PPB_Instance_FunctionAPI> {
239 public: 259 public:
240 EnterInstance(PP_Instance instance); 260 EnterInstance(PP_Instance instance);
261 EnterInstance(PP_Instance instance, const PP_CompletionCallback& callback);
241 ~EnterInstance(); 262 ~EnterInstance();
242 }; 263 };
243 264
244 } // namespace thunk 265 } // namespace thunk
245 } // namespace ppapi 266 } // namespace ppapi
246 267
247 #endif // PPAPI_THUNK_ENTER_H_ 268 #endif // PPAPI_THUNK_ENTER_H_
OLDNEW
« no previous file with comments | « ppapi/thunk/common.cc ('k') | ppapi/thunk/enter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698