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

Side by Side Diff: base/mac/scoped_nsexception_enabler.mm

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: willchan comments + rebase Created 9 years, 1 month 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 | « base/lazy_instance_unittest.cc ('k') | base/message_loop.cc » ('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 #import "base/mac/scoped_nsexception_enabler.h" 5 #import "base/mac/scoped_nsexception_enabler.h"
6 6
7 #import "base/lazy_instance.h" 7 #import "base/lazy_instance.h"
8 #import "base/threading/thread_local.h" 8 #import "base/threading/thread_local.h"
9 9
10 // To make the |g_exceptionsAllowed| declaration readable. 10 // To make the |g_exceptionsAllowed| declaration readable.
11 using base::LazyInstance; 11 using base::LazyInstance;
12 using base::LeakyLazyInstanceTraits; 12 using base::LeakyLazyInstanceTraits;
13 using base::ThreadLocalBoolean; 13 using base::ThreadLocalBoolean;
14 14
15 namespace { 15 namespace {
16 16
17 // Whether to allow NSExceptions to be raised on the current thread. 17 // Whether to allow NSExceptions to be raised on the current thread.
18 LazyInstance<ThreadLocalBoolean, LeakyLazyInstanceTraits<ThreadLocalBoolean> > 18 LazyInstance<ThreadLocalBoolean, LeakyLazyInstanceTraits<ThreadLocalBoolean> >
19 g_exceptionsAllowed(base::LINKER_INITIALIZED); 19 g_exceptionsAllowed = LAZY_INSTANCE_INITIALIZER;
20 20
21 } // namespace 21 } // namespace
22 22
23 namespace base { 23 namespace base {
24 namespace mac { 24 namespace mac {
25 25
26 bool GetNSExceptionsAllowed() { 26 bool GetNSExceptionsAllowed() {
27 return g_exceptionsAllowed.Get().Get(); 27 return g_exceptionsAllowed.Get().Get();
28 } 28 }
29 29
30 void SetNSExceptionsAllowed(bool allowed) { 30 void SetNSExceptionsAllowed(bool allowed) {
31 return g_exceptionsAllowed.Get().Set(allowed); 31 return g_exceptionsAllowed.Get().Set(allowed);
32 } 32 }
33 33
34 ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() { 34 ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() {
35 was_enabled_ = GetNSExceptionsAllowed(); 35 was_enabled_ = GetNSExceptionsAllowed();
36 SetNSExceptionsAllowed(true); 36 SetNSExceptionsAllowed(true);
37 } 37 }
38 38
39 ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() { 39 ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() {
40 SetNSExceptionsAllowed(was_enabled_); 40 SetNSExceptionsAllowed(was_enabled_);
41 } 41 }
42 42
43 } // namespace mac 43 } // namespace mac
44 } // namespace base 44 } // namespace base
OLDNEW
« no previous file with comments | « base/lazy_instance_unittest.cc ('k') | base/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698