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

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

Issue 9139054: Revert 117399 - Make it possible to have 1 PpapiGlobals per thread. Update unit tests. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/serialized_var_unittest.cc ('k') | ppapi/shared_impl/ppapi_globals.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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.
10 #include "ppapi/c/pp_instance.h" 9 #include "ppapi/c/pp_instance.h"
11 #include "ppapi/c/pp_module.h" 10 #include "ppapi/c/pp_module.h"
12 #include "ppapi/shared_impl/api_id.h" 11 #include "ppapi/shared_impl/api_id.h"
13 #include "ppapi/shared_impl/ppapi_shared_export.h" 12 #include "ppapi/shared_impl/ppapi_shared_export.h"
14 13
15 namespace base {
16 class Lock;
17 }
18
19 namespace ppapi { 14 namespace ppapi {
20 15
21 class CallbackTracker; 16 class CallbackTracker;
22 class FunctionGroupBase; 17 class FunctionGroupBase;
23 class ResourceTracker; 18 class ResourceTracker;
24 class VarTracker; 19 class VarTracker;
25 20
26 // Abstract base class 21 // Abstract base class
27 class PPAPI_SHARED_EXPORT PpapiGlobals { 22 class PPAPI_SHARED_EXPORT PpapiGlobals {
28 public: 23 public:
29 PpapiGlobals(); 24 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
38 virtual ~PpapiGlobals(); 25 virtual ~PpapiGlobals();
39 26
40 // Getter for the global singleton. 27 // Getter for the global singleton.
41 inline static PpapiGlobals* Get() { 28 inline static PpapiGlobals* Get() { return ppapi_globals_; }
42 if (ppapi_globals_)
43 return ppapi_globals_;
44 // In unit tests, the following might be valid (see
45 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL.
46 return GetThreadLocalPointer();
47 }
48
49 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for
50 // a given thread. After setting the PpapiGlobals for a thread, Get() will
51 // return that PpapiGlobals when Get() is called on that thread. Other threads
52 // are unaffected. This allows us to have tests which use >1 PpapiGlobals in
53 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread
54 // emulate the "plugin".
55 //
56 // PpapiGlobals object must have been constructed using the "ForTest"
57 // parameter.
58 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr);
59 29
60 // Retrieves the corresponding tracker. 30 // Retrieves the corresponding tracker.
61 virtual ResourceTracker* GetResourceTracker() = 0; 31 virtual ResourceTracker* GetResourceTracker() = 0;
62 virtual VarTracker* GetVarTracker() = 0; 32 virtual VarTracker* GetVarTracker() = 0;
63 virtual CallbackTracker* GetCallbackTrackerForInstance( 33 virtual CallbackTracker* GetCallbackTrackerForInstance(
64 PP_Instance instance) = 0; 34 PP_Instance instance) = 0;
65 virtual base::Lock* GetProxyLock() = 0;
66 35
67 // Returns the function object corresponding to the given ID, or NULL if 36 // Returns the function object corresponding to the given ID, or NULL if
68 // there isn't one. 37 // there isn't one.
69 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, ApiID id) = 0; 38 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, ApiID id) = 0;
70 39
71 // Returns the PP_Module associated with the given PP_Instance, or 0 on 40 // Returns the PP_Module associated with the given PP_Instance, or 0 on
72 // failure. 41 // failure.
73 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; 42 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0;
74 43
75 virtual bool IsHostGlobals() const;
76 virtual bool IsPluginGlobals() const;
77
78 private: 44 private:
79 // Return the thread-local pointer which is used only for unit testing. It
80 // should always be NULL when running in production. It allows separate
81 // threads to have distinct "globals".
82 static PpapiGlobals* GetThreadLocalPointer();
83
84 static PpapiGlobals* ppapi_globals_; 45 static PpapiGlobals* ppapi_globals_;
85 46
86 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); 47 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals);
87 }; 48 };
88 49
89 } // namespace ppapi 50 } // namespace ppapi
90 51
91 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ 52 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_
OLDNEW
« 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