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

Unified Diff: components/prefs/pref_notifier_impl.cc

Issue 2352703003: Remove stl_util's STLDeleteContainerPairSecondPointers from prefs. (Closed)
Patch Set: Created 4 years, 3 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 | « components/prefs/pref_notifier_impl.h ('k') | components/prefs/pref_notifier_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/prefs/pref_notifier_impl.cc
diff --git a/components/prefs/pref_notifier_impl.cc b/components/prefs/pref_notifier_impl.cc
index ffb50b400636ccb8d594e7a2d0e9a2ee68db4a72..48dd57c22d20eae537736bc4aee73bb2951b797e 100644
--- a/components/prefs/pref_notifier_impl.cc
+++ b/components/prefs/pref_notifier_impl.cc
@@ -5,12 +5,10 @@
#include "components/prefs/pref_notifier_impl.h"
#include "base/logging.h"
-#include "base/stl_util.h"
+#include "base/memory/ptr_util.h"
#include "components/prefs/pref_service.h"
-PrefNotifierImpl::PrefNotifierImpl()
- : pref_service_(NULL) {
-}
+PrefNotifierImpl::PrefNotifierImpl() : pref_service_(nullptr) {}
PrefNotifierImpl::PrefNotifierImpl(PrefService* service)
: pref_service_(service) {
@@ -20,11 +18,10 @@ PrefNotifierImpl::~PrefNotifierImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
// 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);
+ for (const auto& observer_list : pref_observers_) {
+ PrefObserverList::Iterator obs_iterator(observer_list.second.get());
if (obs_iterator.GetNext()) {
- LOG(WARNING) << "pref observer found at shutdown " << it->first;
+ LOG(WARNING) << "Pref observer found at shutdown.";
}
}
@@ -32,8 +29,6 @@ PrefNotifierImpl::~PrefNotifierImpl() {
if (!init_observers_.empty())
LOG(WARNING) << "Init observer found at shutdown.";
- base::STLDeleteContainerPairSecondPointers(pref_observers_.begin(),
- pref_observers_.end());
pref_observers_.clear();
init_observers_.clear();
}
@@ -41,14 +36,13 @@ PrefNotifierImpl::~PrefNotifierImpl() {
void PrefNotifierImpl::AddPrefObserver(const std::string& path,
PrefObserver* obs) {
// Get the pref observer list associated with the path.
- PrefObserverList* observer_list = NULL;
- const PrefObserverMap::iterator observer_iterator =
- pref_observers_.find(path);
+ PrefObserverList* observer_list = nullptr;
+ auto observer_iterator = pref_observers_.find(path);
if (observer_iterator == pref_observers_.end()) {
observer_list = new PrefObserverList;
- pref_observers_[path] = observer_list;
+ pref_observers_[path] = base::WrapUnique(observer_list);
} else {
- observer_list = observer_iterator->second;
+ observer_list = observer_iterator->second.get();
}
// Add the pref observer. ObserverList will DCHECK if it already is
@@ -60,13 +54,12 @@ void PrefNotifierImpl::RemovePrefObserver(const std::string& path,
PrefObserver* obs) {
DCHECK(thread_checker_.CalledOnValidThread());
- const PrefObserverMap::iterator observer_iterator =
- pref_observers_.find(path);
+ auto observer_iterator = pref_observers_.find(path);
if (observer_iterator == pref_observers_.end()) {
return;
}
- PrefObserverList* observer_list = observer_iterator->second;
+ PrefObserverList* observer_list = observer_iterator->second.get();
observer_list->RemoveObserver(obs);
}
@@ -87,11 +80,8 @@ void PrefNotifierImpl::OnInitializationCompleted(bool succeeded) {
PrefInitObserverList observers(init_observers_);
init_observers_.clear();
- for (PrefInitObserverList::iterator it = observers.begin();
- it != observers.end();
- ++it) {
- it->Run(succeeded);
- }
+ for (auto& observer : observers)
+ observer.Run(succeeded);
}
void PrefNotifierImpl::FireObservers(const std::string& path) {
@@ -101,8 +91,7 @@ void PrefNotifierImpl::FireObservers(const std::string& path) {
if (!pref_service_->FindPreference(path))
return;
- const PrefObserverMap::iterator observer_iterator =
- pref_observers_.find(path);
+ auto observer_iterator = pref_observers_.find(path);
if (observer_iterator == pref_observers_.end())
return;
@@ -112,6 +101,6 @@ void PrefNotifierImpl::FireObservers(const std::string& path) {
}
void PrefNotifierImpl::SetPrefService(PrefService* pref_service) {
- DCHECK(pref_service_ == NULL);
+ DCHECK(pref_service_ == nullptr);
pref_service_ = pref_service;
}
« no previous file with comments | « components/prefs/pref_notifier_impl.h ('k') | components/prefs/pref_notifier_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698