OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 |
| 6 #include "chrome/browser/sync/engine/verify_updates_command.h" |
| 7 |
| 8 #include "chrome/browser/sync/engine/syncer.h" |
| 9 #include "chrome/browser/sync/engine/syncer_util.h" |
| 10 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
| 11 #include "chrome/browser/sync/engine/syncer_types.h" |
| 12 #include "chrome/browser/sync/engine/syncproto.h" |
| 13 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 14 #include "chrome/browser/sync/syncable/syncable.h" |
| 15 #include "chrome/browser/sync/util/character_set_converters.h" |
| 16 #include "chrome/browser/sync/util/sync_types.h" |
| 17 |
| 18 namespace browser_sync { |
| 19 |
| 20 using syncable::ScopedDirLookup; |
| 21 using syncable::SyncName; |
| 22 using syncable::WriteTransaction; |
| 23 |
| 24 using syncable::GET_BY_ID; |
| 25 using syncable::SYNCER; |
| 26 |
| 27 VerifyUpdatesCommand::VerifyUpdatesCommand() {} |
| 28 VerifyUpdatesCommand::~VerifyUpdatesCommand() {} |
| 29 |
| 30 void VerifyUpdatesCommand::ExecuteImpl(SyncerSession *session) { |
| 31 LOG(INFO) << "Beginning Update Verification"; |
| 32 ScopedDirLookup dir(session->dirman(), session->account_name()); |
| 33 if (!dir.good()) { |
| 34 LOG(ERROR) << "Scoped dir lookup failed!"; |
| 35 return; |
| 36 } |
| 37 WriteTransaction trans(dir, SYNCER, __FILE__, __LINE__); |
| 38 GetUpdatesResponse updates = session->update_response().get_updates(); |
| 39 int update_count = updates.entries().size(); |
| 40 |
| 41 LOG(INFO) << update_count << " entries to verify"; |
| 42 for (int i = 0; i < update_count; i++) { |
| 43 const SyncEntity entry = |
| 44 *reinterpret_cast<const SyncEntity *>(&(updates.entries(i))); |
| 45 // Needs to be done separately in order to make sure the update processing |
| 46 // still happens like normal. We should really just use one type of |
| 47 // ID in fact, there isn't actually a need for server_knows and not IDs. |
| 48 SyncerUtil::AttemptReuniteLostCommitResponses(&trans, entry, |
| 49 trans.directory()->cache_guid()); |
| 50 VerifyResult result = VerifyUpdate(&trans, entry); |
| 51 session->AddVerifyResult(result, entry); |
| 52 } |
| 53 } |
| 54 |
| 55 VerifyResult VerifyUpdatesCommand::VerifyUpdate( |
| 56 syncable::WriteTransaction* trans, const SyncEntity& entry) { |
| 57 syncable::Id id = entry.id(); |
| 58 |
| 59 const bool deleted = entry.has_deleted() && entry.deleted(); |
| 60 const bool is_directory = entry.IsFolder(); |
| 61 const bool is_bookmark = entry.has_bookmarkdata(); |
| 62 |
| 63 if (!id.ServerKnows()) { |
| 64 LOG(ERROR) << "Illegal negative id in received updates"; |
| 65 return VERIFY_FAIL; |
| 66 } |
| 67 if (!entry.parent_id().ServerKnows()) { |
| 68 LOG(ERROR) << "Illegal parent id in received updates"; |
| 69 return VERIFY_FAIL; |
| 70 } |
| 71 { |
| 72 SyncName name = SyncerProtoUtil::NameFromSyncEntity(entry); |
| 73 if ((name.value().empty() || name.non_unique_value().empty()) && |
| 74 !deleted) { |
| 75 LOG(ERROR) << "Zero length name in non-deleted update"; |
| 76 return VERIFY_FAIL; |
| 77 } |
| 78 } |
| 79 |
| 80 syncable::MutableEntry same_id(trans, GET_BY_ID, id); |
| 81 VerifyResult result = VERIFY_UNDECIDED; |
| 82 result = SyncerUtil::VerifyNewEntry(entry, &same_id, deleted); |
| 83 |
| 84 if (VERIFY_UNDECIDED == result) { |
| 85 if (deleted) |
| 86 result = VERIFY_SUCCESS; |
| 87 } |
| 88 |
| 89 // If we have an existing entry, we check here for updates that break |
| 90 // consistency rules. |
| 91 if (VERIFY_UNDECIDED == result) { |
| 92 result = SyncerUtil::VerifyUpdateConsistency(trans, entry, &same_id, |
| 93 deleted, is_directory, is_bookmark); |
| 94 } |
| 95 |
| 96 if (VERIFY_UNDECIDED == result) |
| 97 return VERIFY_SUCCESS; // No news is good news. |
| 98 else |
| 99 return result; // This might be VERIFY_SUCCESS as well |
| 100 } |
| 101 |
| 102 } // namespace browser_sync |
OLD | NEW |