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

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

Issue 10383127: Explode Autofill sync error messages for debugging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar DRY Created 8 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/webdata/autofill_profile_syncable_service.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 "chrome/browser/sync/glue/generic_change_processor.h" 5 #include "chrome/browser/sync/glue/generic_change_processor.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 current_sync_data->push_back(SyncData::CreateRemoteData( 122 current_sync_data->push_back(SyncData::CreateRemoteData(
123 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics())); 123 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics()));
124 sync_child_id = sync_child_node.GetSuccessorId(); 124 sync_child_id = sync_child_node.GetSuccessorId();
125 } 125 }
126 return SyncError(); 126 return SyncError();
127 } 127 }
128 128
129 namespace { 129 namespace {
130 130
131 bool AttemptDelete(const SyncChange& change, sync_api::WriteNode* node) { 131 // TODO(isherman): Investigating http://crbug.com/121592
132 SyncError LogLookupFailure(sync_api::BaseNode::InitByLookupResult lookup_result,
133 const tracked_objects::Location& from_here,
134 const std::string& error_prefix,
135 syncable::ModelType type,
136 DataTypeErrorHandler* error_handler) {
137 SyncError error;
138 switch (lookup_result) {
139 case sync_api::BaseNode::INIT_FAILED_ENTRY_NOT_GOOD:
140 error.Reset(from_here,
141 error_prefix +
142 "could not find entry matching the lookup criteria.",
143 type);
144 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
145 error.message());
146 return error;
147
148 case sync_api::BaseNode::INIT_FAILED_ENTRY_IS_DEL:
149 error.Reset(from_here, error_prefix + "entry is already deleted.", type);
150 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
151 error.message());
152 return error;
153
154 case sync_api::BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY:
155 error.Reset(from_here, error_prefix + "unable to decrypt", type);
156 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
157 error.message());
158 return error;
159
160 case sync_api::BaseNode::INIT_FAILED_PRECONDITION:
161 error.Reset(from_here,
162 error_prefix + "a precondition was not met for calling init.",
163 type);
164 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
165 error.message());
166 return error;
167
168 default:
169 // Should have listed all the possible error cases above.
170 NOTREACHED();
171 error.Reset(from_here, error_prefix + "unknown error", type);
172 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
173 error.message());
174 return error;
175 }
176 }
177
178 SyncError AttemptDelete(const SyncChange& change,
179 syncable::ModelType type,
180 const std::string& type_str,
181 sync_api::WriteNode* node,
182 DataTypeErrorHandler* error_handler) {
132 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); 183 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE);
133 if (change.sync_data().IsLocal()) { 184 if (change.sync_data().IsLocal()) {
134 const std::string& tag = change.sync_data().GetTag(); 185 const std::string& tag = change.sync_data().GetTag();
135 if (tag.empty()) { 186 if (tag.empty()) {
136 return false; 187 SyncError error(
188 FROM_HERE,
189 "Failed to delete " + type_str + " node. Local data, empty tag.",
190 type);
191 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
192 error.message());
193 return error;
137 } 194 }
138 if (node->InitByClientTagLookup( 195
139 change.sync_data().GetDataType(), tag) != 196 sync_api::BaseNode::InitByLookupResult result =
140 sync_api::BaseNode::INIT_OK) { 197 node->InitByClientTagLookup(change.sync_data().GetDataType(), tag);
141 return false; 198 if (result != sync_api::BaseNode::INIT_OK) {
199 return LogLookupFailure(
200 result, FROM_HERE,
201 "Failed to delete " + type_str + " node. Local data, ",
202 type, error_handler);
142 } 203 }
143 } else { 204 } else {
144 if (node->InitByIdLookup(change.sync_data().GetRemoteId()) != 205 sync_api::BaseNode::InitByLookupResult result =
145 sync_api::BaseNode::INIT_OK) { 206 node->InitByIdLookup(change.sync_data().GetRemoteId());
146 return false; 207 if (result != sync_api::BaseNode::INIT_OK) {
208 return LogLookupFailure(
209 result, FROM_HERE,
210 "Failed to delete " + type_str + " node. Non-local data, ",
211 type, error_handler);
147 } 212 }
148 } 213 }
149 node->Remove(); 214 node->Remove();
150 return true; 215 return SyncError();
151 } 216 }
152 217
153 } // namespace 218 } // namespace
154 219
155 SyncError GenericChangeProcessor::ProcessSyncChanges( 220 SyncError GenericChangeProcessor::ProcessSyncChanges(
156 const tracked_objects::Location& from_here, 221 const tracked_objects::Location& from_here,
157 const SyncChangeList& list_of_changes) { 222 const SyncChangeList& list_of_changes) {
158 DCHECK(CalledOnValidThread()); 223 DCHECK(CalledOnValidThread());
159 sync_api::WriteTransaction trans(from_here, share_handle()); 224 sync_api::WriteTransaction trans(from_here, share_handle());
160 225
161 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); 226 for (SyncChangeList::const_iterator iter = list_of_changes.begin();
162 iter != list_of_changes.end(); 227 iter != list_of_changes.end();
163 ++iter) { 228 ++iter) {
164 const SyncChange& change = *iter; 229 const SyncChange& change = *iter;
165 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); 230 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED);
166 syncable::ModelType type = change.sync_data().GetDataType(); 231 syncable::ModelType type = change.sync_data().GetDataType();
167 std::string type_str = syncable::ModelTypeToString(type); 232 std::string type_str = syncable::ModelTypeToString(type);
168 sync_api::WriteNode sync_node(&trans); 233 sync_api::WriteNode sync_node(&trans);
169 if (change.change_type() == SyncChange::ACTION_DELETE) { 234 if (change.change_type() == SyncChange::ACTION_DELETE) {
170 if (!AttemptDelete(change, &sync_node)) { 235 SyncError error = AttemptDelete(change, type, type_str, &sync_node,
236 error_handler());
237 if (error.IsSet()) {
171 NOTREACHED(); 238 NOTREACHED();
172 SyncError error(FROM_HERE,
173 "Failed to delete " + type_str + " node.",
174 type);
175 error_handler()->OnSingleDatatypeUnrecoverableError(error.location(),
176 error.message());
177 return error; 239 return error;
178 } 240 }
179 } else if (change.change_type() == SyncChange::ACTION_ADD) { 241 } else if (change.change_type() == SyncChange::ACTION_ADD) {
180 // TODO(sync): Handle other types of creation (custom parents, folders, 242 // TODO(sync): Handle other types of creation (custom parents, folders,
181 // etc.). 243 // etc.).
182 sync_api::ReadNode root_node(&trans); 244 sync_api::ReadNode root_node(&trans);
183 if (root_node.InitByTagLookup( 245 if (root_node.InitByTagLookup(
184 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != 246 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) !=
185 sync_api::BaseNode::INIT_OK) { 247 sync_api::BaseNode::INIT_OK) {
186 NOTREACHED(); 248 NOTREACHED();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void GenericChangeProcessor::StopImpl() { 397 void GenericChangeProcessor::StopImpl() {
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
337 } 399 }
338 400
339 sync_api::UserShare* GenericChangeProcessor::share_handle() const { 401 sync_api::UserShare* GenericChangeProcessor::share_handle() const {
340 DCHECK(CalledOnValidThread()); 402 DCHECK(CalledOnValidThread());
341 return share_handle_; 403 return share_handle_;
342 } 404 }
343 405
344 } // namespace browser_sync 406 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/webdata/autofill_profile_syncable_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698