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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/thunk/enter.h
diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h
index 276f0457647d07d08f367cbced88430fdf781c3c..9c43a6d76bd5481c53daef6c53bc16e04e629621 100644
--- a/ppapi/thunk/enter.h
+++ b/ppapi/thunk/enter.h
@@ -245,6 +245,46 @@ class PPAPI_THUNK_EXPORT EnterInstanceNoLock
PPB_Instance_API* functions_;
};
+// EnterInstanceAPI ------------------------------------------------------------
+
+template<typename ApiT, bool lock_on_entry = true>
+class PPAPI_THUNK_EXPORT EnterInstanceAPI
+ : public subtle::EnterBase,
+ public subtle::LockOnEntry<lock_on_entry> {
+ public:
+ EnterInstanceAPI(PP_Instance instance) : EnterBase() {
+ functions_ = NULL;
+ PPB_Instance_API* ppb_instance =
+ PpapiGlobals::Get()->GetInstanceAPI(instance);
+ if (ppb_instance) {
+ Resource* resource =
+ ppb_instance->GetSingletonResource(instance,
+ ApiT::kSingletonResourceID);
+ if (resource)
+ functions_ = resource->GetAs<ApiT>();
+ }
+ SetStateForFunctionError(instance, functions_, true);
+ }
+ ~EnterInstanceAPI() {}
+
+ bool succeeded() const { return !!functions_; }
+ bool failed() const { return !functions_; }
+
+ ApiT* functions() { return functions_; }
+
+ private:
+ ApiT* functions_;
+};
+
+template<typename ApiT>
+class PPAPI_THUNK_EXPORT EnterInstanceAPINoLock
+ : public EnterInstanceAPI<ApiT, false> {
+ public:
+ EnterInstanceAPINoLock(PP_Instance instance)
+ : EnterInstanceAPI<ApiT, false>(instance) {
+ }
+};
+
// EnterResourceCreation -------------------------------------------------------
class PPAPI_THUNK_EXPORT EnterResourceCreation

Powered by Google App Engine
This is Rietveld 408576698