Index: base/mac/scoped_nsexception_enabler.mm |
diff --git a/base/mac/scoped_nsexception_enabler.mm b/base/mac/scoped_nsexception_enabler.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e79dcd9981fbf3388d2b6c28df60321d0f1a9386 |
--- /dev/null |
+++ b/base/mac/scoped_nsexception_enabler.mm |
@@ -0,0 +1,44 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "base/mac/scoped_nsexception_enabler.h" |
+ |
+#import "base/lazy_instance.h" |
+#import "base/threading/thread_local.h" |
+ |
+// To make the |g_exceptionsAllowed| declaration readable. |
+using base::LazyInstance; |
+using base::LeakyLazyInstanceTraits; |
+using base::ThreadLocalBoolean; |
+ |
+namespace { |
+ |
+// Whether to allow NSExceptions to be raised on the current thread. |
+LazyInstance<ThreadLocalBoolean, LeakyLazyInstanceTraits<ThreadLocalBoolean> > |
+ g_exceptionsAllowed(base::LINKER_INITIALIZED); |
+ |
+} // namespace |
+ |
+namespace base { |
+namespace mac { |
+ |
+bool GetNSExceptionsAllowed() { |
+ return g_exceptionsAllowed.Get().Get(); |
+} |
+ |
+void SetNSExceptionsAllowed(bool allowed) { |
+ return g_exceptionsAllowed.Get().Set(allowed); |
+} |
+ |
+ScopedNSExceptionEnabler::ScopedNSExceptionEnabler(bool enable) { |
+ was_enabled_ = GetNSExceptionsAllowed(); |
+ SetNSExceptionsAllowed(was_enabled_ || enable); |
+} |
+ |
+ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() { |
+ SetNSExceptionsAllowed(was_enabled_); |
+} |
+ |
+} // namespace mac |
+} // namespace base |