Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Unified Diff: ppapi/shared_impl/ppapi_globals.h

Issue 9187055: Reland 9034035: Make it possible to have 1 PpapiGlobals per thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/serialized_var_unittest.cc ('k') | ppapi/shared_impl/ppapi_globals.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..93f121c09d94b35b1925026ea8bb033ac7e0e84c 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,42 @@ 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_;
+ // In unit tests, the following might be valid (see
+ // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL.
+ return GetThreadLocalPointer();
+ }
+
+ // 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.
@@ -41,7 +72,15 @@ class PPAPI_SHARED_EXPORT PpapiGlobals {
// failure.
virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0;
+ virtual bool IsHostGlobals() const;
+ virtual bool IsPluginGlobals() const;
+
private:
+ // Return the thread-local pointer which is used only for unit testing. It
+ // should always be NULL when running in production. It allows separate
+ // threads to have distinct "globals".
+ static PpapiGlobals* GetThreadLocalPointer();
+
static PpapiGlobals* ppapi_globals_;
DISALLOW_COPY_AND_ASSIGN(PpapiGlobals);
« no previous file with comments | « ppapi/proxy/serialized_var_unittest.cc ('k') | ppapi/shared_impl/ppapi_globals.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698