| OLD | NEW |
| 1 // Copyright (c) 2011 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 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; | 11 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; |
| 12 base::ThreadLocalPointer<PpapiGlobals> PpapiGlobals::ppapi_globals_for_test_; |
| 12 | 13 |
| 13 PpapiGlobals::PpapiGlobals() { | 14 PpapiGlobals::PpapiGlobals() { |
| 14 DCHECK(!ppapi_globals_); | 15 DCHECK(!ppapi_globals_); |
| 15 ppapi_globals_ = this; | 16 ppapi_globals_ = this; |
| 16 } | 17 } |
| 17 | 18 |
| 19 PpapiGlobals::PpapiGlobals(ForTest) { |
| 20 DCHECK(!ppapi_globals_); |
| 21 } |
| 22 |
| 18 PpapiGlobals::~PpapiGlobals() { | 23 PpapiGlobals::~PpapiGlobals() { |
| 19 DCHECK(ppapi_globals_ == this); | 24 DCHECK(ppapi_globals_ == this || !ppapi_globals_); |
| 20 ppapi_globals_ = NULL; | 25 ppapi_globals_ = NULL; |
| 21 } | 26 } |
| 22 | 27 |
| 28 // static |
| 29 void PpapiGlobals::SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr) { |
| 30 // If we're using a per-thread PpapiGlobals, we should not have a global one. |
| 31 // If we allowed it, it would always over-ride the "test" versions. |
| 32 DCHECK(!ppapi_globals_); |
| 33 ppapi_globals_for_test_.Set(ptr); |
| 34 } |
| 35 |
| 23 } // namespace ppapi | 36 } // namespace ppapi |
| OLD | NEW |