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" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/threading/thread_local.h" // For testing purposes only. | 12 #include "base/threading/thread_local.h" // For testing purposes only. |
13 #include "ppapi/c/dev/ppb_console_dev.h" | 13 #include "ppapi/c/dev/ppb_console_dev.h" |
14 #include "ppapi/c/pp_instance.h" | 14 #include "ppapi/c/pp_instance.h" |
15 #include "ppapi/c/pp_module.h" | 15 #include "ppapi/c/pp_module.h" |
16 #include "ppapi/shared_impl/api_id.h" | 16 #include "ppapi/shared_impl/api_id.h" |
17 #include "ppapi/shared_impl/ppapi_shared_export.h" | 17 #include "ppapi/shared_impl/ppapi_shared_export.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class Lock; | 20 class Lock; |
21 class MessageLoopProxy; | 21 class MessageLoopProxy; |
22 } | 22 } |
23 | 23 |
24 namespace ppapi { | 24 namespace ppapi { |
25 | 25 |
26 class CallbackTracker; | 26 class CallbackTracker; |
| 27 class MessageLoopShared; |
27 class ResourceTracker; | 28 class ResourceTracker; |
28 class VarTracker; | 29 class VarTracker; |
29 | 30 |
30 namespace thunk { | 31 namespace thunk { |
31 class PPB_Instance_API; | 32 class PPB_Instance_API; |
32 class ResourceCreationAPI; | 33 class ResourceCreationAPI; |
33 } | 34 } |
34 | 35 |
35 // Abstract base class | 36 // Abstract base class |
36 class PPAPI_SHARED_EXPORT PpapiGlobals { | 37 class PPAPI_SHARED_EXPORT PpapiGlobals { |
37 public: | 38 public: |
| 39 // Must be created on the main thread. |
38 PpapiGlobals(); | 40 PpapiGlobals(); |
39 | 41 |
40 // 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 |
41 // purposes. This avoids setting the global static ppapi_globals_. For unit | 43 // purposes. This avoids setting the global static ppapi_globals_. For unit |
42 // tests that use this feature, the "test" PpapiGlobals should be constructed | 44 // tests that use this feature, the "test" PpapiGlobals should be constructed |
43 // using this method. See SetPpapiGlobalsOnThreadForTest for more information. | 45 // using this method. See SetPpapiGlobalsOnThreadForTest for more information. |
44 struct ForTest {}; | 46 struct ForTest {}; |
45 PpapiGlobals(ForTest); | 47 explicit PpapiGlobals(ForTest); |
46 | 48 |
47 virtual ~PpapiGlobals(); | 49 virtual ~PpapiGlobals(); |
48 | 50 |
49 // Getter for the global singleton. | 51 // Getter for the global singleton. |
50 inline static PpapiGlobals* Get() { | 52 inline static PpapiGlobals* Get() { |
51 if (ppapi_globals_) | 53 if (ppapi_globals_) |
52 return ppapi_globals_; | 54 return ppapi_globals_; |
53 // In unit tests, the following might be valid (see | 55 // In unit tests, the following might be valid (see |
54 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL. | 56 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL. |
55 return GetThreadLocalPointer(); | 57 return GetThreadLocalPointer(); |
56 } | 58 } |
57 | 59 |
58 // 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 |
59 // 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 |
60 // 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 |
61 // 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 |
62 // 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 |
63 // emulate the "plugin". | 65 // emulate the "plugin". |
64 // | 66 // |
65 // PpapiGlobals object must have been constructed using the "ForTest" | 67 // PpapiGlobals object must have been constructed using the "ForTest" |
66 // parameter. | 68 // parameter. |
67 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr); | 69 static void SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr); |
68 | 70 |
69 // Retrieves the corresponding tracker. | 71 // Retrieves the corresponding tracker. |
70 virtual ResourceTracker* GetResourceTracker() = 0; | 72 virtual ResourceTracker* GetResourceTracker() = 0; |
71 virtual VarTracker* GetVarTracker() = 0; | 73 virtual VarTracker* GetVarTracker() = 0; |
72 virtual CallbackTracker* GetCallbackTrackerForInstance( | 74 virtual CallbackTracker* GetCallbackTrackerForInstance( |
73 PP_Instance instance) = 0; | 75 PP_Instance instance) = 0; |
| 76 |
74 virtual base::Lock* GetProxyLock() = 0; | 77 virtual base::Lock* GetProxyLock() = 0; |
75 | 78 |
76 // Logs the given string to the JS console. If "source" is empty, the name of | 79 // Logs the given string to the JS console. If "source" is empty, the name of |
77 // the current module will be used, if it can be determined. | 80 // the current module will be used, if it can be determined. |
78 virtual void LogWithSource(PP_Instance instance, | 81 virtual void LogWithSource(PP_Instance instance, |
79 PP_LogLevel_Dev level, | 82 PP_LogLevel_Dev level, |
80 const std::string& source, | 83 const std::string& source, |
81 const std::string& value) = 0; | 84 const std::string& value) = 0; |
82 | 85 |
83 // Like LogWithSource but broadcasts the log to all instances of the given | 86 // Like LogWithSource but broadcasts the log to all instances of the given |
(...skipping 12 matching lines...) Expand all Loading... |
96 // Returns the given API object associated with the given instance, or NULL | 99 // Returns the given API object associated with the given instance, or NULL |
97 // if the instance is invalid. | 100 // if the instance is invalid. |
98 virtual thunk::PPB_Instance_API* GetInstanceAPI(PP_Instance instance) = 0; | 101 virtual thunk::PPB_Instance_API* GetInstanceAPI(PP_Instance instance) = 0; |
99 virtual thunk::ResourceCreationAPI* GetResourceCreationAPI( | 102 virtual thunk::ResourceCreationAPI* GetResourceCreationAPI( |
100 PP_Instance instance) = 0; | 103 PP_Instance instance) = 0; |
101 | 104 |
102 // Returns the PP_Module associated with the given PP_Instance, or 0 on | 105 // Returns the PP_Module associated with the given PP_Instance, or 0 on |
103 // failure. | 106 // failure. |
104 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; | 107 virtual PP_Module GetModuleForInstance(PP_Instance instance) = 0; |
105 | 108 |
106 // Returns the base::MessageLoopProxy for the main thread. Note that this must | 109 // Returns the base::MessageLoopProxy for the main thread. This is set in the |
107 // be called on the main thread the first time so that it can initialize | 110 // constructor, so PpapiGlobals must be created on the main thread. |
108 // its static data. | |
109 base::MessageLoopProxy* GetMainThreadMessageLoop(); | 111 base::MessageLoopProxy* GetMainThreadMessageLoop(); |
110 | 112 |
| 113 // Return the MessageLoopShared of the current thread, if any. This will |
| 114 // always return NULL on the host side, where PPB_MessageLoop is not |
| 115 // supported. |
| 116 virtual MessageLoopShared* GetCurrentMessageLoop() = 0; |
| 117 |
111 // Returns the command line for the process. | 118 // Returns the command line for the process. |
112 virtual std::string GetCmdLine() = 0; | 119 virtual std::string GetCmdLine() = 0; |
113 | 120 |
114 // Preloads the font on Windows, does nothing on other platforms. | 121 // Preloads the font on Windows, does nothing on other platforms. |
115 // TODO(brettw) remove this by passing the instance into the API so we don't | 122 // TODO(brettw) remove this by passing the instance into the API so we don't |
116 // have to have it on the globals. | 123 // have to have it on the globals. |
117 virtual void PreCacheFontForFlash(const void* logfontw) = 0; | 124 virtual void PreCacheFontForFlash(const void* logfontw) = 0; |
118 | 125 |
119 virtual bool IsHostGlobals() const; | 126 virtual bool IsHostGlobals() const; |
120 virtual bool IsPluginGlobals() const; | 127 virtual bool IsPluginGlobals() const; |
121 | 128 |
122 private: | 129 private: |
123 // Return the thread-local pointer which is used only for unit testing. It | 130 // Return the thread-local pointer which is used only for unit testing. It |
124 // should always be NULL when running in production. It allows separate | 131 // should always be NULL when running in production. It allows separate |
125 // threads to have distinct "globals". | 132 // threads to have distinct "globals". |
126 static PpapiGlobals* GetThreadLocalPointer(); | 133 static PpapiGlobals* GetThreadLocalPointer(); |
127 | 134 |
128 static PpapiGlobals* ppapi_globals_; | 135 static PpapiGlobals* ppapi_globals_; |
129 | 136 |
130 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 137 scoped_refptr<base::MessageLoopProxy> main_loop_proxy_; |
131 | 138 |
132 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); | 139 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); |
133 }; | 140 }; |
134 | 141 |
135 } // namespace ppapi | 142 } // namespace ppapi |
136 | 143 |
137 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ | 144 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ |
OLD | NEW |