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

Side by Side Diff: chrome/browser/prefs/overlay_user_pref_store.cc

Issue 10068036: RefCounted types should not have public destructors, chrome/browser/ part 5 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win fix Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/prefs/overlay_user_pref_store.h" 5 #include "chrome/browser/prefs/overlay_user_pref_store.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 9
10 OverlayUserPrefStore::OverlayUserPrefStore( 10 OverlayUserPrefStore::OverlayUserPrefStore(
11 PersistentPrefStore* underlay) 11 PersistentPrefStore* underlay)
12 : underlay_(underlay) { 12 : underlay_(underlay) {
13 underlay_->AddObserver(this); 13 underlay_->AddObserver(this);
14 } 14 }
15 15
16 OverlayUserPrefStore::~OverlayUserPrefStore() {
17 underlay_->RemoveObserver(this);
18 }
19
20 bool OverlayUserPrefStore::IsSetInOverlay(const std::string& key) const { 16 bool OverlayUserPrefStore::IsSetInOverlay(const std::string& key) const {
21 return overlay_.GetValue(key, NULL); 17 return overlay_.GetValue(key, NULL);
22 } 18 }
23 19
24 void OverlayUserPrefStore::AddObserver(PrefStore::Observer* observer) { 20 void OverlayUserPrefStore::AddObserver(PrefStore::Observer* observer) {
25 observers_.AddObserver(observer); 21 observers_.AddObserver(observer);
26 } 22 }
27 23
28 void OverlayUserPrefStore::RemoveObserver(PrefStore::Observer* observer) { 24 void OverlayUserPrefStore::RemoveObserver(PrefStore::Observer* observer) {
29 observers_.RemoveObserver(observer); 25 observers_.RemoveObserver(observer);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 125
130 void OverlayUserPrefStore::CommitPendingWrite() { 126 void OverlayUserPrefStore::CommitPendingWrite() {
131 underlay_->CommitPendingWrite(); 127 underlay_->CommitPendingWrite();
132 // We do not write our content intentionally. 128 // We do not write our content intentionally.
133 } 129 }
134 130
135 void OverlayUserPrefStore::ReportValueChanged(const std::string& key) { 131 void OverlayUserPrefStore::ReportValueChanged(const std::string& key) {
136 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); 132 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
137 } 133 }
138 134
135 void OverlayUserPrefStore::OnPrefValueChanged(const std::string& key) {
136 if (!overlay_.GetValue(GetOverlayKey(key), NULL))
137 ReportValueChanged(GetOverlayKey(key));
138 }
139
140 void OverlayUserPrefStore::OnInitializationCompleted(bool succeeded) {
141 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
142 OnInitializationCompleted(succeeded));
143 }
144
139 void OverlayUserPrefStore::RegisterOverlayPref(const std::string& key) { 145 void OverlayUserPrefStore::RegisterOverlayPref(const std::string& key) {
140 RegisterOverlayPref(key, key); 146 RegisterOverlayPref(key, key);
141 } 147 }
142 148
143 void OverlayUserPrefStore::RegisterOverlayPref( 149 void OverlayUserPrefStore::RegisterOverlayPref(
144 const std::string& overlay_key, 150 const std::string& overlay_key,
145 const std::string& underlay_key) { 151 const std::string& underlay_key) {
146 DCHECK(!overlay_key.empty()) << "Overlay key is empty"; 152 DCHECK(!overlay_key.empty()) << "Overlay key is empty";
147 DCHECK(overlay_to_underlay_names_map_.find(overlay_key) == 153 DCHECK(overlay_to_underlay_names_map_.find(overlay_key) ==
148 overlay_to_underlay_names_map_.end()) << 154 overlay_to_underlay_names_map_.end()) <<
149 "Overlay key already registered"; 155 "Overlay key already registered";
150 DCHECK(!underlay_key.empty()) << "Underlay key is empty"; 156 DCHECK(!underlay_key.empty()) << "Underlay key is empty";
151 DCHECK(underlay_to_overlay_names_map_.find(underlay_key) == 157 DCHECK(underlay_to_overlay_names_map_.find(underlay_key) ==
152 underlay_to_overlay_names_map_.end()) << 158 underlay_to_overlay_names_map_.end()) <<
153 "Underlay key already registered"; 159 "Underlay key already registered";
154 overlay_to_underlay_names_map_[overlay_key] = underlay_key; 160 overlay_to_underlay_names_map_[overlay_key] = underlay_key;
155 underlay_to_overlay_names_map_[underlay_key] = overlay_key; 161 underlay_to_overlay_names_map_[underlay_key] = overlay_key;
156 } 162 }
157 163
158 void OverlayUserPrefStore::OnPrefValueChanged(const std::string& key) { 164 OverlayUserPrefStore::~OverlayUserPrefStore() {
159 if (!overlay_.GetValue(GetOverlayKey(key), NULL)) 165 underlay_->RemoveObserver(this);
160 ReportValueChanged(GetOverlayKey(key));
161 }
162
163 void OverlayUserPrefStore::OnInitializationCompleted(bool succeeded) {
164 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
165 OnInitializationCompleted(succeeded));
166 } 166 }
167 167
168 const std::string& OverlayUserPrefStore::GetOverlayKey( 168 const std::string& OverlayUserPrefStore::GetOverlayKey(
169 const std::string& underlay_key) const { 169 const std::string& underlay_key) const {
170 NamesMap::const_iterator i = 170 NamesMap::const_iterator i =
171 underlay_to_overlay_names_map_.find(underlay_key); 171 underlay_to_overlay_names_map_.find(underlay_key);
172 return i != underlay_to_overlay_names_map_.end() ? i->second : underlay_key; 172 return i != underlay_to_overlay_names_map_.end() ? i->second : underlay_key;
173 } 173 }
174 174
175 const std::string& OverlayUserPrefStore::GetUnderlayKey( 175 const std::string& OverlayUserPrefStore::GetUnderlayKey(
176 const std::string& overlay_key) const { 176 const std::string& overlay_key) const {
177 NamesMap::const_iterator i = 177 NamesMap::const_iterator i =
178 overlay_to_underlay_names_map_.find(overlay_key); 178 overlay_to_underlay_names_map_.find(overlay_key);
179 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key; 179 return i != overlay_to_underlay_names_map_.end() ? i->second : overlay_key;
180 } 180 }
181 181
182 bool OverlayUserPrefStore::ShallBeStoredInOverlay( 182 bool OverlayUserPrefStore::ShallBeStoredInOverlay(
183 const std::string& key) const { 183 const std::string& key) const {
184 return overlay_to_underlay_names_map_.find(key) != 184 return overlay_to_underlay_names_map_.find(key) !=
185 overlay_to_underlay_names_map_.end(); 185 overlay_to_underlay_names_map_.end();
186 } 186 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/overlay_user_pref_store.h ('k') | chrome/browser/prefs/testing_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698