Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: ppapi/shared_impl/ppapi_globals.cc

Issue 9034035: Make it possible to have 1 PpapiGlobals per thread. Update unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments, shared fixes Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 namespace {
12
13 base::ThreadLocalPointer<PpapiGlobals> tls_ppapi_globals_for_test;
14
15 } // namespace
16
11 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; 17 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL;
12 18
13 PpapiGlobals::PpapiGlobals() { 19 PpapiGlobals::PpapiGlobals() {
14 DCHECK(!ppapi_globals_); 20 DCHECK(!ppapi_globals_);
15 ppapi_globals_ = this; 21 ppapi_globals_ = this;
16 } 22 }
17 23
24 PpapiGlobals::PpapiGlobals(ForTest) {
25 DCHECK(!ppapi_globals_);
26 }
27
18 PpapiGlobals::~PpapiGlobals() { 28 PpapiGlobals::~PpapiGlobals() {
19 DCHECK(ppapi_globals_ == this); 29 DCHECK(ppapi_globals_ == this || !ppapi_globals_);
20 ppapi_globals_ = NULL; 30 ppapi_globals_ = NULL;
21 } 31 }
22 32
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 // static
42 PpapiGlobals* PpapiGlobals::GetThreadLocalPointer() {
43 return tls_ppapi_globals_for_test.Get();
44 }
45
23 } // namespace ppapi 46 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698