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

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

Issue 11359063: Refactor the way singleton-style resources are exposed via PPB_Instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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_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 <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 EnterInstanceNoLock(PP_Instance instance, 238 EnterInstanceNoLock(PP_Instance instance,
239 const PP_CompletionCallback& callback); 239 const PP_CompletionCallback& callback);
240 ~EnterInstanceNoLock(); 240 ~EnterInstanceNoLock();
241 241
242 PPB_Instance_API* functions() { return functions_; } 242 PPB_Instance_API* functions() { return functions_; }
243 243
244 private: 244 private:
245 PPB_Instance_API* functions_; 245 PPB_Instance_API* functions_;
246 }; 246 };
247 247
248 // EnterInstanceAPI ------------------------------------------------------------
249
250 template<typename ApiT, bool lock_on_entry = true>
251 class PPAPI_THUNK_EXPORT EnterInstanceAPI
252 : public subtle::EnterBase,
253 public subtle::LockOnEntry<lock_on_entry> {
254 public:
255 EnterInstanceAPI(PP_Instance instance,
256 SingletonResourceID singleton_resource_id) : EnterBase() {
yzshen1 2012/11/20 21:47:25 We can deduce the SingletonResourceID from ApiT, r
raymes 2012/11/20 23:30:23 Yes I was considering whether or not I wanted to d
257 functions_ = NULL;
258 PPB_Instance_API* ppb_instance =
259 PpapiGlobals::Get()->GetInstanceAPI(instance);
260 if (ppb_instance) {
261 Resource* resource =
262 ppb_instance->GetSingletonResource(instance, singleton_resource_id);
263 if (resource)
264 functions_ = resource->GetAs<ApiT>();
265 }
266 SetStateForFunctionError(instance, functions_, true);
267 }
268 ~EnterInstanceAPI() {}
269
270 bool succeeded() const { return !!functions_; }
271 bool failed() const { return !functions_; }
272
273 ApiT* functions() { return functions_; }
274
275 private:
276 ApiT* functions_;
277 };
278
279 template<typename ApiT>
280 class PPAPI_THUNK_EXPORT EnterInstanceAPINoLock
281 : public EnterInstanceAPI<ApiT, false> {
282 public:
283 EnterInstanceAPINoLock(PP_Instance instance,
284 SingletonResourceID singleton_resource_id)
285 : EnterInstanceAPI<ApiT, false>(instance, singleton_resource_id) {
286 }
287 };
288
248 // EnterResourceCreation ------------------------------------------------------- 289 // EnterResourceCreation -------------------------------------------------------
249 290
250 class PPAPI_THUNK_EXPORT EnterResourceCreation 291 class PPAPI_THUNK_EXPORT EnterResourceCreation
251 : public subtle::EnterBase, 292 : public subtle::EnterBase,
252 public subtle::LockOnEntry<true> { 293 public subtle::LockOnEntry<true> {
253 public: 294 public:
254 EnterResourceCreation(PP_Instance instance); 295 EnterResourceCreation(PP_Instance instance);
255 ~EnterResourceCreation(); 296 ~EnterResourceCreation();
256 297
257 ResourceCreationAPI* functions() { return functions_; } 298 ResourceCreationAPI* functions() { return functions_; }
(...skipping 12 matching lines...) Expand all
270 ResourceCreationAPI* functions() { return functions_; } 311 ResourceCreationAPI* functions() { return functions_; }
271 312
272 private: 313 private:
273 ResourceCreationAPI* functions_; 314 ResourceCreationAPI* functions_;
274 }; 315 };
275 316
276 } // namespace thunk 317 } // namespace thunk
277 } // namespace ppapi 318 } // namespace ppapi
278 319
279 #endif // PPAPI_THUNK_ENTER_H_ 320 #endif // PPAPI_THUNK_ENTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698