OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "base/mac/scoped_nsexception_enabler.h" |
| 6 |
| 7 #import "base/lazy_instance.h" |
| 8 #import "base/threading/thread_local.h" |
| 9 |
| 10 // To make the |g_exceptionsAllowed| declaration readable. |
| 11 using base::LazyInstance; |
| 12 using base::LeakyLazyInstanceTraits; |
| 13 using base::ThreadLocalBoolean; |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Whether to allow NSExceptions to be raised on the current thread. |
| 18 LazyInstance<ThreadLocalBoolean, LeakyLazyInstanceTraits<ThreadLocalBoolean> > |
| 19 g_exceptionsAllowed(base::LINKER_INITIALIZED); |
| 20 |
| 21 } // namespace |
| 22 |
| 23 namespace base { |
| 24 namespace mac { |
| 25 |
| 26 bool GetNSExceptionsAllowed() { |
| 27 return g_exceptionsAllowed.Get().Get(); |
| 28 } |
| 29 |
| 30 void SetNSExceptionsAllowed(bool allowed) { |
| 31 return g_exceptionsAllowed.Get().Set(allowed); |
| 32 } |
| 33 |
| 34 ScopedNSExceptionEnabler::ScopedNSExceptionEnabler() { |
| 35 was_enabled_ = GetNSExceptionsAllowed(); |
| 36 SetNSExceptionsAllowed(true); |
| 37 } |
| 38 |
| 39 ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() { |
| 40 SetNSExceptionsAllowed(was_enabled_); |
| 41 } |
| 42 |
| 43 } // namespace mac |
| 44 } // namespace base |
OLD | NEW |