OLD | NEW |
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 |
14 namespace ppapi { | 15 namespace ppapi { |
15 | 16 |
16 class CallbackTracker; | 17 class CallbackTracker; |
17 class FunctionGroupBase; | 18 class FunctionGroupBase; |
18 class ResourceTracker; | 19 class ResourceTracker; |
19 class VarTracker; | 20 class VarTracker; |
20 | 21 |
21 // Abstract base class | 22 // Abstract base class |
22 class PPAPI_SHARED_EXPORT PpapiGlobals { | 23 class PPAPI_SHARED_EXPORT PpapiGlobals { |
23 public: | 24 public: |
24 PpapiGlobals(); | 25 PpapiGlobals(); |
25 virtual ~PpapiGlobals(); | 26 virtual ~PpapiGlobals(); |
26 | 27 |
27 // Getter for the global singleton. | 28 // Getter for the global singleton. |
28 inline static PpapiGlobals* Get() { return ppapi_globals_; } | 29 inline static PpapiGlobals* Get() { |
| 30 if (ppapi_globals_) |
| 31 return ppapi_globals_; |
| 32 return ppapi_globals_for_test_.Get(); |
| 33 } |
| 34 static void SetPpapiGlobalsForTest(PpapiGlobals* ptr) { |
| 35 ppapi_globals_for_test_.Set(ptr); |
| 36 ppapi_globals_ = NULL; |
| 37 } |
29 | 38 |
30 // Retrieves the corresponding tracker. | 39 // Retrieves the corresponding tracker. |
31 virtual ResourceTracker* GetResourceTracker() = 0; | 40 virtual ResourceTracker* GetResourceTracker() = 0; |
32 virtual VarTracker* GetVarTracker() = 0; | 41 virtual VarTracker* GetVarTracker() = 0; |
33 virtual CallbackTracker* GetCallbackTrackerForInstance( | 42 virtual CallbackTracker* GetCallbackTrackerForInstance( |
34 PP_Instance instance) = 0; | 43 PP_Instance instance) = 0; |
35 | 44 |
36 // Returns the function object corresponding to the given ID, or NULL if | 45 // Returns the function object corresponding to the given ID, or NULL if |
37 // there isn't one. | 46 // there isn't one. |
38 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, ApiID id) = 0; | 47 virtual FunctionGroupBase* GetFunctionAPI(PP_Instance inst, ApiID id) = 0; |
39 | 48 |
40 // Returns the PP_Module associated with the given PP_Instance, or 0 on | 49 // Returns the PP_Module associated with the given PP_Instance, or 0 on |
41 // failure. | 50 // failure. |
42 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; | 51 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; |
43 | 52 |
44 private: | 53 private: |
45 static PpapiGlobals* ppapi_globals_; | 54 static PpapiGlobals* ppapi_globals_; |
| 55 static base::ThreadLocalPointer<PpapiGlobals> ppapi_globals_for_test_; |
46 | 56 |
47 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); | 57 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); |
48 }; | 58 }; |
49 | 59 |
50 } // namespace ppapi | 60 } // namespace ppapi |
51 | 61 |
52 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ | 62 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ |
OLD | NEW |