| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/test/base/scoped_block_swizzler.h" | 5 #include "ios/chrome/test/base/scoped_block_swizzler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 ScopedBlockSwizzler::ScopedBlockSwizzler(Class target, SEL selector, id block) { | 9 ScopedBlockSwizzler::ScopedBlockSwizzler(Class target, SEL selector, id block) { |
| 10 method_ = class_getInstanceMethod(target, selector); | 10 method_ = class_getInstanceMethod(target, selector); |
| 11 if (!method_) { | 11 if (!method_) { |
| 12 // Try swizzling a class method instead. | 12 // Try swizzling a class method instead. |
| 13 method_ = class_getClassMethod(target, selector); | 13 method_ = class_getClassMethod(target, selector); |
| 14 } | 14 } |
| 15 DCHECK(method_); | 15 DCHECK(method_); |
| 16 | 16 |
| 17 IMP block_imp = imp_implementationWithBlock(block); | 17 IMP block_imp = imp_implementationWithBlock(block); |
| 18 original_imp_ = method_setImplementation(method_, block_imp); | 18 original_imp_ = method_setImplementation(method_, block_imp); |
| 19 } | 19 } |
| 20 | 20 |
| 21 ScopedBlockSwizzler::~ScopedBlockSwizzler() { | 21 ScopedBlockSwizzler::~ScopedBlockSwizzler() { |
| 22 IMP block_imp = method_setImplementation(method_, original_imp_); | 22 IMP block_imp = method_setImplementation(method_, original_imp_); |
| 23 DCHECK(imp_removeBlock(block_imp)); | 23 DCHECK(imp_removeBlock(block_imp)); |
| 24 } | 24 } |
| OLD | NEW |