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

Unified Diff: base/mac/scoped_objc_class_swizzler.h

Issue 345243007: Add ScopedObjCClassSwizzler in base/mac, absorbs objc_method_swizzle and ScopedClassSwizzler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix EventsMacTest.ButtonEvents Created 6 years, 5 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
Index: base/mac/scoped_objc_class_swizzler.h
diff --git a/base/mac/scoped_objc_class_swizzler.h b/base/mac/scoped_objc_class_swizzler.h
new file mode 100644
index 0000000000000000000000000000000000000000..03c131d1b4e4ab32ebded28d487af640c6bbc2fa
--- /dev/null
+++ b/base/mac/scoped_objc_class_swizzler.h
@@ -0,0 +1,38 @@
+// Copyright 2014 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.
+
+#ifndef BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_
+#define BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_
+
+#import <objc/runtime.h>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+
+namespace base {
+namespace mac {
+
+// Within a given scope, replace the selector |selector| on |target| with that
+// from |source|.
+class BASE_EXPORT ScopedObjCClassSwizzler {
+ public:
+ ScopedObjCClassSwizzler(Class target, Class source, SEL selector);
+ ~ScopedObjCClassSwizzler();
+
+ // Return a callable function pointer for the replaced method. To call this
+ // from the replacing function, the first two arguments should be |self| and
+ // |_cmd|. These are followed by the (variadic) method arguments.
+ IMP GetOriginalImplementation();
+
+ private:
+ Method old_selector_impl_;
+ Method new_selector_impl_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedObjCClassSwizzler);
+};
+
+} // namespace mac
+} // namespace base
+
+#endif // BASE_MAC_SCOPED_OBJC_CLASS_SWIZZLER_H_

Powered by Google App Engine
This is Rietveld 408576698