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

Side by Side Diff: components/prefs/pref_notifier_impl_unittest.cc

Issue 2415793002: Remove usage of base::ObserverList<T>::Iter::GetNext() in //components/prefs. (Closed)
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "components/prefs/mock_pref_change_callback.h" 9 #include "components/prefs/mock_pref_change_callback.h"
10 #include "components/prefs/pref_notifier_impl.h" 10 #include "components/prefs/pref_notifier_impl.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 virtual ~MockPrefNotifier() {} 52 virtual ~MockPrefNotifier() {}
53 53
54 MOCK_METHOD1(FireObservers, void(const std::string& path)); 54 MOCK_METHOD1(FireObservers, void(const std::string& path));
55 55
56 size_t CountObserver(const std::string& path, PrefObserver* obs) { 56 size_t CountObserver(const std::string& path, PrefObserver* obs) {
57 PrefObserverMap::const_iterator observer_iterator = 57 PrefObserverMap::const_iterator observer_iterator =
58 pref_observers()->find(path); 58 pref_observers()->find(path);
59 if (observer_iterator == pref_observers()->end()) 59 if (observer_iterator == pref_observers()->end())
60 return false; 60 return false;
61 61
62 PrefObserverList* observer_list = observer_iterator->second.get();
63 PrefObserverList::Iterator it(observer_list);
64 PrefObserver* existing_obs;
65 size_t count = 0; 62 size_t count = 0;
66 while ((existing_obs = it.GetNext()) != NULL) { 63 for (auto& existing_obs : *observer_iterator->second) {
67 if (existing_obs == obs) 64 if (&existing_obs == obs)
68 count++; 65 count++;
69 } 66 }
70 67
71 return count; 68 return count;
72 } 69 }
73 70
74 // Make public for tests below. 71 // Make public for tests below.
75 using PrefNotifierImpl::OnPreferenceChanged; 72 using PrefNotifierImpl::OnPreferenceChanged;
76 using PrefNotifierImpl::OnInitializationCompleted; 73 using PrefNotifierImpl::OnInitializationCompleted;
77 }; 74 };
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref)); 210 EXPECT_CALL(obs2_, OnPreferenceChanged(&pref_service_, kChangedPref));
214 notifier.OnPreferenceChanged(kChangedPref); 211 notifier.OnPreferenceChanged(kChangedPref);
215 Mock::VerifyAndClearExpectations(&obs1_); 212 Mock::VerifyAndClearExpectations(&obs1_);
216 Mock::VerifyAndClearExpectations(&obs2_); 213 Mock::VerifyAndClearExpectations(&obs2_);
217 214
218 notifier.RemovePrefObserver(kChangedPref, &obs2_); 215 notifier.RemovePrefObserver(kChangedPref, &obs2_);
219 notifier.RemovePrefObserver(kUnchangedPref, &obs2_); 216 notifier.RemovePrefObserver(kUnchangedPref, &obs2_);
220 } 217 }
221 218
222 } // namespace 219 } // namespace
OLDNEW
« components/prefs/pref_notifier_impl.cc ('K') | « components/prefs/pref_notifier_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698