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

Unified Diff: chrome/common/mac/objc_method_swizzle.mm

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: Inlude in shiny new gn base_unittests target Created 6 years, 4 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 | « chrome/common/mac/objc_method_swizzle.h ('k') | chrome/common/mac/objc_method_swizzle_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/mac/objc_method_swizzle.mm
diff --git a/chrome/common/mac/objc_method_swizzle.mm b/chrome/common/mac/objc_method_swizzle.mm
deleted file mode 100644
index 62b630a11a8809bb1de5c406022dd3d405d4bdb3..0000000000000000000000000000000000000000
--- a/chrome/common/mac/objc_method_swizzle.mm
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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 "chrome/common/mac/objc_method_swizzle.h"
-
-#import "base/logging.h"
-
-namespace ObjcEvilDoers {
-
-Method GetImplementedInstanceMethod(Class aClass, SEL aSelector) {
- Method method = NULL;
- unsigned int methodCount = 0;
- Method* methodList = class_copyMethodList(aClass, &methodCount);
- if (methodList) {
- for (unsigned int i = 0; i < methodCount; ++i) {
- if (method_getName(methodList[i]) == aSelector) {
- method = methodList[i];
- break;
- }
- }
- free(methodList);
- }
- return method;
-}
-
-IMP SwizzleImplementedInstanceMethods(
- Class aClass, const SEL originalSelector, const SEL alternateSelector) {
- // The methods must both be implemented by the target class, not
- // inherited from a superclass.
- Method original = GetImplementedInstanceMethod(aClass, originalSelector);
- Method alternate = GetImplementedInstanceMethod(aClass, alternateSelector);
- DCHECK(original);
- DCHECK(alternate);
- if (!original || !alternate) {
- return NULL;
- }
-
- // The argument and return types must match exactly.
- const char* originalTypes = method_getTypeEncoding(original);
- const char* alternateTypes = method_getTypeEncoding(alternate);
- DCHECK(originalTypes);
- DCHECK(alternateTypes);
- DCHECK(0 == strcmp(originalTypes, alternateTypes));
- if (!originalTypes || !alternateTypes ||
- strcmp(originalTypes, alternateTypes)) {
- return NULL;
- }
-
- IMP ret = method_getImplementation(original);
- if (ret) {
- method_exchangeImplementations(original, alternate);
- }
- return ret;
-}
-
-} // namespace ObjcEvilDoers
« no previous file with comments | « chrome/common/mac/objc_method_swizzle.h ('k') | chrome/common/mac/objc_method_swizzle_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698