Chromium Code Reviews| 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" |
| (...skipping 198 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) : EnterBase(), | |
|
brettw
2012/11/27 05:55:10
The style guide either puts everything on one line
raymes
2012/11/27 17:48:45
Done.
| |
| 256 functions_(NULL) { | |
| 257 PPB_Instance_API* ppb_instance = | |
| 258 PpapiGlobals::Get()->GetInstanceAPI(instance); | |
| 259 if (ppb_instance) { | |
| 260 Resource* resource = | |
| 261 ppb_instance->GetSingletonResource(instance, | |
| 262 ApiT::kSingletonResourceID); | |
| 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() const { 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 explicit EnterInstanceAPINoLock(PP_Instance instance) | |
| 284 : EnterInstanceAPI<ApiT, false>(instance) { | |
| 285 } | |
| 286 }; | |
| 287 | |
| 248 // EnterResourceCreation ------------------------------------------------------- | 288 // EnterResourceCreation ------------------------------------------------------- |
| 249 | 289 |
| 250 class PPAPI_THUNK_EXPORT EnterResourceCreation | 290 class PPAPI_THUNK_EXPORT EnterResourceCreation |
| 251 : public subtle::EnterBase, | 291 : public subtle::EnterBase, |
| 252 public subtle::LockOnEntry<true> { | 292 public subtle::LockOnEntry<true> { |
| 253 public: | 293 public: |
| 254 EnterResourceCreation(PP_Instance instance); | 294 explicit EnterResourceCreation(PP_Instance instance); |
| 255 ~EnterResourceCreation(); | 295 ~EnterResourceCreation(); |
| 256 | 296 |
| 257 ResourceCreationAPI* functions() { return functions_; } | 297 ResourceCreationAPI* functions() { return functions_; } |
| 258 | 298 |
| 259 private: | 299 private: |
| 260 ResourceCreationAPI* functions_; | 300 ResourceCreationAPI* functions_; |
| 261 }; | 301 }; |
| 262 | 302 |
| 263 class PPAPI_THUNK_EXPORT EnterResourceCreationNoLock | 303 class PPAPI_THUNK_EXPORT EnterResourceCreationNoLock |
| 264 : public subtle::EnterBase, | 304 : public subtle::EnterBase, |
| 265 public subtle::LockOnEntry<false> { | 305 public subtle::LockOnEntry<false> { |
| 266 public: | 306 public: |
| 267 EnterResourceCreationNoLock(PP_Instance instance); | 307 explicit EnterResourceCreationNoLock(PP_Instance instance); |
| 268 ~EnterResourceCreationNoLock(); | 308 ~EnterResourceCreationNoLock(); |
| 269 | 309 |
| 270 ResourceCreationAPI* functions() { return functions_; } | 310 ResourceCreationAPI* functions() { return functions_; } |
| 271 | 311 |
| 272 private: | 312 private: |
| 273 ResourceCreationAPI* functions_; | 313 ResourceCreationAPI* functions_; |
| 274 }; | 314 }; |
| 275 | 315 |
| 276 } // namespace thunk | 316 } // namespace thunk |
| 277 } // namespace ppapi | 317 } // namespace ppapi |
| 278 | 318 |
| 279 #endif // PPAPI_THUNK_ENTER_H_ | 319 #endif // PPAPI_THUNK_ENTER_H_ |
| OLD | NEW |