| OLD | NEW |
| 1 // Copyright (c) 2012 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 #include "ppapi/shared_impl/ppapi_globals.h" | 5 #include "ppapi/shared_impl/ppapi_globals.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace ppapi { | 9 namespace ppapi { |
| 10 | 10 |
| 11 namespace { | |
| 12 | |
| 13 base::ThreadLocalPointer<PpapiGlobals> tls_ppapi_globals_for_test; | |
| 14 | |
| 15 } // namespace | |
| 16 | |
| 17 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; | 11 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; |
| 18 | 12 |
| 19 PpapiGlobals::PpapiGlobals() { | 13 PpapiGlobals::PpapiGlobals() { |
| 20 DCHECK(!ppapi_globals_); | 14 DCHECK(!ppapi_globals_); |
| 21 ppapi_globals_ = this; | 15 ppapi_globals_ = this; |
| 22 } | 16 } |
| 23 | 17 |
| 24 PpapiGlobals::PpapiGlobals(ForTest) { | |
| 25 DCHECK(!ppapi_globals_); | |
| 26 } | |
| 27 | |
| 28 PpapiGlobals::~PpapiGlobals() { | 18 PpapiGlobals::~PpapiGlobals() { |
| 29 DCHECK(ppapi_globals_ == this || !ppapi_globals_); | 19 DCHECK(ppapi_globals_ == this); |
| 30 ppapi_globals_ = NULL; | 20 ppapi_globals_ = NULL; |
| 31 } | 21 } |
| 32 | 22 |
| 33 // static | |
| 34 void PpapiGlobals::SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr) { | |
| 35 // If we're using a per-thread PpapiGlobals, we should not have a global one. | |
| 36 // If we allowed it, it would always over-ride the "test" versions. | |
| 37 DCHECK(!ppapi_globals_); | |
| 38 tls_ppapi_globals_for_test.Set(ptr); | |
| 39 } | |
| 40 | |
| 41 bool PpapiGlobals::IsHostGlobals() const { | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 bool PpapiGlobals::IsPluginGlobals() const { | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 PpapiGlobals* PpapiGlobals::GetThreadLocalPointer() { | |
| 51 return tls_ppapi_globals_for_test.Get(); | |
| 52 } | |
| 53 | |
| 54 } // namespace ppapi | 23 } // namespace ppapi |
| OLD | NEW |