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

Unified Diff: base/mac/scoped_nsexception_enabler.mm

Issue 7038010: [Mac] Allow NSExceptions in certain cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Oh, clang, you crazy fox. Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/mac/scoped_nsexception_enabler.h ('k') | chrome/browser/chrome_browser_application_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6815de3fbf0b57aa6856623600e318a1f5c968d5
--- /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() {
+ was_enabled_ = GetNSExceptionsAllowed();
+ SetNSExceptionsAllowed(true);
+}
+
+ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() {
+ SetNSExceptionsAllowed(was_enabled_);
+}
+
+} // namespace mac
+} // namespace base
« no previous file with comments | « base/mac/scoped_nsexception_enabler.h ('k') | chrome/browser/chrome_browser_application_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698