| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 PerThreadForTest {}; | 46 struct PerThreadForTest {}; |
| 47 explicit PpapiGlobals(PerThreadForTest); | 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 static PpapiGlobals* Get(); |
| 53 if (ppapi_globals_) | |
| 54 return ppapi_globals_; | |
| 55 // In unit tests, the following might be valid (see | |
| 56 // SetPpapiGlobalsOnThreadForTest). Normally, this will just return NULL. | |
| 57 return GetThreadLocalPointer(); | |
| 58 } | |
| 59 | 53 |
| 60 // This allows us to set a given PpapiGlobals object as the PpapiGlobals for | 54 // 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 | 55 // 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 | 56 // 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 | 57 // 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 | 58 // the same process, e.g. for having 1 thread emulate the "host" and 1 thread |
| 65 // emulate the "plugin". | 59 // emulate the "plugin". |
| 66 // | 60 // |
| 67 // PpapiGlobals object must have been constructed using the "PerThreadForTest" | 61 // PpapiGlobals object must have been constructed using the "PerThreadForTest" |
| 68 // parameter. | 62 // parameter. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 124 |
| 131 virtual bool IsHostGlobals() const; | 125 virtual bool IsHostGlobals() const; |
| 132 virtual bool IsPluginGlobals() const; | 126 virtual bool IsPluginGlobals() const; |
| 133 | 127 |
| 134 private: | 128 private: |
| 135 // Return the thread-local pointer which is used only for unit testing. It | 129 // Return the thread-local pointer which is used only for unit testing. It |
| 136 // should always be NULL when running in production. It allows separate | 130 // should always be NULL when running in production. It allows separate |
| 137 // threads to have distinct "globals". | 131 // threads to have distinct "globals". |
| 138 static PpapiGlobals* GetThreadLocalPointer(); | 132 static PpapiGlobals* GetThreadLocalPointer(); |
| 139 | 133 |
| 140 static PpapiGlobals* ppapi_globals_; | |
| 141 | |
| 142 scoped_refptr<base::MessageLoopProxy> main_loop_proxy_; | 134 scoped_refptr<base::MessageLoopProxy> main_loop_proxy_; |
| 143 | 135 |
| 144 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); | 136 DISALLOW_COPY_AND_ASSIGN(PpapiGlobals); |
| 145 }; | 137 }; |
| 146 | 138 |
| 147 } // namespace ppapi | 139 } // namespace ppapi |
| 148 | 140 |
| 149 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ | 141 #endif // PPAPI_SHARED_IMPL_PPAPI_GLOBALS_H_ |
| OLD | NEW |