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

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: 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 = change.sync_data().local().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 =
319 node->InitByIdLookup(change.sync_data().GetRemoteId()); 319 node->InitByIdLookup(change.sync_data().remote().GetRemoteId());
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(change.sync_data().GetDataType(),
419 root_node, 419 root_node,
420 change.sync_data().GetTag()); 420 change.sync_data().local().GetTag());
421 if (result != syncer::WriteNode::INIT_SUCCESS) { 421 if (result != syncer::WriteNode::INIT_SUCCESS) {
422 std::string error_prefix = "Failed to create " + type_str + " node: " + 422 std::string error_prefix = "Failed to create " + type_str + " node: " +
423 change.location().ToString() + ", "; 423 change.location().ToString() + ", ";
424 switch (result) { 424 switch (result) {
425 case syncer::WriteNode::INIT_FAILED_EMPTY_TAG: { 425 case syncer::WriteNode::INIT_FAILED_EMPTY_TAG: {
426 syncer::SyncError error; 426 syncer::SyncError error;
427 error.Reset(FROM_HERE, error_prefix + "empty tag", type); 427 error.Reset(FROM_HERE, error_prefix + "empty tag", type);
428 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 428 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
429 error.message()); 429 error.message());
430 LOG(ERROR) << "Create: Empty tag."; 430 LOG(ERROR) << "Create: Empty tag.";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 // in breakpad uploads. 479 // in breakpad uploads.
480 syncer::SyncError GenericChangeProcessor::HandleActionUpdate( 480 syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
481 const syncer::SyncChange& change, 481 const syncer::SyncChange& change,
482 const std::string& type_str, 482 const std::string& type_str,
483 const syncer::ModelType& type, 483 const syncer::ModelType& type,
484 const syncer::WriteTransaction& trans, 484 const syncer::WriteTransaction& trans,
485 syncer::WriteNode* sync_node) { 485 syncer::WriteNode* sync_node) {
486 // TODO(zea): consider having this logic for all possible changes? 486 // TODO(zea): consider having this logic for all possible changes?
487 syncer::BaseNode::InitByLookupResult result = 487 syncer::BaseNode::InitByLookupResult result =
488 sync_node->InitByClientTagLookup(change.sync_data().GetDataType(), 488 sync_node->InitByClientTagLookup(change.sync_data().GetDataType(),
489 change.sync_data().GetTag()); 489 change.sync_data().local().GetTag());
490 if (result != syncer::BaseNode::INIT_OK) { 490 if (result != syncer::BaseNode::INIT_OK) {
491 std::string error_prefix = "Failed to load " + type_str + " node. " + 491 std::string error_prefix = "Failed to load " + type_str + " node. " +
492 change.location().ToString() + ", "; 492 change.location().ToString() + ", ";
493 if (result == syncer::BaseNode::INIT_FAILED_PRECONDITION) { 493 if (result == syncer::BaseNode::INIT_FAILED_PRECONDITION) {
494 syncer::SyncError error; 494 syncer::SyncError error;
495 error.Reset(FROM_HERE, error_prefix + "empty tag", type); 495 error.Reset(FROM_HERE, error_prefix + "empty tag", type);
496 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 496 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
497 error.message()); 497 error.message());
498 LOG(ERROR) << "Update: Empty tag."; 498 LOG(ERROR) << "Update: Empty tag.";
499 return error; 499 return error;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 void GenericChangeProcessor::StartImpl(Profile* profile) { 617 void GenericChangeProcessor::StartImpl(Profile* profile) {
618 DCHECK(CalledOnValidThread()); 618 DCHECK(CalledOnValidThread());
619 } 619 }
620 620
621 syncer::UserShare* GenericChangeProcessor::share_handle() const { 621 syncer::UserShare* GenericChangeProcessor::share_handle() const {
622 DCHECK(CalledOnValidThread()); 622 DCHECK(CalledOnValidThread());
623 return share_handle_; 623 return share_handle_;
624 } 624 }
625 625
626 } // namespace browser_sync 626 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698