This source file includes following definitions.
- Get
- SetPpapiGlobalsOnThreadForTest
- GetMainThreadMessageLoop
- ResetMainThreadMessageLoopForTesting
- IsHostGlobals
- IsPluginGlobals
- MarkPluginIsActive
- GetThreadLocalPointer
#include "ppapi/shared_impl/ppapi_globals.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/threading/thread_local.h"
namespace ppapi {
namespace {
base::LazyInstance<base::ThreadLocalPointer<PpapiGlobals> >::Leaky
tls_ppapi_globals_for_test = LAZY_INSTANCE_INITIALIZER;
}
PpapiGlobals* ppapi_globals = NULL;
PpapiGlobals::PpapiGlobals() {
DCHECK(!ppapi_globals);
ppapi_globals = this;
main_loop_proxy_ = base::MessageLoopProxy::current();
}
PpapiGlobals::PpapiGlobals(PerThreadForTest) {
DCHECK(!ppapi_globals);
main_loop_proxy_ = base::MessageLoopProxy::current();
}
PpapiGlobals::~PpapiGlobals() {
DCHECK(ppapi_globals == this || !ppapi_globals);
ppapi_globals = NULL;
}
PpapiGlobals* PpapiGlobals::Get() {
if (ppapi_globals)
return ppapi_globals;
return GetThreadLocalPointer();
}
void PpapiGlobals::SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr) {
DCHECK(!ppapi_globals);
tls_ppapi_globals_for_test.Pointer()->Set(ptr);
}
base::MessageLoopProxy* PpapiGlobals::GetMainThreadMessageLoop() {
return main_loop_proxy_.get();
}
void PpapiGlobals::ResetMainThreadMessageLoopForTesting() {
main_loop_proxy_ = base::MessageLoopProxy::current();
}
bool PpapiGlobals::IsHostGlobals() const { return false; }
bool PpapiGlobals::IsPluginGlobals() const { return false; }
void PpapiGlobals::MarkPluginIsActive() {}
PpapiGlobals* PpapiGlobals::GetThreadLocalPointer() {
return tls_ppapi_globals_for_test.Pointer()->Get();
}
}