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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 PersistentPrefStore::PrefReadError HandleReadErrors( | 50 PersistentPrefStore::PrefReadError HandleReadErrors( |
51 const base::Value* value, | 51 const base::Value* value, |
52 const base::FilePath& path, | 52 const base::FilePath& path, |
53 int error_code, | 53 int error_code, |
54 const std::string& error_msg) { | 54 const std::string& error_msg) { |
55 if (!value) { | 55 if (!value) { |
56 DVLOG(1) << "Error while loading JSON file: " << error_msg | 56 DVLOG(1) << "Error while loading JSON file: " << error_msg |
57 << ", file: " << path.value(); | 57 << ", file: " << path.value(); |
58 switch (error_code) { | 58 switch (error_code) { |
59 case JSONFileValueSerializer::JSON_ACCESS_DENIED: | 59 case JSONFileValueDeserializer::JSON_ACCESS_DENIED: |
60 return PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED; | 60 return PersistentPrefStore::PREF_READ_ERROR_ACCESS_DENIED; |
61 break; | 61 break; |
62 case JSONFileValueSerializer::JSON_CANNOT_READ_FILE: | 62 case JSONFileValueDeserializer::JSON_CANNOT_READ_FILE: |
63 return PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER; | 63 return PersistentPrefStore::PREF_READ_ERROR_FILE_OTHER; |
64 break; | 64 break; |
65 case JSONFileValueSerializer::JSON_FILE_LOCKED: | 65 case JSONFileValueDeserializer::JSON_FILE_LOCKED: |
66 return PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED; | 66 return PersistentPrefStore::PREF_READ_ERROR_FILE_LOCKED; |
67 break; | 67 break; |
68 case JSONFileValueSerializer::JSON_NO_SUCH_FILE: | 68 case JSONFileValueDeserializer::JSON_NO_SUCH_FILE: |
69 return PersistentPrefStore::PREF_READ_ERROR_NO_FILE; | 69 return PersistentPrefStore::PREF_READ_ERROR_NO_FILE; |
70 break; | 70 break; |
71 default: | 71 default: |
72 // JSON errors indicate file corruption of some sort. | 72 // JSON errors indicate file corruption of some sort. |
73 // Since the file is corrupt, move it to the side and continue with | 73 // Since the file is corrupt, move it to the side and continue with |
74 // empty preferences. This will result in them losing their settings. | 74 // empty preferences. This will result in them losing their settings. |
75 // We keep the old file for possible support and debugging assistance | 75 // We keep the old file for possible support and debugging assistance |
76 // as well as to detect if they're seeing these errors repeatedly. | 76 // as well as to detect if they're seeing these errors repeatedly. |
77 // TODO(erikkay) Instead, use the last known good file. | 77 // TODO(erikkay) Instead, use the last known good file. |
78 base::FilePath bad = path.ReplaceExtension(kBadExtension); | 78 base::FilePath bad = path.ReplaceExtension(kBadExtension); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const base::FilePath& alternate_path) { | 112 const base::FilePath& alternate_path) { |
113 if (!base::PathExists(path) && !alternate_path.empty() && | 113 if (!base::PathExists(path) && !alternate_path.empty() && |
114 base::PathExists(alternate_path)) { | 114 base::PathExists(alternate_path)) { |
115 base::Move(alternate_path, path); | 115 base::Move(alternate_path, path); |
116 } | 116 } |
117 | 117 |
118 int error_code; | 118 int error_code; |
119 std::string error_msg; | 119 std::string error_msg; |
120 scoped_ptr<JsonPrefStore::ReadResult> read_result( | 120 scoped_ptr<JsonPrefStore::ReadResult> read_result( |
121 new JsonPrefStore::ReadResult); | 121 new JsonPrefStore::ReadResult); |
122 JSONFileValueSerializer serializer(path); | 122 JSONFileValueDeserializer deserializer(path); |
123 read_result->value.reset(serializer.Deserialize(&error_code, &error_msg)); | 123 read_result->value.reset(deserializer.Deserialize(&error_code, &error_msg)); |
124 read_result->error = | 124 read_result->error = |
125 HandleReadErrors(read_result->value.get(), path, error_code, error_msg); | 125 HandleReadErrors(read_result->value.get(), path, error_code, error_msg); |
126 read_result->no_dir = !base::PathExists(path.DirName()); | 126 read_result->no_dir = !base::PathExists(path.DirName()); |
127 | 127 |
128 if (read_result->error == PersistentPrefStore::PREF_READ_ERROR_NONE) | 128 if (read_result->error == PersistentPrefStore::PREF_READ_ERROR_NONE) |
129 RecordJsonDataSizeHistogram(path, serializer.get_last_read_size()); | 129 RecordJsonDataSizeHistogram(path, deserializer.get_last_read_size()); |
130 | 130 |
131 return read_result.Pass(); | 131 return read_result.Pass(); |
132 } | 132 } |
133 | 133 |
134 } // namespace | 134 } // namespace |
135 | 135 |
136 // static | 136 // static |
137 scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile( | 137 scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile( |
138 const base::FilePath& filename, | 138 const base::FilePath& filename, |
139 base::SequencedWorkerPool* worker_pool) { | 139 base::SequencedWorkerPool* worker_pool) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 425 |
426 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) | 426 if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) |
427 error_delegate_->OnError(read_error_); | 427 error_delegate_->OnError(read_error_); |
428 | 428 |
429 FOR_EACH_OBSERVER(PrefStore::Observer, | 429 FOR_EACH_OBSERVER(PrefStore::Observer, |
430 observers_, | 430 observers_, |
431 OnInitializationCompleted(true)); | 431 OnInitializationCompleted(true)); |
432 | 432 |
433 return; | 433 return; |
434 } | 434 } |
OLD | NEW |