diff options
Diffstat (limited to 'chrome/browser/prefs/pref_change_registrar.cc')
-rw-r--r-- | chrome/browser/prefs/pref_change_registrar.cc | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/chrome/browser/prefs/pref_change_registrar.cc b/chrome/browser/prefs/pref_change_registrar.cc index dc8bb97..05372b1 100644 --- a/chrome/browser/prefs/pref_change_registrar.cc +++ b/chrome/browser/prefs/pref_change_registrar.cc @@ -9,16 +9,11 @@ PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {} PrefChangeRegistrar::~PrefChangeRegistrar() { - if (service_) { - for (std::set<ObserverRegistration>::const_iterator it = observers_.begin(); - it != observers_.end(); ++it) { - service_->RemovePrefObserver(it->first.c_str(), it->second); - } - } + RemoveAll(); } void PrefChangeRegistrar::Init(PrefService* service) { - DCHECK(!service_); + DCHECK(IsEmpty() || service_ == service); service_ = service; } @@ -51,3 +46,17 @@ void PrefChangeRegistrar::Remove(const char* path, NotificationObserver* obs) { service_->RemovePrefObserver(it->first.c_str(), it->second); observers_.erase(it); } + +void PrefChangeRegistrar::RemoveAll() { + if (service_) { + for (std::set<ObserverRegistration>::const_iterator it = observers_.begin(); + it != observers_.end(); ++it) { + service_->RemovePrefObserver(it->first.c_str(), it->second); + } + observers_.clear(); + } +} + +bool PrefChangeRegistrar::IsEmpty() const { + return observers_.empty(); +} |