OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/json_pref_store.h" | 5 #include "chrome/common/json_pref_store.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 if (!old_value || !value->Equals(old_value)) | 62 if (!old_value || !value->Equals(old_value)) |
63 prefs_->Set(key, new_value.release()); | 63 prefs_->Set(key, new_value.release()); |
64 } | 64 } |
65 | 65 |
66 void JsonPrefStore::RemoveValue(const std::string& key) { | 66 void JsonPrefStore::RemoveValue(const std::string& key) { |
67 if (prefs_->Remove(key, NULL)) { | 67 if (prefs_->Remove(key, NULL)) { |
68 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); | 68 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
| 72 bool JsonPrefStore::ReadOnly() const { |
| 73 return read_only_; |
| 74 } |
| 75 |
72 PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { | 76 PersistentPrefStore::PrefReadError JsonPrefStore::ReadPrefs() { |
73 if (path_.empty()) { | 77 if (path_.empty()) { |
74 read_only_ = true; | 78 read_only_ = true; |
75 return PREF_READ_ERROR_FILE_NOT_SPECIFIED; | 79 return PREF_READ_ERROR_FILE_NOT_SPECIFIED; |
76 } | 80 } |
77 JSONFileValueSerializer serializer(path_); | 81 JSONFileValueSerializer serializer(path_); |
78 | 82 |
79 int error_code = 0; | 83 int error_code = 0; |
80 std::string error_msg; | 84 std::string error_msg; |
81 scoped_ptr<Value> value(serializer.Deserialize(&error_code, &error_msg)); | 85 scoped_ptr<Value> value(serializer.Deserialize(&error_code, &error_msg)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 167 } |
164 | 168 |
165 bool JsonPrefStore::SerializeData(std::string* output) { | 169 bool JsonPrefStore::SerializeData(std::string* output) { |
166 // TODO(tc): Do we want to prune webkit preferences that match the default | 170 // TODO(tc): Do we want to prune webkit preferences that match the default |
167 // value? | 171 // value? |
168 JSONStringValueSerializer serializer(output); | 172 JSONStringValueSerializer serializer(output); |
169 serializer.set_pretty_print(true); | 173 serializer.set_pretty_print(true); |
170 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); | 174 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); |
171 return serializer.Serialize(*(copy.get())); | 175 return serializer.Serialize(*(copy.get())); |
172 } | 176 } |
OLD | NEW |