| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/ios/crb_protocol_observers.h" | 5 #import "base/ios/crb_protocol_observers.h" |
| 6 | 6 |
| 7 #include <objc/runtime.h> | 7 #include <objc/runtime.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 - (Protocol*)protocol { | 99 - (Protocol*)protocol { |
| 100 return _protocol.get(); | 100 return _protocol.get(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 - (void)addObserver:(id)observer { | 103 - (void)addObserver:(id)observer { |
| 104 DCHECK(observer); | 104 DCHECK(observer); |
| 105 DCHECK([observer conformsToProtocol:self.protocol]); | 105 DCHECK([observer conformsToProtocol:self.protocol]); |
| 106 | 106 |
| 107 if (ContainsValue(_observers, observer)) | 107 if (base::ContainsValue(_observers, observer)) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 _observers.push_back(observer); | 110 _observers.push_back(observer); |
| 111 } | 111 } |
| 112 | 112 |
| 113 - (void)removeObserver:(id)observer { | 113 - (void)removeObserver:(id)observer { |
| 114 DCHECK(observer); | 114 DCHECK(observer); |
| 115 auto it = std::find(_observers.begin(), _observers.end(), observer); | 115 auto it = std::find(_observers.begin(), _observers.end(), observer); |
| 116 if (it != _observers.end()) { | 116 if (it != _observers.end()) { |
| 117 if (_invocationDepth) | 117 if (_invocationDepth) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 #pragma mark - Private | 183 #pragma mark - Private |
| 184 | 184 |
| 185 - (void)compact { | 185 - (void)compact { |
| 186 DCHECK(!_invocationDepth); | 186 DCHECK(!_invocationDepth); |
| 187 _observers.erase(std::remove(_observers.begin(), _observers.end(), nil), | 187 _observers.erase(std::remove(_observers.begin(), _observers.end(), nil), |
| 188 _observers.end()); | 188 _observers.end()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 @end | 191 @end |
| OLD | NEW |