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