OLD | NEW |
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/proxy/interface_id.h" | 10 #include "ppapi/proxy/interface_id.h" |
11 #include "ppapi/shared_impl/function_group_base.h" | 11 #include "ppapi/shared_impl/function_group_base.h" |
12 #include "ppapi/shared_impl/ppapi_globals.h" | |
13 #include "ppapi/shared_impl/proxy_lock.h" | 12 #include "ppapi/shared_impl/proxy_lock.h" |
14 #include "ppapi/shared_impl/resource.h" | 13 #include "ppapi/shared_impl/resource.h" |
| 14 #include "ppapi/shared_impl/tracker_base.h" |
15 #include "ppapi/shared_impl/resource_tracker.h" | 15 #include "ppapi/shared_impl/resource_tracker.h" |
16 #include "ppapi/shared_impl/tracker_base.h" | |
17 #include "ppapi/thunk/ppapi_thunk_export.h" | 16 #include "ppapi/thunk/ppapi_thunk_export.h" |
18 #include "ppapi/thunk/ppb_instance_api.h" | 17 #include "ppapi/thunk/ppb_instance_api.h" |
19 #include "ppapi/thunk/resource_creation_api.h" | 18 #include "ppapi/thunk/resource_creation_api.h" |
20 | 19 |
21 namespace ppapi { | 20 namespace ppapi { |
22 namespace thunk { | 21 namespace thunk { |
23 | 22 |
24 // Enter* helper objects: These objects wrap a call from the C PPAPI into | 23 // Enter* helper objects: These objects wrap a call from the C PPAPI into |
25 // the internal implementation. They make sure the lock is acquired and will | 24 // the internal implementation. They make sure the lock is acquired and will |
26 // automatically set up some stuff for you. | 25 // automatically set up some stuff for you. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { | 109 class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { |
111 public: | 110 public: |
112 EnterFunctionGivenResource(PP_Resource resource, bool report_error) | 111 EnterFunctionGivenResource(PP_Resource resource, bool report_error) |
113 : EnterFunction<FunctionsT>(GetInstanceForResource(resource), | 112 : EnterFunction<FunctionsT>(GetInstanceForResource(resource), |
114 report_error) { | 113 report_error) { |
115 } | 114 } |
116 | 115 |
117 private: | 116 private: |
118 static PP_Instance GetInstanceForResource(PP_Resource resource) { | 117 static PP_Instance GetInstanceForResource(PP_Resource resource) { |
119 Resource* object = | 118 Resource* object = |
120 PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); | 119 TrackerBase::Get()->GetResourceTracker()->GetResource(resource); |
121 return object ? object->pp_instance() : 0; | 120 return object ? object->pp_instance() : 0; |
122 } | 121 } |
123 }; | 122 }; |
124 | 123 |
125 // EnterResource --------------------------------------------------------------- | 124 // EnterResource --------------------------------------------------------------- |
126 | 125 |
127 template<typename ResourceT, bool lock_on_entry = true> | 126 template<typename ResourceT, bool lock_on_entry = true> |
128 class EnterResource : subtle::LockOnEntry<lock_on_entry> { | 127 class EnterResource : subtle::LockOnEntry<lock_on_entry> { |
129 public: | 128 public: |
130 EnterResource(PP_Resource resource, bool report_error) | 129 EnterResource(PP_Resource resource, bool report_error) |
131 : object_(NULL) { | 130 : object_(NULL) { |
132 resource_ = | 131 resource_ = TrackerBase::Get()->GetResourceTracker()->GetResource(resource); |
133 PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource); | |
134 if (resource_) | 132 if (resource_) |
135 object_ = resource_->GetAs<ResourceT>(); | 133 object_ = resource_->GetAs<ResourceT>(); |
136 // TODO(brettw) check error and if report_error is set, do something. | 134 // TODO(brettw) check error and if report_error is set, do something. |
137 } | 135 } |
138 ~EnterResource() {} | 136 ~EnterResource() {} |
139 | 137 |
140 bool succeeded() const { return !!object_; } | 138 bool succeeded() const { return !!object_; } |
141 bool failed() const { return !object_; } | 139 bool failed() const { return !object_; } |
142 | 140 |
143 ResourceT* object() { return object_; } | 141 ResourceT* object() { return object_; } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 : public EnterFunctionNoLock<PPB_Instance_FunctionAPI> { | 174 : public EnterFunctionNoLock<PPB_Instance_FunctionAPI> { |
177 public: | 175 public: |
178 EnterInstance(PP_Instance instance); | 176 EnterInstance(PP_Instance instance); |
179 ~EnterInstance(); | 177 ~EnterInstance(); |
180 }; | 178 }; |
181 | 179 |
182 } // namespace thunk | 180 } // namespace thunk |
183 } // namespace ppapi | 181 } // namespace ppapi |
184 | 182 |
185 #endif // PPAPI_THUNK_ENTER_H_ | 183 #endif // PPAPI_THUNK_ENTER_H_ |
OLD | NEW |