Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11231)

Unified Diff: chromecast/base/device_capabilities_impl.cc

Issue 1401993002: Refactoring DeviceCapabilities unit test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unregister() does not remove capability. Register() does not take initial value. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromecast/base/device_capabilities_impl.h ('k') | chromecast/base/device_capabilities_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/base/device_capabilities_impl.cc
diff --git a/chromecast/base/device_capabilities_impl.cc b/chromecast/base/device_capabilities_impl.cc
index bc4be65122f5924e6ad871d15698d21bc0ce2c9c..7361390cfd20c2f031dbd18b60f41f8d79d6465a 100644
--- a/chromecast/base/device_capabilities_impl.cc
+++ b/chromecast/base/device_capabilities_impl.cc
@@ -83,33 +83,31 @@ DeviceCapabilitiesImpl::~DeviceCapabilitiesImpl() {
}
void DeviceCapabilitiesImpl::Register(const std::string& key,
- scoped_ptr<base::Value> init_value,
Validator* validator) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(IsValidRegisterKey(key));
- DCHECK(init_value.get());
DCHECK(validator);
- AddValidator(key, validator);
-
- capabilities_->Set(key, init_value.Pass());
- UpdateStrAndNotifyChanged(key);
+ bool added = validator_map_.insert(std::make_pair(key, validator)).second;
+ // Check that a validator has not already been registered for this key
+ DCHECK(added);
}
void DeviceCapabilitiesImpl::Unregister(const std::string& key,
const Validator* validator) {
DCHECK(thread_checker_.CalledOnValidThread());
- auto validator_it = validator_map_.find(key);
- DCHECK(validator_it != validator_map_.end());
// Check that validator being unregistered matches the original for |key|.
// This prevents managers from accidentally unregistering incorrect
// validators.
- DCHECK_EQ(validator, validator_it->second);
- validator_map_.erase(validator_it);
+ DCHECK_EQ(validator, GetValidator(key));
+ bool erased = validator_map_.erase(key);
+ DCHECK(erased);
+}
- bool removed = capabilities_->Remove(key, nullptr);
- DCHECK(removed);
- UpdateStrAndNotifyChanged(key);
+DeviceCapabilities::Validator* DeviceCapabilitiesImpl::GetValidator(
+ const std::string& key) const {
+ auto validator_it = validator_map_.find(key);
+ return validator_it == validator_map_.end() ? nullptr : validator_it->second;
}
bool DeviceCapabilitiesImpl::BluetoothSupported() const {
@@ -208,14 +206,6 @@ void DeviceCapabilitiesImpl::SetValidatedValueInternal(
UpdateStrAndNotifyChanged(path);
}
-void DeviceCapabilitiesImpl::AddValidator(const std::string& key,
- Validator* validator) {
- DCHECK(validator);
- bool added = validator_map_.insert(std::make_pair(key, validator)).second;
- // Check that a validator has not already been registered for this key
- DCHECK(added);
-}
-
void DeviceCapabilitiesImpl::UpdateStrAndNotifyChanged(
const std::string& path) {
// Update capabilities string here since all updates to capabilities must
« no previous file with comments | « chromecast/base/device_capabilities_impl.h ('k') | chromecast/base/device_capabilities_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698