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

Side by Side Diff: sync/engine/process_updates_command.cc

Issue 10735041: Remove syncproto.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most comments Created 8 years, 5 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) 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 "sync/engine/process_updates_command.h" 5 #include "sync/engine/process_updates_command.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "sync/engine/syncer.h" 11 #include "sync/engine/syncer.h"
12 #include "sync/engine/syncer_proto_util.h" 12 #include "sync/engine/syncer_proto_util.h"
13 #include "sync/engine/syncer_util.h" 13 #include "sync/engine/syncer_util.h"
14 #include "sync/engine/syncproto.h"
15 #include "sync/sessions/sync_session.h" 14 #include "sync/sessions/sync_session.h"
16 #include "sync/syncable/directory.h" 15 #include "sync/syncable/directory.h"
17 #include "sync/syncable/mutable_entry.h" 16 #include "sync/syncable/mutable_entry.h"
17 #include "sync/syncable/syncable_proto_util.h"
18 #include "sync/syncable/syncable_util.h" 18 #include "sync/syncable/syncable_util.h"
19 #include "sync/syncable/write_transaction.h" 19 #include "sync/syncable/write_transaction.h"
20 #include "sync/util/cryptographer.h" 20 #include "sync/util/cryptographer.h"
21 21
22 using std::vector; 22 using std::vector;
23 23
24 namespace syncer { 24 namespace syncer {
25 25
26 using sessions::SyncSession; 26 using sessions::SyncSession;
27 using sessions::StatusController; 27 using sessions::StatusController;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 } 66 }
67 67
68 StatusController* status = session->mutable_status_controller(); 68 StatusController* status = session->mutable_status_controller();
69 status->mutable_update_progress()->ClearVerifiedUpdates(); 69 status->mutable_update_progress()->ClearVerifiedUpdates();
70 return SYNCER_OK; 70 return SYNCER_OK;
71 } 71 }
72 72
73 namespace { 73 namespace {
74 // Returns true if the entry is still ok to process. 74 // Returns true if the entry is still ok to process.
75 bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry, 75 bool ReverifyEntry(syncable::WriteTransaction* trans,
76 const sync_pb::SyncEntity& entry,
76 syncable::MutableEntry* same_id) { 77 syncable::MutableEntry* same_id) {
77 78
78 const bool deleted = entry.has_deleted() && entry.deleted(); 79 const bool deleted = entry.has_deleted() && entry.deleted();
79 const bool is_directory = entry.IsFolder(); 80 const bool is_directory = IsFolder(entry);
80 const syncer::ModelType model_type = entry.GetModelType(); 81 const syncer::ModelType model_type = GetModelType(entry);
81 82
82 return VERIFY_SUCCESS == VerifyUpdateConsistency(trans, 83 return VERIFY_SUCCESS == VerifyUpdateConsistency(trans,
83 entry, 84 entry,
84 same_id, 85 same_id,
85 deleted, 86 deleted,
86 is_directory, 87 is_directory,
87 model_type); 88 model_type);
88 } 89 }
89 } // namespace 90 } // namespace
90 91
91 // Process a single update. Will avoid touching global state. 92 // Process a single update. Will avoid touching global state.
92 ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate( 93 ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate(
93 const sync_pb::SyncEntity& proto_update, 94 const sync_pb::SyncEntity& update,
94 const Cryptographer* cryptographer, 95 const Cryptographer* cryptographer,
95 syncable::WriteTransaction* const trans) { 96 syncable::WriteTransaction* const trans) {
96 97 const syncable::Id& server_id = SyncableIdFromProto(update.id_string());
97 const SyncEntity& update = *static_cast<const SyncEntity*>(&proto_update);
98 syncable::Id server_id = update.id();
99 const std::string name = SyncerProtoUtil::NameFromSyncEntity(update); 98 const std::string name = SyncerProtoUtil::NameFromSyncEntity(update);
100 99
101 // Look to see if there's a local item that should recieve this update, 100 // Look to see if there's a local item that should recieve this update,
102 // maybe due to a duplicate client tag or a lost commit response. 101 // maybe due to a duplicate client tag or a lost commit response.
103 syncable::Id local_id = FindLocalIdToUpdate(trans, update); 102 syncable::Id local_id = FindLocalIdToUpdate(trans, update);
104 103
105 // FindLocalEntryToUpdate has veto power. 104 // FindLocalEntryToUpdate has veto power.
106 if (local_id.IsNull()) { 105 if (local_id.IsNull()) {
107 return SUCCESS_PROCESSED; // The entry has become irrelevant. 106 return SUCCESS_PROCESSED; // The entry has become irrelevant.
108 } 107 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Force application of this update, no matter what. 142 // Force application of this update, no matter what.
144 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 143 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
145 } 144 }
146 145
147 // If this is a newly received undecryptable update, and the only thing that 146 // If this is a newly received undecryptable update, and the only thing that
148 // has changed are the specifics, store the original decryptable specifics, 147 // has changed are the specifics, store the original decryptable specifics,
149 // (on which any current or future local changes are based) before we 148 // (on which any current or future local changes are based) before we
150 // overwrite SERVER_SPECIFICS. 149 // overwrite SERVER_SPECIFICS.
151 // MTIME, CTIME, and NON_UNIQUE_NAME are not enforced. 150 // MTIME, CTIME, and NON_UNIQUE_NAME are not enforced.
152 if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) && 151 if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) &&
153 (update.parent_id() == target_entry.Get(syncable::SERVER_PARENT_ID)) && 152 (SyncableIdFromProto(update.parent_id_string()) ==
153 target_entry.Get(syncable::SERVER_PARENT_ID)) &&
154 (update.position_in_parent() == 154 (update.position_in_parent() ==
155 target_entry.Get(syncable::SERVER_POSITION_IN_PARENT)) && 155 target_entry.Get(syncable::SERVER_POSITION_IN_PARENT)) &&
156 update.has_specifics() && update.specifics().has_encrypted() && 156 update.has_specifics() && update.specifics().has_encrypted() &&
157 !cryptographer->CanDecrypt(update.specifics().encrypted())) { 157 !cryptographer->CanDecrypt(update.specifics().encrypted())) {
158 sync_pb::EntitySpecifics prev_specifics = 158 sync_pb::EntitySpecifics prev_specifics =
159 target_entry.Get(syncable::SERVER_SPECIFICS); 159 target_entry.Get(syncable::SERVER_SPECIFICS);
160 // We only store the old specifics if they were decryptable and applied and 160 // We only store the old specifics if they were decryptable and applied and
161 // there is no BASE_SERVER_SPECIFICS already. Else do nothing. 161 // there is no BASE_SERVER_SPECIFICS already. Else do nothing.
162 if (!target_entry.Get(syncable::IS_UNAPPLIED_UPDATE) && 162 if (!target_entry.Get(syncable::IS_UNAPPLIED_UPDATE) &&
163 !syncer::IsRealDataType(syncer::GetModelTypeFromSpecifics( 163 !syncer::IsRealDataType(syncer::GetModelTypeFromSpecifics(
(...skipping 12 matching lines...) Expand all
176 target_entry.Put(syncable::BASE_SERVER_SPECIFICS, 176 target_entry.Put(syncable::BASE_SERVER_SPECIFICS,
177 sync_pb::EntitySpecifics()); 177 sync_pb::EntitySpecifics());
178 } 178 }
179 179
180 UpdateServerFieldsFromUpdate(&target_entry, update, name); 180 UpdateServerFieldsFromUpdate(&target_entry, update, name);
181 181
182 return SUCCESS_PROCESSED; 182 return SUCCESS_PROCESSED;
183 } 183 }
184 184
185 } // namespace syncer 185 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/process_commit_response_command_unittest.cc ('k') | sync/engine/store_timestamps_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698