OLD | NEW |
---|---|
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 "chrome/browser/prefs/pref_service.h" | 5 #include "chrome/browser/prefs/pref_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 } | 138 } |
139 | 139 |
140 PrefService::PrefService(PrefStore* managed_platform_prefs, | 140 PrefService::PrefService(PrefStore* managed_platform_prefs, |
141 PrefStore* managed_cloud_prefs, | 141 PrefStore* managed_cloud_prefs, |
142 PrefStore* extension_prefs, | 142 PrefStore* extension_prefs, |
143 PrefStore* command_line_prefs, | 143 PrefStore* command_line_prefs, |
144 PersistentPrefStore* user_prefs, | 144 PersistentPrefStore* user_prefs, |
145 PrefStore* recommended_platform_prefs, | 145 PrefStore* recommended_platform_prefs, |
146 PrefStore* recommended_cloud_prefs, | 146 PrefStore* recommended_cloud_prefs, |
147 DefaultPrefStore* default_store, | 147 DefaultPrefStore* default_store, |
148 PrefServiceDelegate* delegate) | 148 PrefServiceDelegate* delegate) |
Mattias Nissler (ping if slow)
2011/04/26 09:04:26
Why do we still pass this PrefServiceDelegate to t
altimofeev
2011/04/27 10:32:08
Done.
| |
149 : user_pref_store_(user_prefs), | 149 : user_pref_store_(user_prefs), |
150 default_store_(default_store), | 150 default_store_(default_store), |
151 delegate_(delegate) { | 151 delegate_(delegate) { |
152 pref_notifier_.reset(new PrefNotifierImpl(this)); | 152 pref_notifier_.reset(new PrefNotifierImpl(this)); |
153 pref_value_store_.reset( | 153 pref_value_store_.reset( |
154 new PrefValueStore(managed_platform_prefs, | 154 new PrefValueStore(managed_platform_prefs, |
155 managed_cloud_prefs, | 155 managed_cloud_prefs, |
156 extension_prefs, | 156 extension_prefs, |
157 command_line_prefs, | 157 command_line_prefs, |
158 user_pref_store_, | 158 user_pref_store_, |
(...skipping 28 matching lines...) Expand all Loading... | |
187 DCHECK(CalledOnValidThread()); | 187 DCHECK(CalledOnValidThread()); |
188 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); | 188 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); |
189 prefs_.clear(); | 189 prefs_.clear(); |
190 | 190 |
191 // Reset pointers so accesses after destruction reliably crash. | 191 // Reset pointers so accesses after destruction reliably crash. |
192 pref_value_store_.reset(); | 192 pref_value_store_.reset(); |
193 user_pref_store_ = NULL; | 193 user_pref_store_ = NULL; |
194 default_store_ = NULL; | 194 default_store_ = NULL; |
195 } | 195 } |
196 | 196 |
197 void PrefService::OnPrefsRead(PersistentPrefStore::PrefReadError error, | 197 void PrefService::OnInitializationCompleted() { |
Mattias Nissler (ping if slow)
2011/04/26 09:04:26
If we use the PREF_INITIALIZATION_COMPLETED notifi
altimofeev
2011/04/27 10:32:08
I have leaved "PrefStore::Observer" here, because
Mattias Nissler (ping if slow)
2011/04/27 12:16:30
Yes, PrefNotifier already has OnInitializationComp
| |
198 bool no_dir) { | 198 // This is the only message PrefService is waiting for, so remove us from the |
199 if (no_dir) { | 199 // observers list. |
200 user_pref_store_->RemoveObserver(this); | |
201 | |
202 PersistentPrefStore::PrefReadError error; | |
203 bool is_fatal; | |
204 user_pref_store_->GetErrors(&error, &is_fatal); | |
Bernhard Bauer
2011/04/25 15:54:10
Could you pass these values directly to OnInitiali
altimofeev
2011/04/27 10:32:08
The problem is that "OnInitializationCompleted" is
Bernhard Bauer
2011/04/27 10:52:16
I think passing (PREF_READ_ERROR_NONE, false) at t
Mattias Nissler (ping if slow)
2011/04/27 12:16:30
I think passing the parameters makes sense. At the
| |
205 if (is_fatal) { | |
200 // Bad news. When profile is created, the process that creates the directory | 206 // Bad news. When profile is created, the process that creates the directory |
201 // is explicitly started. So if directory is missing it probably means that | 207 // is explicitly started. So if directory is missing it probably means that |
202 // Chromium hasn't sufficient privileges. | 208 // Chromium hasn't sufficient privileges. |
203 CHECK(delegate_); | 209 CHECK(delegate_); |
204 delegate_->OnPrefsLoaded(this, false); | 210 delegate_->OnPrefsLoaded(this, false); |
205 return; | 211 return; |
206 } | 212 } |
207 | 213 |
208 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { | 214 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { |
209 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for | 215 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for |
(...skipping 11 matching lines...) Expand all Loading... | |
221 NewRunnableFunction(&NotifyReadError, this, message_id)); | 227 NewRunnableFunction(&NotifyReadError, this, message_id)); |
222 } | 228 } |
223 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20); | 229 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20); |
224 } | 230 } |
225 | 231 |
226 if (delegate_) | 232 if (delegate_) |
227 delegate_->OnPrefsLoaded(this, true); | 233 delegate_->OnPrefsLoaded(this, true); |
228 } | 234 } |
229 | 235 |
230 void PrefService::InitFromStorage() { | 236 void PrefService::InitFromStorage() { |
237 user_pref_store_->AddObserver(this); | |
231 if (!delegate_) { | 238 if (!delegate_) { |
232 const PersistentPrefStore::PrefReadError error = | 239 user_pref_store_->ReadPrefs(); |
233 user_pref_store_->ReadPrefs(); | |
234 OnPrefsRead(error, false); | |
235 } else { | 240 } else { |
236 // todo(altimofeev): move this method to PersistentPrefStore interface. | 241 user_pref_store_.get()->ReadPrefsAsync(); |
237 (static_cast<JsonPrefStore*>(user_pref_store_.get()))->ReadPrefs(this); | |
238 } | 242 } |
239 } | 243 } |
240 | 244 |
241 bool PrefService::ReloadPersistentPrefs() { | 245 bool PrefService::ReloadPersistentPrefs() { |
242 return user_pref_store_->ReadPrefs() == | 246 return user_pref_store_->ReadPrefs() == |
243 PersistentPrefStore::PREF_READ_ERROR_NONE; | 247 PersistentPrefStore::PREF_READ_ERROR_NONE; |
244 } | 248 } |
245 | 249 |
246 bool PrefService::SavePersistentPrefs() { | 250 bool PrefService::SavePersistentPrefs() { |
247 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 703 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
700 } | 704 } |
701 | 705 |
702 bool PrefService::Preference::IsUserModifiable() const { | 706 bool PrefService::Preference::IsUserModifiable() const { |
703 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 707 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
704 } | 708 } |
705 | 709 |
706 bool PrefService::Preference::IsExtensionModifiable() const { | 710 bool PrefService::Preference::IsExtensionModifiable() const { |
707 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 711 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
708 } | 712 } |
OLD | NEW |