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

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

Issue 217063005: Separate SyncData methods into three groups, local, remote, and common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@syncapi
Patch Set: Rebase. Created 6 years, 8 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
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/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 284 }
285 285
286 syncer::SyncError AttemptDelete( 286 syncer::SyncError AttemptDelete(
287 const syncer::SyncChange& change, 287 const syncer::SyncChange& change,
288 syncer::ModelType type, 288 syncer::ModelType type,
289 const std::string& type_str, 289 const std::string& type_str,
290 syncer::WriteNode* node, 290 syncer::WriteNode* node,
291 DataTypeErrorHandler* error_handler) { 291 DataTypeErrorHandler* error_handler) {
292 DCHECK_EQ(change.change_type(), syncer::SyncChange::ACTION_DELETE); 292 DCHECK_EQ(change.change_type(), syncer::SyncChange::ACTION_DELETE);
293 if (change.sync_data().IsLocal()) { 293 if (change.sync_data().IsLocal()) {
294 const std::string& tag = change.sync_data().GetTag(); 294 const std::string& tag = syncer::SyncDataLocal(change.sync_data()).GetTag();
295 if (tag.empty()) { 295 if (tag.empty()) {
296 syncer::SyncError error( 296 syncer::SyncError error(
297 FROM_HERE, 297 FROM_HERE,
298 syncer::SyncError::DATATYPE_ERROR, 298 syncer::SyncError::DATATYPE_ERROR,
299 "Failed to delete " + type_str + " node. Local data, empty tag. " + 299 "Failed to delete " + type_str + " node. Local data, empty tag. " +
300 change.location().ToString(), 300 change.location().ToString(),
301 type); 301 type);
302 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), 302 error_handler->OnSingleDatatypeUnrecoverableError(error.location(),
303 error.message()); 303 error.message());
304 NOTREACHED(); 304 NOTREACHED();
305 return error; 305 return error;
306 } 306 }
307 307
308 syncer::BaseNode::InitByLookupResult result = 308 syncer::BaseNode::InitByLookupResult result =
309 node->InitByClientTagLookup(change.sync_data().GetDataType(), tag); 309 node->InitByClientTagLookup(change.sync_data().GetDataType(), tag);
310 if (result != syncer::BaseNode::INIT_OK) { 310 if (result != syncer::BaseNode::INIT_OK) {
311 return LogLookupFailure( 311 return LogLookupFailure(
312 result, FROM_HERE, 312 result, FROM_HERE,
313 "Failed to delete " + type_str + " node. Local data. " + 313 "Failed to delete " + type_str + " node. Local data. " +
314 change.location().ToString(), 314 change.location().ToString(),
315 type, error_handler); 315 type, error_handler);
316 } 316 }
317 } else { 317 } else {
318 syncer::BaseNode::InitByLookupResult result = 318 syncer::BaseNode::InitByLookupResult result = node->InitByIdLookup(
319 node->InitByIdLookup(change.sync_data().GetRemoteId()); 319 syncer::SyncDataRemote(change.sync_data()).GetId());
320 if (result != syncer::BaseNode::INIT_OK) { 320 if (result != syncer::BaseNode::INIT_OK) {
321 return LogLookupFailure( 321 return LogLookupFailure(
322 result, FROM_HERE, 322 result, FROM_HERE,
323 "Failed to delete " + type_str + " node. Non-local data. " + 323 "Failed to delete " + type_str + " node. Non-local data. " +
324 change.location().ToString(), 324 change.location().ToString(),
325 type, error_handler); 325 type, error_handler);
326 } 326 }
327 } 327 }
328 if (IsActOnceDataType(type)) 328 if (IsActOnceDataType(type))
329 node->Drop(); 329 node->Drop();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 syncer::SyncError::DATATYPE_ERROR, 408 syncer::SyncError::DATATYPE_ERROR,
409 "Failed to look up root node for type " + type_str, 409 "Failed to look up root node for type " + type_str,
410 type); 410 type);
411 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 411 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
412 error.message()); 412 error.message());
413 NOTREACHED(); 413 NOTREACHED();
414 LOG(ERROR) << "Create: no root node."; 414 LOG(ERROR) << "Create: no root node.";
415 return error; 415 return error;
416 } 416 }
417 syncer::WriteNode::InitUniqueByCreationResult result = 417 syncer::WriteNode::InitUniqueByCreationResult result =
418 sync_node->InitUniqueByCreation(change.sync_data().GetDataType(), 418 sync_node->InitUniqueByCreation(
419 root_node, 419 change.sync_data().GetDataType(),
420 change.sync_data().GetTag()); 420 root_node,
421 syncer::SyncDataLocal(change.sync_data()).GetTag());
421 if (result != syncer::WriteNode::INIT_SUCCESS) { 422 if (result != syncer::WriteNode::INIT_SUCCESS) {
422 std::string error_prefix = "Failed to create " + type_str + " node: " + 423 std::string error_prefix = "Failed to create " + type_str + " node: " +
423 change.location().ToString() + ", "; 424 change.location().ToString() + ", ";
424 switch (result) { 425 switch (result) {
425 case syncer::WriteNode::INIT_FAILED_EMPTY_TAG: { 426 case syncer::WriteNode::INIT_FAILED_EMPTY_TAG: {
426 syncer::SyncError error; 427 syncer::SyncError error;
427 error.Reset(FROM_HERE, error_prefix + "empty tag", type); 428 error.Reset(FROM_HERE, error_prefix + "empty tag", type);
428 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 429 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
429 error.message()); 430 error.message());
430 LOG(ERROR) << "Create: Empty tag."; 431 LOG(ERROR) << "Create: Empty tag.";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // the compiler attempts to merge it with other calls, losing useful information 479 // the compiler attempts to merge it with other calls, losing useful information
479 // in breakpad uploads. 480 // in breakpad uploads.
480 syncer::SyncError GenericChangeProcessor::HandleActionUpdate( 481 syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
481 const syncer::SyncChange& change, 482 const syncer::SyncChange& change,
482 const std::string& type_str, 483 const std::string& type_str,
483 const syncer::ModelType& type, 484 const syncer::ModelType& type,
484 const syncer::WriteTransaction& trans, 485 const syncer::WriteTransaction& trans,
485 syncer::WriteNode* sync_node) { 486 syncer::WriteNode* sync_node) {
486 // TODO(zea): consider having this logic for all possible changes? 487 // TODO(zea): consider having this logic for all possible changes?
487 syncer::BaseNode::InitByLookupResult result = 488 syncer::BaseNode::InitByLookupResult result =
488 sync_node->InitByClientTagLookup(change.sync_data().GetDataType(), 489 sync_node->InitByClientTagLookup(
489 change.sync_data().GetTag()); 490 change.sync_data().GetDataType(),
491 syncer::SyncDataLocal(change.sync_data()).GetTag());
490 if (result != syncer::BaseNode::INIT_OK) { 492 if (result != syncer::BaseNode::INIT_OK) {
491 std::string error_prefix = "Failed to load " + type_str + " node. " + 493 std::string error_prefix = "Failed to load " + type_str + " node. " +
492 change.location().ToString() + ", "; 494 change.location().ToString() + ", ";
493 if (result == syncer::BaseNode::INIT_FAILED_PRECONDITION) { 495 if (result == syncer::BaseNode::INIT_FAILED_PRECONDITION) {
494 syncer::SyncError error; 496 syncer::SyncError error;
495 error.Reset(FROM_HERE, error_prefix + "empty tag", type); 497 error.Reset(FROM_HERE, error_prefix + "empty tag", type);
496 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 498 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
497 error.message()); 499 error.message());
498 LOG(ERROR) << "Update: Empty tag."; 500 LOG(ERROR) << "Update: Empty tag.";
499 return error; 501 return error;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 void GenericChangeProcessor::StartImpl(Profile* profile) { 619 void GenericChangeProcessor::StartImpl(Profile* profile) {
618 DCHECK(CalledOnValidThread()); 620 DCHECK(CalledOnValidThread());
619 } 621 }
620 622
621 syncer::UserShare* GenericChangeProcessor::share_handle() const { 623 syncer::UserShare* GenericChangeProcessor::share_handle() const {
622 DCHECK(CalledOnValidThread()); 624 DCHECK(CalledOnValidThread());
623 return share_handle_; 625 return share_handle_;
624 } 626 }
625 627
626 } // namespace browser_sync 628 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/favicon_cache_unittest.cc ('k') | chrome/browser/sync/profile_sync_service_preference_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698