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

Side by Side Diff: ppapi/shared_impl/ppapi_globals.h

Issue 9034035: Make it possible to have 1 PpapiGlobals per thread. Update unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test. Cleanup. Move proxy lock to globals. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_SHARED_IMPL_PPAPI_GLOBALS_H_ 5 #ifndef PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
6 #define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ 6 #define PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/threading/thread_local.h" // For testing purposes only.
9 #include "ppapi/c/pp_instance.h" 10 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_module.h" 11 #include "ppapi/c/pp_module.h"
11 #include "ppapi/shared_impl/api_id.h" 12 #include "ppapi/shared_impl/api_id.h"
12 #include "ppapi/shared_impl/ppapi_shared_export.h" 13 #include "ppapi/shared_impl/ppapi_shared_export.h"
13 14
15 namespace base {
16 class Lock;
17 }
18
14 namespace ppapi { 19 namespace ppapi {
15 20
16 class CallbackTracker; 21 class CallbackTracker;
17 class FunctionGroupBase; 22 class FunctionGroupBase;
18 class ResourceTracker; 23 class ResourceTracker;
19 class VarTracker; 24 class VarTracker;
20 25
21 // Abstract base class 26 // Abstract base class
22 class PPAPI_SHARED_EXPORT PpapiGlobals { 27 class PPAPI_SHARED_EXPORT PpapiGlobals {
23 public: 28 public:
24 PpapiGlobals(); 29 PpapiGlobals();
30
31 // This constructor is to be used only for making a PpapiGlobal for testing
32 // purposes. This avoids setting the global static ppapi_globals_. For unit
33 // tests that use this feature, the "test" PpapiGlobals should be constructed
34 // using this method. See SetPpapiGlobalsOnThreadForTest for more information.
35 struct ForTest {};
36 PpapiGlobals(ForTest);
37
25 virtual ~PpapiGlobals(); 38 virtual ~PpapiGlobals();
26 39
27 // Getter for the global singleton. 40 // Getter for the global singleton.
28 inline static PpapiGlobals* Get() { return ppapi_globals_; } 41 inline static PpapiGlobals* Get() {
42 if (ppapi_globals_)
43 return ppapi_globals_;
44 return ppapi_globals_for_test_.Get();
45 }
46
47 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for
48 // a given thread. After setting the PpapiGlobals for a thread, Get() will
49 // return that PpapiGlobals when Get() is called on that thread. Other threads
50 // are unaffected. This allows us to have tests which use >1 PpapiGlobals in
51 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread
52 // emulate the "plugin".
53 //
54 // PpapiGlobals object must have been constructed using the "ForTest"
55 // parameter.
56 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr);
29 57
30 // Retrieves the corresponding tracker. 58 // Retrieves the corresponding tracker.
31 virtual ResourceTracker* GetResourceTracker() = 0; 59 virtual ResourceTracker* GetResourceTracker() = 0;
32 virtual VarTracker* GetVarTracker() = 0; 60 virtual VarTracker* GetVarTracker() = 0;
33 virtual CallbackTracker* GetCallbackTrackerForInstance( 61 virtual CallbackTracker* GetCallbackTrackerForInstance(
34 PP_Instance instance) = 0; 62 PP_Instance instance) = 0;
63 virtual base::Lock* GetProxyLock() = 0;
35 64
36 // Returns the function object corresponding to the given ID, or NULL if 65 // Returns the function object corresponding to the given ID, or NULL if
37 // there isn't one. 66 // there isn't one.
38 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, ApiID id) = 0; 67 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, ApiID id) = 0;
39 68
40 // Returns the PP_Module associated with the given PP_Instance, or 0 on 69 // Returns the PP_Module associated with the given PP_Instance, or 0 on
41 // failure. 70 // failure.
42 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; 71 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0;
43 72
44 private: 73 private:
45 static PpapiGlobals* ppapi_globals_; 74 static PpapiGlobals* ppapi_globals_;
46 75
76 // The thread-local pointer is used only for unit testing. It should always be
77 // NULL when running in production, to allow separate threads to have distinct
78 // "globals".
79 static base::ThreadLocalPointer<PpapiGlobals> ppapi_globals_for_test_;
80
47 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); 81 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals);
48 }; 82 };
49 83
50 } // namespace ppapi 84 } // namespace ppapi
51 85
52 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ 86 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698