Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chromecast/base/device_capabilities_impl.h" | 5 #include "chromecast/base/device_capabilities_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 // Make sure that all observers have been removed at this point | 142 // Make sure that all observers have been removed at this point |
| 143 observer_list_->AssertEmpty(); | 143 observer_list_->AssertEmpty(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void DeviceCapabilitiesImpl::Register(const std::string& key, | 146 void DeviceCapabilitiesImpl::Register(const std::string& key, |
| 147 Validator* validator) { | 147 Validator* validator) { |
| 148 DCHECK(IsValidRegisterKey(key)); | 148 DCHECK(IsValidRegisterKey(key)); |
| 149 DCHECK(validator); | 149 DCHECK(validator); |
| 150 | 150 |
| 151 base::AutoLock auto_lock(validation_lock_); | 151 base::AutoLock auto_lock(validation_lock_); |
| 152 bool added = | |
| 153 validator_map_.add(key, base::WrapUnique(new ValidatorInfo(validator))) | |
| 154 .second; | |
| 155 // Check that a validator has not already been registered for this key | 152 // Check that a validator has not already been registered for this key |
| 156 DCHECK(added); | 153 DCHECK_EQ(0u, validator_map_.count(key)); |
| 154 validator_map_[key] = base::WrapUnique(new ValidatorInfo(validator)); | |
|
davidben
2016/04/11 19:27:58
This technically changes behavior in the failed DC
lcwu1
2016/04/11 21:43:03
Yes, I like the new implementation better. Thanks
| |
| 157 } | 155 } |
| 158 | 156 |
| 159 void DeviceCapabilitiesImpl::Unregister(const std::string& key, | 157 void DeviceCapabilitiesImpl::Unregister(const std::string& key, |
| 160 const Validator* validator) { | 158 const Validator* validator) { |
| 161 base::AutoLock auto_lock(validation_lock_); | 159 base::AutoLock auto_lock(validation_lock_); |
| 162 auto validator_it = validator_map_.find(key); | 160 auto validator_it = validator_map_.find(key); |
| 163 DCHECK(validator_it != validator_map_.end()); | 161 DCHECK(validator_it != validator_map_.end()); |
| 164 // Check that validator being unregistered matches the original for |key|. | 162 // Check that validator being unregistered matches the original for |key|. |
| 165 // This prevents managers from accidentally unregistering incorrect | 163 // This prevents managers from accidentally unregistering incorrect |
| 166 // validators. | 164 // validators. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 } | 318 } |
| 321 | 319 |
| 322 // Even though ObserverListThreadSafe notifications are always asynchronous | 320 // Even though ObserverListThreadSafe notifications are always asynchronous |
| 323 // (posts task even if to same thread), no locks should be held at this point | 321 // (posts task even if to same thread), no locks should be held at this point |
| 324 // in the code. This is just to be safe that no deadlocks occur if Observers | 322 // in the code. This is just to be safe that no deadlocks occur if Observers |
| 325 // call DeviceCapabilities methods in OnCapabilitiesChanged(). | 323 // call DeviceCapabilities methods in OnCapabilitiesChanged(). |
| 326 observer_list_->Notify(FROM_HERE, &Observer::OnCapabilitiesChanged, path); | 324 observer_list_->Notify(FROM_HERE, &Observer::OnCapabilitiesChanged, path); |
| 327 } | 325 } |
| 328 | 326 |
| 329 } // namespace chromecast | 327 } // namespace chromecast |
| OLD | NEW |