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

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

Issue 9187055: Reland 9034035: Make it possible to have 1 PpapiGlobals per thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « ppapi/shared_impl/ppapi_globals.h ('k') | ppapi/shared_impl/proxy_lock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/lazy_instance.h" // For testing purposes only.
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_local.h" // For testing purposes only.
8 10
9 namespace ppapi { 11 namespace ppapi {
10 12
13 namespace {
14 // Thread-local globals for testing. See SetPpapiGlobalsOnThreadForTest for more
15 // information.
16 base::LazyInstance<
17 base::ThreadLocalPointer<PpapiGlobals>,
18 base::LeakyLazyInstanceTraits<base::ThreadLocalPointer<PpapiGlobals> > >
19 tls_ppapi_globals_for_test = LAZY_INSTANCE_INITIALIZER;
20 } // namespace
21
11 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL; 22 PpapiGlobals* PpapiGlobals::ppapi_globals_ = NULL;
12 23
13 PpapiGlobals::PpapiGlobals() { 24 PpapiGlobals::PpapiGlobals() {
14 DCHECK(!ppapi_globals_); 25 DCHECK(!ppapi_globals_);
15 ppapi_globals_ = this; 26 ppapi_globals_ = this;
16 } 27 }
17 28
29 PpapiGlobals::PpapiGlobals(ForTest) {
30 DCHECK(!ppapi_globals_);
31 }
32
18 PpapiGlobals::~PpapiGlobals() { 33 PpapiGlobals::~PpapiGlobals() {
19 DCHECK(ppapi_globals_ == this); 34 DCHECK(ppapi_globals_ == this || !ppapi_globals_);
20 ppapi_globals_ = NULL; 35 ppapi_globals_ = NULL;
21 } 36 }
22 37
38 // static
39 void PpapiGlobals::SetPpapiGlobalsOnThreadForTest(PpapiGlobals* ptr) {
40 // If we're using a per-thread PpapiGlobals, we should not have a global one.
41 // If we allowed it, it would always over-ride the "test" versions.
42 DCHECK(!ppapi_globals_);
43 tls_ppapi_globals_for_test.Pointer()->Set(ptr);
44 }
45
46 bool PpapiGlobals::IsHostGlobals() const {
47 return false;
48 }
49
50 bool PpapiGlobals::IsPluginGlobals() const {
51 return false;
52 }
53
54 // static
55 PpapiGlobals* PpapiGlobals::GetThreadLocalPointer() {
56 return tls_ppapi_globals_for_test.Pointer()->Get();
57 }
58
23 } // namespace ppapi 59 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppapi_globals.h ('k') | ppapi/shared_impl/proxy_lock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698