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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (path_.empty()) { | 77 if (path_.empty()) { |
78 read_only_ = true; | 78 read_only_ = true; |
79 return PREF_READ_ERROR_FILE_NOT_SPECIFIED; | 79 return PREF_READ_ERROR_FILE_NOT_SPECIFIED; |
80 } | 80 } |
81 JSONFileValueSerializer serializer(path_); | 81 JSONFileValueSerializer serializer(path_); |
82 | 82 |
83 int error_code = 0; | 83 int error_code = 0; |
84 std::string error_msg; | 84 std::string error_msg; |
85 scoped_ptr<Value> value(serializer.Deserialize(&error_code, &error_msg)); | 85 scoped_ptr<Value> value(serializer.Deserialize(&error_code, &error_msg)); |
86 if (!value.get()) { | 86 if (!value.get()) { |
87 #if defined(GOOGLE_CHROME_BUILD) | |
88 // This log could be used for more detailed client-side error diagnosis, | |
89 // but since this triggers often with unit tests, we need to disable it | |
90 // in non-official builds. | |
91 PLOG(ERROR) << "Error reading Preferences: " << error_msg << " " << | |
92 path_.value(); | |
93 #endif | |
94 PrefReadError error; | 87 PrefReadError error; |
95 switch (error_code) { | 88 switch (error_code) { |
96 case JSONFileValueSerializer::JSON_ACCESS_DENIED: | 89 case JSONFileValueSerializer::JSON_ACCESS_DENIED: |
97 // If the file exists but is simply unreadable, put the file into a | 90 // If the file exists but is simply unreadable, put the file into a |
98 // state where we don't try to save changes. Otherwise, we could | 91 // state where we don't try to save changes. Otherwise, we could |
99 // clobber the existing prefs. | 92 // clobber the existing prefs. |
100 error = PREF_READ_ERROR_ACCESS_DENIED; | 93 error = PREF_READ_ERROR_ACCESS_DENIED; |
101 read_only_ = true; | 94 read_only_ = true; |
102 break; | 95 break; |
103 case JSONFileValueSerializer::JSON_CANNOT_READ_FILE: | 96 case JSONFileValueSerializer::JSON_CANNOT_READ_FILE: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 160 } |
168 | 161 |
169 bool JsonPrefStore::SerializeData(std::string* output) { | 162 bool JsonPrefStore::SerializeData(std::string* output) { |
170 // TODO(tc): Do we want to prune webkit preferences that match the default | 163 // TODO(tc): Do we want to prune webkit preferences that match the default |
171 // value? | 164 // value? |
172 JSONStringValueSerializer serializer(output); | 165 JSONStringValueSerializer serializer(output); |
173 serializer.set_pretty_print(true); | 166 serializer.set_pretty_print(true); |
174 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); | 167 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); |
175 return serializer.Serialize(*(copy.get())); | 168 return serializer.Serialize(*(copy.get())); |
176 } | 169 } |
OLD | NEW |