Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: base/prefs/json_pref_store.cc

Issue 925783002: Split ValueSerializer into separate Serializer and Deserializer classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cpplint warnings. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/json/json_value_serializer_unittest.cc ('k') | base/test/gtest_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 }
OLDNEW
« no previous file with comments | « base/json/json_value_serializer_unittest.cc ('k') | base/test/gtest_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698