| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/web_view/test/boolean_observer.h" | 5 #import "ios/web_view/test/observer.h" |
| 6 | 6 |
| 7 #if !defined(__has_feature) || !__has_feature(objc_arc) | 7 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 8 #error "This file requires ARC support." | 8 #error "This file requires ARC support." |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 @implementation BooleanObserver | 11 @implementation Observer |
| 12 | 12 |
| 13 @synthesize keyPath = _keyPath; | 13 @synthesize keyPath = _keyPath; |
| 14 @synthesize lastValue = _lastValue; | 14 @synthesize lastValue = _lastValue; |
| 15 @synthesize object = _object; | 15 @synthesize object = _object; |
| 16 | 16 |
| 17 - (void)setObservedObject:(NSObject*)object keyPath:(NSString*)keyPath { | 17 - (void)setObservedObject:(NSObject*)object keyPath:(NSString*)keyPath { |
| 18 [_object removeObserver:self forKeyPath:_keyPath]; | 18 [_object removeObserver:self forKeyPath:_keyPath]; |
| 19 | 19 |
| 20 _lastValue = nil; | 20 _lastValue = nil; |
| 21 _keyPath = [keyPath copy]; | 21 _keyPath = [keyPath copy]; |
| 22 _object = object; | 22 _object = object; |
| 23 if (keyPath) { | 23 [_object addObserver:self |
| 24 [_object addObserver:self | 24 forKeyPath:_keyPath |
| 25 forKeyPath:_keyPath | 25 options:NSKeyValueObservingOptionNew |
| 26 options:NSKeyValueObservingOptionNew | 26 context:nil]; |
| 27 context:nil]; | |
| 28 } | |
| 29 } | 27 } |
| 30 | 28 |
| 31 - (void)observeValueForKeyPath:(NSString*)keyPath | 29 - (void)observeValueForKeyPath:(NSString*)keyPath |
| 32 ofObject:(id)object | 30 ofObject:(id)object |
| 33 change:(NSDictionary<NSKeyValueChangeKey, id>*)change | 31 change:(NSDictionary<NSKeyValueChangeKey, id>*)change |
| 34 context:(void*)context { | 32 context:(void*)context { |
| 35 if (![object isEqual:_object] || ![keyPath isEqualToString:_keyPath]) { | 33 if (![object isEqual:_object] || ![keyPath isEqualToString:_keyPath]) { |
| 36 // Ignore extraneous call from previous |_object| or |_keyPath|. | 34 // Ignore extraneous call from previous |_object| or |_keyPath|. |
| 37 return; | 35 return; |
| 38 } | 36 } |
| 39 _lastValue = change[NSKeyValueChangeNewKey]; | 37 _lastValue = change[NSKeyValueChangeNewKey]; |
| 40 } | 38 } |
| 41 | 39 |
| 42 - (void)dealloc { | 40 - (void)dealloc { |
| 43 [_object removeObserver:self forKeyPath:_keyPath]; | 41 [_object removeObserver:self forKeyPath:_keyPath]; |
| 44 } | 42 } |
| 45 | 43 |
| 46 @end | 44 @end |
| OLD | NEW |