OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Abstract base class | 36 // Abstract base class |
37 class PPAPI_SHARED_EXPORT PpapiGlobals { | 37 class PPAPI_SHARED_EXPORT PpapiGlobals { |
38 public: | 38 public: |
39 // Must be created on the main thread. | 39 // Must be created on the main thread. |
40 PpapiGlobals(); | 40 PpapiGlobals(); |
41 | 41 |
42 // This constructor is to be used only for making a PpapiGlobal for testing | 42 // This constructor is to be used only for making a PpapiGlobal for testing |
43 // purposes. This avoids setting the global static ppapi_globals_. For unit | 43 // purposes. This avoids setting the global static ppapi_globals_. For unit |
44 // tests that use this feature, the "test" PpapiGlobals should be constructed | 44 // tests that use this feature, the "test" PpapiGlobals should be constructed |
45 // using this method. See SetPpapiGlobalsOnThreadForTest for more information. | 45 // using this method. See SetPpapiGlobalsOnThreadForTest for more information. |
46 struct ForTest {}; | 46 struct PerThreadForTest {}; |
47 explicit PpapiGlobals(ForTest); | 47 explicit PpapiGlobals(PerThreadForTest); |
48 | 48 |
49 virtual ~PpapiGlobals(); | 49 virtual ~PpapiGlobals(); |
50 | 50 |
51 // Getter for the global singleton. | 51 // Getter for the global singleton. |
52 inline static PpapiGlobals* Get() { | 52 inline static PpapiGlobals* Get() { |
53 if (ppapi_globals_) | 53 if (ppapi_globals_) |
54 return ppapi_globals_; | 54 return ppapi_globals_; |
55 // In unit tests, the following might be valid (see | 55 // In unit tests, the following might be valid (see |
56 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL. | 56 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL. |
57 return GetThreadLocalPointer(); | 57 return GetThreadLocalPointer(); |
58 } | 58 } |
59 | 59 |
60 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for | 60 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for |
61 // a given thread. After setting the PpapiGlobals for a thread, Get() will | 61 // a given thread. After setting the PpapiGlobals for a thread, Get() will |
62 // return that PpapiGlobals when Get() is called on that thread. Other threads | 62 // return that PpapiGlobals when Get() is called on that thread. Other threads |
63 // are unaffected. This allows us to have tests which use >1 PpapiGlobals in | 63 // are unaffected. This allows us to have tests which use >1 PpapiGlobals in |
64 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread | 64 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread |
65 // emulate the "plugin". | 65 // emulate the "plugin". |
66 // | 66 // |
67 // PpapiGlobals object must have been constructed using the "ForTest" | 67 // PpapiGlobals object must have been constructed using the "PerThreadForTest" |
68 // parameter. | 68 // parameter. |
69 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr); | 69 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr); |
70 | 70 |
71 // Retrieves the corresponding tracker. | 71 // Retrieves the corresponding tracker. |
72 virtual ResourceTracker* GetResourceTracker() = 0; | 72 virtual ResourceTracker* GetResourceTracker() = 0; |
73 virtual VarTracker* GetVarTracker() = 0; | 73 virtual VarTracker* GetVarTracker() = 0; |
74 virtual CallbackTracker* GetCallbackTrackerForInstance( | 74 virtual CallbackTracker* GetCallbackTrackerForInstance( |
75 PP_Instance instance) = 0; | 75 PP_Instance instance) = 0; |
76 | 76 |
77 virtual base::Lock* GetProxyLock() = 0; | 77 virtual base::Lock* GetProxyLock() = 0; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 static PpapiGlobals* ppapi_globals_; | 135 static PpapiGlobals* ppapi_globals_; |
136 | 136 |
137 scoped_refptr<base::MessageLoopProxy> main_loop_proxy_; | 137 scoped_refptr<base::MessageLoopProxy> main_loop_proxy_; |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); | 139 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); |
140 }; | 140 }; |
141 | 141 |
142 } // namespace ppapi | 142 } // namespace ppapi |
143 | 143 |
144 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ | 144 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ |
OLD | NEW |