| 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/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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 | 149 |
| 150 JsonPrefStore::~JsonPrefStore() { | 150 JsonPrefStore::~JsonPrefStore() { |
| 151 CommitPendingWrite(); | 151 CommitPendingWrite(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 PrefStore::ReadResult JsonPrefStore::GetValue(const std::string& key, | 154 PrefStore::ReadResult JsonPrefStore::GetValue(const std::string& key, |
| 155 const Value** result) const { | 155 const Value** result) const { |
| 156 Value* tmp = NULL; | 156 Value* tmp = NULL; |
| 157 if (prefs_->Get(key, &tmp)) { | 157 if (prefs_->Get(key, &tmp)) { |
| 158 *result = tmp; | 158 if (result) |
| 159 *result = tmp; |
| 159 return READ_OK; | 160 return READ_OK; |
| 160 } | 161 } |
| 161 return READ_NO_VALUE; | 162 return READ_NO_VALUE; |
| 162 } | 163 } |
| 163 | 164 |
| 164 void JsonPrefStore::AddObserver(PrefStore::Observer* observer) { | 165 void JsonPrefStore::AddObserver(PrefStore::Observer* observer) { |
| 165 observers_.AddObserver(observer); | 166 observers_.AddObserver(observer); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) { | 169 void JsonPrefStore::RemoveObserver(PrefStore::Observer* observer) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 311 } |
| 311 | 312 |
| 312 bool JsonPrefStore::SerializeData(std::string* output) { | 313 bool JsonPrefStore::SerializeData(std::string* output) { |
| 313 // TODO(tc): Do we want to prune webkit preferences that match the default | 314 // TODO(tc): Do we want to prune webkit preferences that match the default |
| 314 // value? | 315 // value? |
| 315 JSONStringValueSerializer serializer(output); | 316 JSONStringValueSerializer serializer(output); |
| 316 serializer.set_pretty_print(true); | 317 serializer.set_pretty_print(true); |
| 317 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); | 318 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); |
| 318 return serializer.Serialize(*(copy.get())); | 319 return serializer.Serialize(*(copy.get())); |
| 319 } | 320 } |
| OLD | NEW |