OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/prefs/json_pref_store.h" | 5 #include "base/prefs/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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 static base::Value* DoReading(const base::FilePath& path, | 64 static base::Value* DoReading(const base::FilePath& path, |
65 PersistentPrefStore::PrefReadError* error, | 65 PersistentPrefStore::PrefReadError* error, |
66 bool* no_dir) { | 66 bool* no_dir) { |
67 int error_code; | 67 int error_code; |
68 std::string error_msg; | 68 std::string error_msg; |
69 JSONFileValueSerializer serializer(path); | 69 JSONFileValueSerializer serializer(path); |
70 base::Value* value = serializer.Deserialize(&error_code, &error_msg); | 70 base::Value* value = serializer.Deserialize(&error_code, &error_msg); |
71 HandleErrors(value, path, error_code, error_msg, error); | 71 HandleErrors(value, path, error_code, error_msg, error); |
72 *no_dir = !file_util::PathExists(path.DirName()); | 72 *no_dir = !base::PathExists(path.DirName()); |
73 return value; | 73 return value; |
74 } | 74 } |
75 | 75 |
76 static void HandleErrors(const base::Value* value, | 76 static void HandleErrors(const base::Value* value, |
77 const base::FilePath& path, | 77 const base::FilePath& path, |
78 int error_code, | 78 int error_code, |
79 const std::string& error_msg, | 79 const std::string& error_msg, |
80 PersistentPrefStore::PrefReadError* error); | 80 PersistentPrefStore::PrefReadError* error); |
81 | 81 |
82 private: | 82 private: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Since the file is corrupt, move it to the side and continue with | 121 // Since the file is corrupt, move it to the side and continue with |
122 // empty preferences. This will result in them losing their settings. | 122 // empty preferences. This will result in them losing their settings. |
123 // We keep the old file for possible support and debugging assistance | 123 // We keep the old file for possible support and debugging assistance |
124 // as well as to detect if they're seeing these errors repeatedly. | 124 // as well as to detect if they're seeing these errors repeatedly. |
125 // TODO(erikkay) Instead, use the last known good file. | 125 // TODO(erikkay) Instead, use the last known good file. |
126 base::FilePath bad = path.ReplaceExtension(kBadExtension); | 126 base::FilePath bad = path.ReplaceExtension(kBadExtension); |
127 | 127 |
128 // If they've ever had a parse error before, put them in another bucket. | 128 // If they've ever had a parse error before, put them in another bucket. |
129 // TODO(erikkay) if we keep this error checking for very long, we may | 129 // TODO(erikkay) if we keep this error checking for very long, we may |
130 // want to differentiate between recent and long ago errors. | 130 // want to differentiate between recent and long ago errors. |
131 if (file_util::PathExists(bad)) | 131 if (base::PathExists(bad)) |
132 *error = PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT; | 132 *error = PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT; |
133 base::Move(path, bad); | 133 base::Move(path, bad); |
134 break; | 134 break; |
135 } | 135 } |
136 } else if (!value->IsType(base::Value::TYPE_DICTIONARY)) { | 136 } else if (!value->IsType(base::Value::TYPE_DICTIONARY)) { |
137 *error = PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE; | 137 *error = PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE; |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 } // namespace | 141 } // namespace |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 copy->Set(key, new base::ListValue); | 349 copy->Set(key, new base::ListValue); |
350 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) { | 350 } else if (value->IsType(base::Value::TYPE_DICTIONARY)) { |
351 const base::DictionaryValue* dict = NULL; | 351 const base::DictionaryValue* dict = NULL; |
352 if (value->GetAsDictionary(&dict) && dict->empty()) | 352 if (value->GetAsDictionary(&dict) && dict->empty()) |
353 copy->Set(key, new base::DictionaryValue); | 353 copy->Set(key, new base::DictionaryValue); |
354 } | 354 } |
355 } | 355 } |
356 | 356 |
357 return serializer.Serialize(*(copy.get())); | 357 return serializer.Serialize(*(copy.get())); |
358 } | 358 } |
OLD | NEW |