| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 DCHECK(!file_path.empty()); | 135 DCHECK(!file_path.empty()); |
| 136 DCHECK(CalledOnValidThread()); | 136 DCHECK(CalledOnValidThread()); |
| 137 | 137 |
| 138 JSONFileValueSerializer serializer(file_path); | 138 JSONFileValueSerializer serializer(file_path); |
| 139 Value* root = NULL; | 139 scoped_ptr<Value> root(serializer.Deserialize(NULL)); |
| 140 if (serializer.Deserialize(&root, NULL)) { | 140 if (!root.get()) |
| 141 // Preferences should always have a dictionary root. | 141 return false; |
| 142 if (!root->IsType(Value::TYPE_DICTIONARY)) { | |
| 143 delete root; | |
| 144 return false; | |
| 145 } | |
| 146 | 142 |
| 147 persistent_.reset(static_cast<DictionaryValue*>(root)); | 143 // Preferences should always have a dictionary root. |
| 148 return true; | 144 if (!root->IsType(Value::TYPE_DICTIONARY)) |
| 149 } | 145 return false; |
| 150 | 146 |
| 151 return false; | 147 persistent_.reset(static_cast<DictionaryValue*>(root.release())); |
| 148 return true; |
| 152 } | 149 } |
| 153 | 150 |
| 154 void PrefService::ReloadPersistentPrefs() { | 151 void PrefService::ReloadPersistentPrefs() { |
| 155 DCHECK(CalledOnValidThread()); | 152 DCHECK(CalledOnValidThread()); |
| 156 | 153 |
| 157 JSONFileValueSerializer serializer(pref_filename_); | 154 JSONFileValueSerializer serializer(pref_filename_); |
| 158 Value* root; | 155 scoped_ptr<Value> root(serializer.Deserialize(NULL)); |
| 159 if (serializer.Deserialize(&root, NULL)) { | 156 if (!root.get()) |
| 160 // Preferences should always have a dictionary root. | 157 return; |
| 161 if (!root->IsType(Value::TYPE_DICTIONARY)) { | |
| 162 delete root; | |
| 163 return; | |
| 164 } | |
| 165 | 158 |
| 166 persistent_.reset(static_cast<DictionaryValue*>(root)); | 159 // Preferences should always have a dictionary root. |
| 167 for (PreferenceSet::iterator it = prefs_.begin(); | 160 if (!root->IsType(Value::TYPE_DICTIONARY)) |
| 168 it != prefs_.end(); ++it) { | 161 return; |
| 169 (*it)->root_pref_ = persistent_.get(); | 162 |
| 170 } | 163 persistent_.reset(static_cast<DictionaryValue*>(root.release())); |
| 164 for (PreferenceSet::iterator it = prefs_.begin(); |
| 165 it != prefs_.end(); ++it) { |
| 166 (*it)->root_pref_ = persistent_.get(); |
| 171 } | 167 } |
| 172 } | 168 } |
| 173 | 169 |
| 174 bool PrefService::SavePersistentPrefs(base::Thread* thread) const { | 170 bool PrefService::SavePersistentPrefs(base::Thread* thread) const { |
| 175 DCHECK(!pref_filename_.empty()); | 171 DCHECK(!pref_filename_.empty()); |
| 176 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
| 177 | 173 |
| 178 // TODO(tc): Do we want to prune webkit preferences that match the default | 174 // TODO(tc): Do we want to prune webkit preferences that match the default |
| 179 // value? | 175 // value? |
| 180 std::string data; | 176 std::string data; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 665 |
| 670 // Pref not found, just return the app default. | 666 // Pref not found, just return the app default. |
| 671 return default_value_.get(); | 667 return default_value_.get(); |
| 672 } | 668 } |
| 673 | 669 |
| 674 bool PrefService::Preference::IsDefaultValue() const { | 670 bool PrefService::Preference::IsDefaultValue() const { |
| 675 DCHECK(default_value_.get()); | 671 DCHECK(default_value_.get()); |
| 676 return default_value_->Equals(GetValue()); | 672 return default_value_->Equals(GetValue()); |
| 677 } | 673 } |
| 678 | 674 |
| OLD | NEW |