Index: ui/base/test/scoped_preferred_scroller_style_mac.mm |
diff --git a/ui/base/test/scoped_preferred_scroller_style_mac.mm b/ui/base/test/scoped_preferred_scroller_style_mac.mm |
index 1a73819bd122591ef9f27ec219f103fa89e0b5d9..84eb27503000301b226272f9d9f2257708f2db6d 100644 |
--- a/ui/base/test/scoped_preferred_scroller_style_mac.mm |
+++ b/ui/base/test/scoped_preferred_scroller_style_mac.mm |
@@ -6,12 +6,17 @@ |
#import <AppKit/AppKit.h> |
+#include "base/logging.h" |
#import "base/mac/scoped_objc_class_swizzler.h" |
using base::mac::ScopedObjCClassSwizzler; |
namespace { |
+// Swizzling can be stacked, but not interleaved without creating unexpected |
+// states. Require that there is only one swizzler rather than tracking a stack. |
+bool g_swizzling = false; |
+ |
void NotifyStyleChanged() { |
[[NSNotificationCenter defaultCenter] |
postNotificationName:NSPreferredScrollerStyleDidChangeNotification |
@@ -60,6 +65,8 @@ ScopedPreferredScrollerStyle::ScopedPreferredScrollerStyle(bool overlay) |
? [FakeNSScrollerPreferredStyleOverlayDonor class] |
: [FakeNSScrollerPreferredStyleLegacyDonor class]; |
+ DCHECK(!g_swizzling); |
+ g_swizzling = true; |
swizzler_.reset(new ScopedObjCClassSwizzler( |
[NSScroller class], style_class, @selector(preferredScrollerStyle))); |
@@ -69,6 +76,8 @@ ScopedPreferredScrollerStyle::ScopedPreferredScrollerStyle(bool overlay) |
ScopedPreferredScrollerStyle::~ScopedPreferredScrollerStyle() { |
swizzler_.reset(); |
+ DCHECK(g_swizzling); |
+ g_swizzling = false; |
if ([NSScroller preferredScrollerStyle] != GetScrollerStyle(overlay_)) |
NotifyStyleChanged(); |