| OLD | NEW |
| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
| 14 #include "ppapi/shared_impl/api_id.h" | |
| 15 #include "ppapi/shared_impl/ppapi_globals.h" | 14 #include "ppapi/shared_impl/ppapi_globals.h" |
| 16 #include "ppapi/shared_impl/proxy_lock.h" | 15 #include "ppapi/shared_impl/proxy_lock.h" |
| 17 #include "ppapi/shared_impl/resource.h" | 16 #include "ppapi/shared_impl/resource.h" |
| 18 #include "ppapi/shared_impl/resource_tracker.h" | 17 #include "ppapi/shared_impl/resource_tracker.h" |
| 18 #include "ppapi/shared_impl/singleton_resource_id.h" |
| 19 #include "ppapi/shared_impl/tracked_callback.h" | 19 #include "ppapi/shared_impl/tracked_callback.h" |
| 20 #include "ppapi/thunk/ppapi_thunk_export.h" | 20 #include "ppapi/thunk/ppapi_thunk_export.h" |
| 21 #include "ppapi/thunk/ppb_instance_api.h" | 21 #include "ppapi/thunk/ppb_instance_api.h" |
| 22 #include "ppapi/thunk/resource_creation_api.h" | 22 #include "ppapi/thunk/resource_creation_api.h" |
| 23 | 23 |
| 24 namespace ppapi { | 24 namespace ppapi { |
| 25 namespace thunk { | 25 namespace thunk { |
| 26 | 26 |
| 27 // Enter* helper objects: These objects wrap a call from the C PPAPI into | 27 // Enter* helper objects: These objects wrap a call from the C PPAPI into |
| 28 // the internal implementation. They make sure the lock is acquired and will | 28 // the internal implementation. They make sure the lock is acquired and will |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 : EnterResource<ResourceT, false>(resource, callback, report_error) { | 209 : EnterResource<ResourceT, false>(resource, callback, report_error) { |
| 210 } | 210 } |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 // EnterInstance --------------------------------------------------------------- | 213 // EnterInstance --------------------------------------------------------------- |
| 214 | 214 |
| 215 class PPAPI_THUNK_EXPORT EnterInstance | 215 class PPAPI_THUNK_EXPORT EnterInstance |
| 216 : public subtle::EnterBase, | 216 : public subtle::EnterBase, |
| 217 public subtle::LockOnEntry<true> { | 217 public subtle::LockOnEntry<true> { |
| 218 public: | 218 public: |
| 219 EnterInstance(PP_Instance instance); | 219 explicit EnterInstance(PP_Instance instance); |
| 220 EnterInstance(PP_Instance instance, | 220 EnterInstance(PP_Instance instance, |
| 221 const PP_CompletionCallback& callback); | 221 const PP_CompletionCallback& callback); |
| 222 ~EnterInstance(); | 222 ~EnterInstance(); |
| 223 | 223 |
| 224 bool succeeded() const { return !!functions_; } | 224 bool succeeded() const { return !!functions_; } |
| 225 bool failed() const { return !functions_; } | 225 bool failed() const { return !functions_; } |
| 226 | 226 |
| 227 PPB_Instance_API* functions() { return functions_; } | 227 PPB_Instance_API* functions() const { return functions_; } |
| 228 | 228 |
| 229 private: | 229 private: |
| 230 PPB_Instance_API* functions_; | 230 PPB_Instance_API* functions_; |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 class PPAPI_THUNK_EXPORT EnterInstanceNoLock | 233 class PPAPI_THUNK_EXPORT EnterInstanceNoLock |
| 234 : public subtle::EnterBase, | 234 : public subtle::EnterBase, |
| 235 public subtle::LockOnEntry<false> { | 235 public subtle::LockOnEntry<false> { |
| 236 public: | 236 public: |
| 237 EnterInstanceNoLock(PP_Instance instance); | 237 explicit EnterInstanceNoLock(PP_Instance instance); |
| 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 explicit EnterInstanceAPI(PP_Instance instance) |
| 256 : EnterBase(), |
| 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, |
| 263 ApiT::kSingletonResourceID); |
| 264 if (resource) |
| 265 functions_ = resource->GetAs<ApiT>(); |
| 266 } |
| 267 SetStateForFunctionError(instance, functions_, true); |
| 268 } |
| 269 ~EnterInstanceAPI() {} |
| 270 |
| 271 bool succeeded() const { return !!functions_; } |
| 272 bool failed() const { return !functions_; } |
| 273 |
| 274 ApiT* functions() const { return functions_; } |
| 275 |
| 276 private: |
| 277 ApiT* functions_; |
| 278 }; |
| 279 |
| 280 template<typename ApiT> |
| 281 class PPAPI_THUNK_EXPORT EnterInstanceAPINoLock |
| 282 : public EnterInstanceAPI<ApiT, false> { |
| 283 public: |
| 284 explicit EnterInstanceAPINoLock(PP_Instance instance) |
| 285 : EnterInstanceAPI<ApiT, false>(instance) { |
| 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 explicit EnterResourceCreation(PP_Instance instance); |
| 255 ~EnterResourceCreation(); | 296 ~EnterResourceCreation(); |
| 256 | 297 |
| 257 ResourceCreationAPI* functions() { return functions_; } | 298 ResourceCreationAPI* functions() { return functions_; } |
| 258 | 299 |
| 259 private: | 300 private: |
| 260 ResourceCreationAPI* functions_; | 301 ResourceCreationAPI* functions_; |
| 261 }; | 302 }; |
| 262 | 303 |
| 263 class PPAPI_THUNK_EXPORT EnterResourceCreationNoLock | 304 class PPAPI_THUNK_EXPORT EnterResourceCreationNoLock |
| 264 : public subtle::EnterBase, | 305 : public subtle::EnterBase, |
| 265 public subtle::LockOnEntry<false> { | 306 public subtle::LockOnEntry<false> { |
| 266 public: | 307 public: |
| 267 EnterResourceCreationNoLock(PP_Instance instance); | 308 explicit EnterResourceCreationNoLock(PP_Instance instance); |
| 268 ~EnterResourceCreationNoLock(); | 309 ~EnterResourceCreationNoLock(); |
| 269 | 310 |
| 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_ |
| OLD | NEW |