| Index: base/test/scoped_class_swizzler_mac.mm
|
| diff --git a/base/test/scoped_class_swizzler_mac.mm b/base/test/scoped_class_swizzler_mac.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fb6506b8abb58ea1833514d21b76ff19b2b5c435
|
| --- /dev/null
|
| +++ b/base/test/scoped_class_swizzler_mac.mm
|
| @@ -0,0 +1,25 @@
|
| +// 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.
|
| +
|
| +#include "base/test/scoped_class_swizzler_mac.h"
|
| +
|
| +namespace base {
|
| +
|
| +ScopedClassSwizzler::ScopedClassSwizzler(Class target, Class source,
|
| + SEL selector) {
|
| + old_selector_impl_ = class_getInstanceMethod(target, selector);
|
| + new_selector_impl_ = class_getInstanceMethod(source, selector);
|
| + if (!old_selector_impl_ && !new_selector_impl_) {
|
| + // Try class methods.
|
| + old_selector_impl_ = class_getClassMethod(target, selector);
|
| + new_selector_impl_ = class_getClassMethod(source, selector);
|
| + }
|
| + method_exchangeImplementations(old_selector_impl_, new_selector_impl_);
|
| +}
|
| +
|
| +ScopedClassSwizzler::~ScopedClassSwizzler() {
|
| + method_exchangeImplementations(old_selector_impl_, new_selector_impl_);
|
| +}
|
| +
|
| +} // namespace base
|
|
|