| Index: ppapi/shared_impl/ppapi_globals.h
|
| diff --git a/ppapi/shared_impl/ppapi_globals.h b/ppapi/shared_impl/ppapi_globals.h
|
| index b3d7d555514785a41f57891eb5ec872c04427c78..ddefb5a43f7da4b9bb93a59c4fabdfb86611da1e 100644
|
| --- a/ppapi/shared_impl/ppapi_globals.h
|
| +++ b/ppapi/shared_impl/ppapi_globals.h
|
| @@ -6,11 +6,16 @@
|
| #define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
|
|
|
| #include "base/basictypes.h"
|
| +#include "base/threading/thread_local.h" // For testing purposes only.
|
| #include "ppapi/c/pp_instance.h"
|
| #include "ppapi/c/pp_module.h"
|
| #include "ppapi/shared_impl/api_id.h"
|
| #include "ppapi/shared_impl/ppapi_shared_export.h"
|
|
|
| +namespace base {
|
| +class Lock;
|
| +}
|
| +
|
| namespace ppapi {
|
|
|
| class CallbackTracker;
|
| @@ -22,16 +27,40 @@ class VarTracker;
|
| class PPAPI_SHARED_EXPORT PpapiGlobals {
|
| public:
|
| PpapiGlobals();
|
| +
|
| + // This constructor is to be used only for making a PpapiGlobal for testing
|
| + // purposes. This avoids setting the global static ppapi_globals_. For unit
|
| + // tests that use this feature, the "test" PpapiGlobals should be constructed
|
| + // using this method. See SetPpapiGlobalsOnThreadForTest for more information.
|
| + struct ForTest {};
|
| + PpapiGlobals(ForTest);
|
| +
|
| virtual ~PpapiGlobals();
|
|
|
| // Getter for the global singleton.
|
| - inline static PpapiGlobals* Get() { return ppapi_globals_; }
|
| + inline static PpapiGlobals* Get() {
|
| + if (ppapi_globals_)
|
| + return ppapi_globals_;
|
| + return ppapi_globals_for_test_.Get();
|
| + }
|
| +
|
| + // This allows us to set a given PpapiGlobals object as the PpapiGlobals for
|
| + // a given thread. After setting the PpapiGlobals for a thread, Get() will
|
| + // return that PpapiGlobals when Get() is called on that thread. Other threads
|
| + // are unaffected. This allows us to have tests which use >1 PpapiGlobals in
|
| + // the same process, e.g. for having 1 thread emulate the "host" and 1 thread
|
| + // emulate the "plugin".
|
| + //
|
| + // PpapiGlobals object must have been constructed using the "ForTest"
|
| + // parameter.
|
| + static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr);
|
|
|
| // Retrieves the corresponding tracker.
|
| virtual ResourceTracker* GetResourceTracker() = 0;
|
| virtual VarTracker* GetVarTracker() = 0;
|
| virtual CallbackTracker* GetCallbackTrackerForInstance(
|
| PP_Instance instance) = 0;
|
| + virtual base::Lock* GetProxyLock() = 0;
|
|
|
| // Returns the function object corresponding to the given ID, or NULL if
|
| // there isn't one.
|
| @@ -44,6 +73,11 @@ class PPAPI_SHARED_EXPORT PpapiGlobals {
|
| private:
|
| static PpapiGlobals* ppapi_globals_;
|
|
|
| + // The thread-local pointer is used only for unit testing. It should always be
|
| + // NULL when running in production, to allow separate threads to have distinct
|
| + // "globals".
|
| + static base::ThreadLocalPointer<PpapiGlobals> ppapi_globals_for_test_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(PpapiGlobals);
|
| };
|
|
|
|
|