OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/common/pref_service.h" | 5 #include "chrome/common/pref_service.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 125 } |
126 | 126 |
127 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); | 127 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); |
128 prefs_.clear(); | 128 prefs_.clear(); |
129 STLDeleteContainerPairSecondPointers(pref_observers_.begin(), | 129 STLDeleteContainerPairSecondPointers(pref_observers_.begin(), |
130 pref_observers_.end()); | 130 pref_observers_.end()); |
131 pref_observers_.clear(); | 131 pref_observers_.clear(); |
132 } | 132 } |
133 | 133 |
134 bool PrefService::LoadPersistentPrefs(const std::wstring& file_path) { | 134 bool PrefService::LoadPersistentPrefs(const std::wstring& file_path) { |
| 135 #if defined(OS_WIN) |
135 DCHECK(!file_path.empty()); | 136 DCHECK(!file_path.empty()); |
| 137 #else |
| 138 // On non-Windows platforms we haven't gotten round to this yet. |
| 139 // TODO(port): remove this exception |
| 140 if (file_path.empty()) { |
| 141 NOTIMPLEMENTED(); |
| 142 return false; |
| 143 } |
| 144 #endif |
136 DCHECK(CalledOnValidThread()); | 145 DCHECK(CalledOnValidThread()); |
137 | 146 |
138 JSONFileValueSerializer serializer(file_path); | 147 JSONFileValueSerializer serializer(file_path); |
139 scoped_ptr<Value> root(serializer.Deserialize(NULL)); | 148 scoped_ptr<Value> root(serializer.Deserialize(NULL)); |
140 if (!root.get()) | 149 if (!root.get()) |
141 return false; | 150 return false; |
142 | 151 |
143 // Preferences should always have a dictionary root. | 152 // Preferences should always have a dictionary root. |
144 if (!root->IsType(Value::TYPE_DICTIONARY)) | 153 if (!root->IsType(Value::TYPE_DICTIONARY)) |
145 return false; | 154 return false; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 337 |
329 std::wstring PrefService::GetString(const wchar_t* path) const { | 338 std::wstring PrefService::GetString(const wchar_t* path) const { |
330 DCHECK(CalledOnValidThread()); | 339 DCHECK(CalledOnValidThread()); |
331 | 340 |
332 std::wstring result; | 341 std::wstring result; |
333 if (transient_->GetString(path, &result)) | 342 if (transient_->GetString(path, &result)) |
334 return result; | 343 return result; |
335 | 344 |
336 const Preference* pref = FindPreference(path); | 345 const Preference* pref = FindPreference(path); |
337 if (!pref) { | 346 if (!pref) { |
| 347 #if defined(OS_WIN) |
338 DCHECK(false) << "Trying to read an unregistered pref: " << path; | 348 DCHECK(false) << "Trying to read an unregistered pref: " << path; |
| 349 #else |
| 350 // TODO(port): remove this exception |
| 351 #endif |
339 return result; | 352 return result; |
340 } | 353 } |
341 bool rv = pref->GetValue()->GetAsString(&result); | 354 bool rv = pref->GetValue()->GetAsString(&result); |
342 DCHECK(rv); | 355 DCHECK(rv); |
343 return result; | 356 return result; |
344 } | 357 } |
345 | 358 |
346 bool PrefService::HasPrefPath(const wchar_t* path) const { | 359 bool PrefService::HasPrefPath(const wchar_t* path) const { |
347 Value* value = NULL; | 360 Value* value = NULL; |
348 return (transient_->Get(path, &value) || persistent_->Get(path, &value)); | 361 return (transient_->Get(path, &value) || persistent_->Get(path, &value)); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 678 |
666 // Pref not found, just return the app default. | 679 // Pref not found, just return the app default. |
667 return default_value_.get(); | 680 return default_value_.get(); |
668 } | 681 } |
669 | 682 |
670 bool PrefService::Preference::IsDefaultValue() const { | 683 bool PrefService::Preference::IsDefaultValue() const { |
671 DCHECK(default_value_.get()); | 684 DCHECK(default_value_.get()); |
672 return default_value_->Equals(GetValue()); | 685 return default_value_->Equals(GetValue()); |
673 } | 686 } |
674 | 687 |
OLD | NEW |