| Index: ppapi/shared_impl/ppapi_globals.cc
|
| diff --git a/ppapi/shared_impl/ppapi_globals.cc b/ppapi/shared_impl/ppapi_globals.cc
|
| index 9b5e9a82cb3fede21d10ab13b46f095acb127d8f..1810302ea0cc350973dc454c6c27b33d840e80f0 100644
|
| --- a/ppapi/shared_impl/ppapi_globals.cc
|
| +++ b/ppapi/shared_impl/ppapi_globals.cc
|
| @@ -4,10 +4,21 @@
|
|
|
| #include "ppapi/shared_impl/ppapi_globals.h"
|
|
|
| +#include "base/lazy_instance.h" // For testing purposes only.
|
| #include "base/logging.h"
|
| +#include "base/threading/thread_local.h" // For testing purposes only.
|
|
|
| namespace ppapi {
|
|
|
| +namespace {
|
| +// Thread-local globals for testing. See SetPpapiGlobalsOnThreadForTest for more
|
| +// information.
|
| +base::LazyInstance<
|
| + base::ThreadLocalPointer<PpapiGlobals>,
|
| + base::LeakyLazyInstanceTraits<base::ThreadLocalPointer<PpapiGlobals> > >
|
| + tls_ppapi_globals_for_test = LAZY_INSTANCE_INITIALIZER;
|
| +} // namespace
|
| +
|
| PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL;
|
|
|
| PpapiGlobals::PpapiGlobals() {
|
| @@ -15,9 +26,34 @@ PpapiGlobals::PpapiGlobals() {
|
| ppapi_globals_ = this;
|
| }
|
|
|
| +PpapiGlobals::PpapiGlobals(ForTest) {
|
| + DCHECK(!ppapi_globals_);
|
| +}
|
| +
|
| PpapiGlobals::~PpapiGlobals() {
|
| - DCHECK(ppapi_globals_ == this);
|
| + DCHECK(ppapi_globals_ == this || !ppapi_globals_);
|
| ppapi_globals_ = NULL;
|
| }
|
|
|
| +// static
|
| +void PpapiGlobals::SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr) {
|
| + // If we're using a per-thread PpapiGlobals, we should not have a global one.
|
| + // If we allowed it, it would always over-ride the "test" versions.
|
| + DCHECK(!ppapi_globals_);
|
| + tls_ppapi_globals_for_test.Pointer()->Set(ptr);
|
| +}
|
| +
|
| +bool PpapiGlobals::IsHostGlobals() const {
|
| + return false;
|
| +}
|
| +
|
| +bool PpapiGlobals::IsPluginGlobals() const {
|
| + return false;
|
| +}
|
| +
|
| +// static
|
| +PpapiGlobals* PpapiGlobals::GetThreadLocalPointer() {
|
| + return tls_ppapi_globals_for_test.Pointer()->Get();
|
| +}
|
| +
|
| } // namespace ppapi
|
|
|