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

Unified Diff: chrome/browser/prefs/pref_notifier_impl.cc

Issue 11368098: Draft change to use base::Closure instead of PrefObserver in PrefChangeRegistrar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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
Index: chrome/browser/prefs/pref_notifier_impl.cc
diff --git a/chrome/browser/prefs/pref_notifier_impl.cc b/chrome/browser/prefs/pref_notifier_impl.cc
index 9bdf32221978b811a9608867921152df309f6b6a..5df6237a99210d7544a6cc840a7077479232e727 100644
--- a/chrome/browser/prefs/pref_notifier_impl.cc
+++ b/chrome/browser/prefs/pref_notifier_impl.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/prefs/pref_notifier_impl.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -22,8 +23,7 @@ PrefNotifierImpl::~PrefNotifierImpl() {
// Verify that there are no pref observers when we shut down.
for (PrefObserverMap::iterator it = pref_observers_.begin();
it != pref_observers_.end(); ++it) {
- PrefObserverList::Iterator obs_iterator(*(it->second));
- if (obs_iterator.GetNext()) {
+ if (!it->second->empty()) {
LOG(WARNING) << "pref observer found at shutdown " << it->first;
}
}
@@ -39,7 +39,7 @@ PrefNotifierImpl::~PrefNotifierImpl() {
}
void PrefNotifierImpl::AddPrefObserver(const char* path,
- PrefObserver* obs) {
+ const base::Closure& obs) {
// Get the pref observer list associated with the path.
PrefObserverList* observer_list = NULL;
const PrefObserverMap::iterator observer_iterator =
@@ -51,13 +51,25 @@ void PrefNotifierImpl::AddPrefObserver(const char* path,
observer_list = observer_iterator->second;
}
- // Add the pref observer. ObserverList will DCHECK if it already is
- // in the list.
- observer_list->AddObserver(obs);
+ // Add the pref observer.
+ // TODO(joi): DO NOT COMMIT must DCHECK if already in list
+ observer_list->push_back(obs);
}
+class SameObserverPredicate {
+ public:
+ SameObserverPredicate(const base::Closure& observer) : obs_(observer) {}
+
+ bool operator ()(const base::Closure& other) {
+ return obs_.Equals(other);
+ }
+
+ private:
+ const base::Closure& obs_;
+};
+
void PrefNotifierImpl::RemovePrefObserver(const char* path,
- PrefObserver* obs) {
+ const base::Closure& obs) {
DCHECK(CalledOnValidThread());
const PrefObserverMap::iterator observer_iterator =
@@ -67,7 +79,10 @@ void PrefNotifierImpl::RemovePrefObserver(const char* path,
}
PrefObserverList* observer_list = observer_iterator->second;
- observer_list->RemoveObserver(obs);
+ // TODO(joi): DO NOT COMMIT, DCHECK if not found.
+ observer_list->erase(
+ std::find_if(observer_list->begin(), observer_list->end(),
+ SameObserverPredicate(obs)));
}
void PrefNotifierImpl::AddInitObserver(base::Callback<void(bool)> obs) {
@@ -106,9 +121,11 @@ void PrefNotifierImpl::FireObservers(const std::string& path) {
if (observer_iterator == pref_observers_.end())
return;
- FOR_EACH_OBSERVER(PrefObserver,
- *(observer_iterator->second),
- OnPreferenceChanged(pref_service_, path));
+ for (PrefObserverList::iterator it = observer_iterator->second->begin();
+ it != observer_iterator->second->end();
+ ++it) {
+ it->Run();
+ }
}
void PrefNotifierImpl::SetPrefService(PrefService* pref_service) {

Powered by Google App Engine
This is Rietveld 408576698