| 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 #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 |
| OLD | NEW |