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

Side by Side Diff: chrome/browser/sync/engine/build_commit_command.cc

Issue 2844037: Fix handling of undeletion within the syncer. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Whitespace. Created 10 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
« no previous file with comments | « no previous file | chrome/browser/sync/engine/conflict_resolver.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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/engine/build_commit_command.h" 5 #include "chrome/browser/sync/engine/build_commit_command.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 void BuildCommitCommand::ExecuteImpl(SyncSession* session) { 86 void BuildCommitCommand::ExecuteImpl(SyncSession* session) {
87 ClientToServerMessage message; 87 ClientToServerMessage message;
88 message.set_share(session->context()->account_name()); 88 message.set_share(session->context()->account_name());
89 message.set_message_contents(ClientToServerMessage::COMMIT); 89 message.set_message_contents(ClientToServerMessage::COMMIT);
90 90
91 CommitMessage* commit_message = message.mutable_commit(); 91 CommitMessage* commit_message = message.mutable_commit();
92 commit_message->set_cache_guid( 92 commit_message->set_cache_guid(
93 session->write_transaction()->directory()->cache_guid()); 93 session->write_transaction()->directory()->cache_guid());
94 AddExtensionsActivityToMessage(session, commit_message); 94 AddExtensionsActivityToMessage(session, commit_message);
95 SyncerProtoUtil::AddRequestBirthday(
96 session->write_transaction()->directory(), &message);
95 97
96 const vector<Id>& commit_ids = session->status_controller()->commit_ids(); 98 const vector<Id>& commit_ids = session->status_controller()->commit_ids();
97 for (size_t i = 0; i < commit_ids.size(); i++) { 99 for (size_t i = 0; i < commit_ids.size(); i++) {
98 Id id = commit_ids[i]; 100 Id id = commit_ids[i];
99 SyncEntity* sync_entry = 101 SyncEntity* sync_entry =
100 static_cast<SyncEntity*>(commit_message->add_entries()); 102 static_cast<SyncEntity*>(commit_message->add_entries());
101 sync_entry->set_id(id); 103 sync_entry->set_id(id);
102 MutableEntry meta_entry(session->write_transaction(), 104 MutableEntry meta_entry(session->write_transaction(),
103 syncable::GET_BY_ID, 105 syncable::GET_BY_ID,
104 id); 106 id);
(...skipping 13 matching lines...) Expand all
118 // the |name| value (using |non_unique_name| instead), and will return 120 // the |name| value (using |non_unique_name| instead), and will return
119 // in the CommitResponse a unique name if one is generated. 121 // in the CommitResponse a unique name if one is generated.
120 // We send both because it may aid in logging. 122 // We send both because it may aid in logging.
121 sync_entry->set_non_unique_name(name); 123 sync_entry->set_non_unique_name(name);
122 124
123 if (!meta_entry.Get(syncable::UNIQUE_CLIENT_TAG).empty()) { 125 if (!meta_entry.Get(syncable::UNIQUE_CLIENT_TAG).empty()) {
124 sync_entry->set_client_defined_unique_tag( 126 sync_entry->set_client_defined_unique_tag(
125 meta_entry.Get(syncable::UNIQUE_CLIENT_TAG)); 127 meta_entry.Get(syncable::UNIQUE_CLIENT_TAG));
126 } 128 }
127 129
128 // Deleted items with negative parent ids can be a problem so we set the 130 // Deleted items with server-unknown parent ids can be a problem so we set
129 // parent to 0. (TODO(sync): Still true in protocol?). 131 // the parent to 0. (TODO(sync): Still true in protocol?).
130 Id new_parent_id; 132 Id new_parent_id;
131 if (meta_entry.Get(syncable::IS_DEL) && 133 if (meta_entry.Get(syncable::IS_DEL) &&
132 !meta_entry.Get(syncable::PARENT_ID).ServerKnows()) { 134 !meta_entry.Get(syncable::PARENT_ID).ServerKnows()) {
133 new_parent_id = session->write_transaction()->root_id(); 135 new_parent_id = session->write_transaction()->root_id();
134 } else { 136 } else {
135 new_parent_id = meta_entry.Get(syncable::PARENT_ID); 137 new_parent_id = meta_entry.Get(syncable::PARENT_ID);
136 } 138 }
137 sync_entry->set_parent_id(new_parent_id); 139 sync_entry->set_parent_id(new_parent_id);
138 // TODO(sync): Investigate all places that think transactional commits 140
139 // actually exist. 141 // If our parent has changed, send up the old one so the server
140 // 142 // can correctly deal with multiple parents.
141 // This is the only logic we'll need when transactional commits are moved 143 // TODO(nick): With the server keeping track of the primary sync parent,
142 // to the server. If our parent has changes, send up the old one so the 144 // it should not be necessary to provide the old_parent_id: the version
143 // server can correctly deal with multiple parents. 145 // number should suffice.
144 if (new_parent_id != meta_entry.Get(syncable::SERVER_PARENT_ID) && 146 if (new_parent_id != meta_entry.Get(syncable::SERVER_PARENT_ID) &&
145 0 != meta_entry.Get(syncable::BASE_VERSION) && 147 0 != meta_entry.Get(syncable::BASE_VERSION) &&
146 syncable::CHANGES_VERSION != meta_entry.Get(syncable::BASE_VERSION)) { 148 syncable::CHANGES_VERSION != meta_entry.Get(syncable::BASE_VERSION)) {
147 sync_entry->set_old_parent_id(meta_entry.Get(syncable::SERVER_PARENT_ID)); 149 sync_entry->set_old_parent_id(meta_entry.Get(syncable::SERVER_PARENT_ID));
148 } 150 }
149 151
150 int64 version = meta_entry.Get(syncable::BASE_VERSION); 152 int64 version = meta_entry.Get(syncable::BASE_VERSION);
151 if (syncable::CHANGES_VERSION == version || 0 == version) { 153 if (syncable::CHANGES_VERSION == version || 0 == version) {
152 // If this CHECK triggers during unit testing, check that we haven't 154 // Undeletions are only supported for items that have a client tag.
153 // altered an item that's an unapplied update. 155 DCHECK(!id.ServerKnows() ||
154 CHECK(!id.ServerKnows()) << meta_entry; 156 !meta_entry.Get(syncable::UNIQUE_CLIENT_TAG).empty())
157 << meta_entry;
158
159 // Version 0 means to create or undelete an object.
155 sync_entry->set_version(0); 160 sync_entry->set_version(0);
156 } else { 161 } else {
157 CHECK(id.ServerKnows()) << meta_entry; 162 DCHECK(id.ServerKnows()) << meta_entry;
158 sync_entry->set_version(meta_entry.Get(syncable::BASE_VERSION)); 163 sync_entry->set_version(meta_entry.Get(syncable::BASE_VERSION));
159 } 164 }
160 sync_entry->set_ctime(ClientTimeToServerTime( 165 sync_entry->set_ctime(ClientTimeToServerTime(
161 meta_entry.Get(syncable::CTIME))); 166 meta_entry.Get(syncable::CTIME)));
162 sync_entry->set_mtime(ClientTimeToServerTime( 167 sync_entry->set_mtime(ClientTimeToServerTime(
163 meta_entry.Get(syncable::MTIME))); 168 meta_entry.Get(syncable::MTIME)));
164 169
165 // Deletion is final on the server, let's move things and then delete them. 170 // Deletion is final on the server, let's move things and then delete them.
166 if (meta_entry.Get(IS_DEL)) { 171 if (meta_entry.Get(IS_DEL)) {
167 sync_entry->set_deleted(true); 172 sync_entry->set_deleted(true);
(...skipping 10 matching lines...) Expand all
178 // the new-style scheme, we should abandon the old way. 183 // the new-style scheme, we should abandon the old way.
179 SetOldStyleBookmarkData(&meta_entry, sync_entry); 184 SetOldStyleBookmarkData(&meta_entry, sync_entry);
180 } 185 }
181 SetEntrySpecifics(&meta_entry, sync_entry); 186 SetEntrySpecifics(&meta_entry, sync_entry);
182 } 187 }
183 } 188 }
184 session->status_controller()->mutable_commit_message()->CopyFrom(message); 189 session->status_controller()->mutable_commit_message()->CopyFrom(message);
185 } 190 }
186 191
187 } // namespace browser_sync 192 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/engine/conflict_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698