pp::InstanceHandle Class Reference

List of all members.

Public Member Functions

 InstanceHandle (Instance *instance)
 InstanceHandle (PP_Instance pp_instance)
PP_Instance pp_instance () const

Detailed Description

An instance handle identifies an instance in a constructor for a resource.

This class solves two different problems:

1. A pp::Instance object's lifetime is managed by the system on the main pepper thread of the module. This means that it may get destroyed at any time based on something that happens on the web page. Therefore, it's not safe to refer to a pp::Instance object on a background thread. Instead, we need to pass some kind of identifier to resource constructors so that they may safely be used on background threads. If the instance becomes invalid, the resource creation will fail on the background thread, but it won't crash.

2. PP_Instance would be a good identifier to use for this case. However, using PP_Instance in the constructor to resources is problematic because it is just a typedef for an integer, as is a PP_Resource. Many resources have alternate constructors that just take an existing PP_Resource, so the constructors would be ambiguous. Having this wrapper around a PP_Instance prevents this ambiguity, and also provides a nice place to consolidate an implicit conversion from pp::Instance* for prettier code on the main thread (you can just pass "this" to resource constructors in your instance objects).

You should always pass an InstanceHandle to background threads instead of a pp::Instance, and use them in resource constructors and code that may be used from background threads.

Constructor & Destructor Documentation

Implicit constructor for converting a pp::Instance to an instance handle.

[in]instanceThe instance with which this InstanceHandle will be associated.
pp::InstanceHandle::InstanceHandle ( PP_Instance  pp_instance) [inline, explicit]

This constructor explicitly converts a PP_Instance to an instance handle.

This should not be implicit because it can make some resource constructors ambiguous. PP_Instance is just a typedef for an integer, as is PP_Resource, so the compiler can get confused between the two.

[in]pp_instanceThe instance with which this InstanceHandle will be associated.

Member Function Documentation

PP_Instance pp::InstanceHandle::pp_instance ( ) const [inline]

The pp_instance() function returns the PP_Instance.

A PP_Instance internal instance handle.

The documentation for this class was generated from the following file: