Chromium Code Reviews| 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 if (_object) { | |
|
Eugene But (OOO till 7-30)
2017/05/23 19:49:33
No need for this check, it's perfectly fine to cal
michaeldo
2017/05/24 15:02:34
Done.
| |
| 19 [_object removeObserver:self forKeyPath:_keyPath]; | |
| 20 } | |
| 21 | |
| 22 _lastValue = NO; | |
| 23 _keyPath = [keyPath copy]; | |
| 24 _object = object; | |
| 25 if (keyPath) { | |
|
Eugene But (OOO till 7-30)
2017/05/23 19:49:33
Is is there a value in passing nil keyPath? Should
michaeldo
2017/05/24 15:02:34
It's the only current way to stop this object from
Eugene But (OOO till 7-30)
2017/05/24 15:32:14
I think if we need API for stopping the observing,
| |
| 26 [_object addObserver:self | |
| 27 forKeyPath:_keyPath | |
| 28 options:NSKeyValueObservingOptionNew | |
| 29 context:nil]; | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 - (void)observeValueForKeyPath:(NSString*)keyPath | |
| 34 ofObject:(id)object | |
| 35 change:(NSDictionary<NSKeyValueChangeKey, id>*)change | |
| 36 context:(void*)context { | |
| 37 if (object != _object || keyPath != _keyPath) { | |
| 38 // Ignore extraneous call from previous |_object| or |_keyPath|. | |
| 39 return; | |
| 40 } | |
| 41 _lastValue = [change[NSKeyValueChangeNewKey] boolValue]; | |
| 42 } | |
| 43 | |
| 44 - (void)dealloc { | |
| 45 [_object removeObserver:self forKeyPath:_keyPath]; | |
| 46 } | |
| 47 | |
| 48 @end | |
| OLD | NEW |