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

Side by Side Diff: chrome/browser/sync/glue/preference_change_processor.cc

Issue 2002012: sync: Add location info to unrecoverable error. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add error handler back to bookmark model associator Created 10 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/browser/sync/glue/preference_change_processor.h" 5 #include "chrome/browser/sync/glue/preference_change_processor.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Do not pollute sync data with values coming from policy. 55 // Do not pollute sync data with values coming from policy.
56 if (preference->IsManaged()) 56 if (preference->IsManaged())
57 return; 57 return;
58 58
59 sync_api::WriteTransaction trans(share_handle()); 59 sync_api::WriteTransaction trans(share_handle());
60 sync_api::WriteNode node(&trans); 60 sync_api::WriteNode node(&trans);
61 61
62 int64 sync_id = model_associator_->GetSyncIdFromChromeId(*name); 62 int64 sync_id = model_associator_->GetSyncIdFromChromeId(*name);
63 if (sync_api::kInvalidId == sync_id) { 63 if (sync_api::kInvalidId == sync_id) {
64 LOG(ERROR) << "Unexpected notification for: " << *name; 64 std::wstring err = L"Unexpected notification for: " + *name;
65 error_handler()->OnUnrecoverableError(); 65 error_handler()->OnUnrecoverableError(FROM_HERE, WideToUTF8(err));
66 return; 66 return;
67 } else { 67 } else {
68 if (!node.InitByIdLookup(sync_id)) { 68 if (!node.InitByIdLookup(sync_id)) {
69 LOG(ERROR) << "Preference node lookup failed."; 69 error_handler()->OnUnrecoverableError(FROM_HERE,
70 error_handler()->OnUnrecoverableError(); 70 "Preference node lookup failed.");
71 return; 71 return;
72 } 72 }
73 } 73 }
74 74
75 if (!WritePreference(&node, *name, preference->GetValue())) { 75 if (!WritePreference(&node, *name, preference->GetValue())) {
76 LOG(ERROR) << "Failed to update preference node."; 76 error_handler()->OnUnrecoverableError(FROM_HERE,
77 error_handler()->OnUnrecoverableError(); 77 "Failed to update preference node.");
78 return; 78 return;
79 } 79 }
80 } 80 }
81 81
82 void PreferenceChangeProcessor::ApplyChangesFromSyncModel( 82 void PreferenceChangeProcessor::ApplyChangesFromSyncModel(
83 const sync_api::BaseTransaction* trans, 83 const sync_api::BaseTransaction* trans,
84 const sync_api::SyncManager::ChangeRecord* changes, 84 const sync_api::SyncManager::ChangeRecord* changes,
85 int change_count) { 85 int change_count) {
86 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 86 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
87 if (!running()) 87 if (!running())
88 return; 88 return;
89 StopObserving(); 89 StopObserving();
90 90
91 for (int i = 0; i < change_count; ++i) { 91 for (int i = 0; i < change_count; ++i) {
92 sync_api::ReadNode node(trans); 92 sync_api::ReadNode node(trans);
93 // TODO(ncarter): Can't look up the name for deletions: lookup of 93 // TODO(ncarter): Can't look up the name for deletions: lookup of
94 // deleted items fails at the syncapi layer. However, the node should 94 // deleted items fails at the syncapi layer. However, the node should
95 // generally still exist in the syncable database; we just need to 95 // generally still exist in the syncable database; we just need to
96 // plumb the syncapi so that it succeeds. 96 // plumb the syncapi so that it succeeds.
97 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == 97 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE ==
98 changes[i].action) { 98 changes[i].action) {
99 // Until the above is fixed, we have no choice but to ignore deletions. 99 // Until the above is fixed, we have no choice but to ignore deletions.
100 LOG(ERROR) << "No way to handle pref deletion"; 100 LOG(ERROR) << "No way to handle pref deletion";
101 continue; 101 continue;
102 } 102 }
103 103
104 if (!node.InitByIdLookup(changes[i].id)) { 104 if (!node.InitByIdLookup(changes[i].id)) {
105 LOG(ERROR) << "Preference node lookup failed."; 105 error_handler()->OnUnrecoverableError(FROM_HERE,
106 error_handler()->OnUnrecoverableError(); 106 "Preference node lookup failed.");
107 return; 107 return;
108 } 108 }
109 DCHECK(syncable::PREFERENCES == node.GetModelType()); 109 DCHECK(syncable::PREFERENCES == node.GetModelType());
110 110
111 std::wstring name; 111 std::wstring name;
112 scoped_ptr<Value> value(ReadPreference(&node, &name)); 112 scoped_ptr<Value> value(ReadPreference(&node, &name));
113 // Skip values we can't deserialize. 113 // Skip values we can't deserialize.
114 if (!value.get()) 114 if (!value.get())
115 continue; 115 continue;
116 116
(...skipping 30 matching lines...) Expand all
147 StartObserving(); 147 StartObserving();
148 } 148 }
149 149
150 bool PreferenceChangeProcessor::WritePreference( 150 bool PreferenceChangeProcessor::WritePreference(
151 sync_api::WriteNode* node, 151 sync_api::WriteNode* node,
152 const std::wstring& name, 152 const std::wstring& name,
153 const Value* value) { 153 const Value* value) {
154 std::string serialized; 154 std::string serialized;
155 JSONStringValueSerializer json(&serialized); 155 JSONStringValueSerializer json(&serialized);
156 if (!json.Serialize(*value)) { 156 if (!json.Serialize(*value)) {
157 LOG(ERROR) << "Failed to serialize preference value."; 157 error_handler()->OnUnrecoverableError(FROM_HERE,
158 error_handler()->OnUnrecoverableError(); 158 "Failed to serialize preference value.");
159 return false; 159 return false;
160 } 160 }
161 161
162 sync_pb::PreferenceSpecifics preference; 162 sync_pb::PreferenceSpecifics preference;
163 preference.set_name(WideToUTF8(name)); 163 preference.set_name(WideToUTF8(name));
164 preference.set_value(serialized); 164 preference.set_value(serialized);
165 node->SetPreferenceSpecifics(preference); 165 node->SetPreferenceSpecifics(preference);
166 node->SetTitle(name); 166 node->SetTitle(name);
167 return true; 167 return true;
168 } 168 }
169 169
170 Value* PreferenceChangeProcessor::ReadPreference( 170 Value* PreferenceChangeProcessor::ReadPreference(
171 sync_api::ReadNode* node, 171 sync_api::ReadNode* node,
172 std::wstring* name) { 172 std::wstring* name) {
173 const sync_pb::PreferenceSpecifics& preference( 173 const sync_pb::PreferenceSpecifics& preference(
174 node->GetPreferenceSpecifics()); 174 node->GetPreferenceSpecifics());
175 base::JSONReader reader; 175 base::JSONReader reader;
176 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false)); 176 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false));
177 if (!value.get()) { 177 if (!value.get()) {
178 LOG(ERROR) << "Failed to deserialize preference value: " 178 std::string err = "Failed to deserialize preference value: " +
179 << reader.GetErrorMessage(); 179 reader.GetErrorMessage();
180 error_handler()->OnUnrecoverableError(); 180 error_handler()->OnUnrecoverableError(FROM_HERE, err);
181 return NULL; 181 return NULL;
182 } 182 }
183 *name = UTF8ToWide(preference.name()); 183 *name = UTF8ToWide(preference.name());
184 return value.release(); 184 return value.release();
185 } 185 }
186 186
187 void PreferenceChangeProcessor::StartImpl(Profile* profile) { 187 void PreferenceChangeProcessor::StartImpl(Profile* profile) {
188 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 188 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
189 pref_service_ = profile->GetPrefs(); 189 pref_service_ = profile->GetPrefs();
190 StartObserving(); 190 StartObserving();
(...skipping 18 matching lines...) Expand all
209 void PreferenceChangeProcessor::StopObserving() { 209 void PreferenceChangeProcessor::StopObserving() {
210 DCHECK(pref_service_); 210 DCHECK(pref_service_);
211 for (std::set<std::wstring>::const_iterator it = 211 for (std::set<std::wstring>::const_iterator it =
212 model_associator_->synced_preferences().begin(); 212 model_associator_->synced_preferences().begin();
213 it != model_associator_->synced_preferences().end(); ++it) { 213 it != model_associator_->synced_preferences().end(); ++it) {
214 pref_service_->RemovePrefObserver((*it).c_str(), this); 214 pref_service_->RemovePrefObserver((*it).c_str(), this);
215 } 215 }
216 } 216 }
217 217
218 } // namespace browser_sync 218 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/preference_change_processor.h ('k') | chrome/browser/sync/glue/preference_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698