OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/syncer_util.h" | 5 #include "chrome/browser/sync/engine/syncer_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/sync/engine/conflict_resolver.h" | 11 #include "chrome/browser/sync/engine/conflict_resolver.h" |
12 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 12 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
13 #include "chrome/browser/sync/engine/syncer_session.h" | |
14 #include "chrome/browser/sync/engine/syncer_types.h" | 13 #include "chrome/browser/sync/engine/syncer_types.h" |
15 #include "chrome/browser/sync/engine/syncproto.h" | 14 #include "chrome/browser/sync/engine/syncproto.h" |
16 #include "chrome/browser/sync/syncable/directory_manager.h" | 15 #include "chrome/browser/sync/syncable/directory_manager.h" |
17 #include "chrome/browser/sync/syncable/syncable.h" | 16 #include "chrome/browser/sync/syncable/syncable.h" |
18 #include "chrome/browser/sync/syncable/syncable_changes_version.h" | 17 #include "chrome/browser/sync/syncable/syncable_changes_version.h" |
19 #include "chrome/browser/sync/util/character_set_converters.h" | 18 #include "chrome/browser/sync/util/character_set_converters.h" |
20 #include "chrome/browser/sync/util/path_helpers.h" | 19 #include "chrome/browser/sync/util/path_helpers.h" |
21 #include "chrome/browser/sync/util/sync_types.h" | 20 #include "chrome/browser/sync/util/sync_types.h" |
22 | 21 |
23 using syncable::BASE_VERSION; | 22 using syncable::BASE_VERSION; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // !local_entry.Good() means we don't have a left behind entry for this | 212 // !local_entry.Good() means we don't have a left behind entry for this |
214 // ID. We successfully committed before. In the future we should get rid | 213 // ID. We successfully committed before. In the future we should get rid |
215 // of this system and just have client side generated IDs as a whole. | 214 // of this system and just have client side generated IDs as a whole. |
216 } | 215 } |
217 } | 216 } |
218 | 217 |
219 // static | 218 // static |
220 UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntry( | 219 UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntry( |
221 syncable::WriteTransaction* const trans, | 220 syncable::WriteTransaction* const trans, |
222 syncable::MutableEntry* const entry, | 221 syncable::MutableEntry* const entry, |
223 SyncerSession* const session) { | 222 ConflictResolver* resolver) { |
224 | 223 |
225 syncable::Id conflicting_id; | 224 syncable::Id conflicting_id; |
226 UpdateAttemptResponse result = | 225 UpdateAttemptResponse result = |
227 AttemptToUpdateEntryWithoutMerge(trans, entry, session, | 226 AttemptToUpdateEntryWithoutMerge(trans, entry, &conflicting_id); |
228 &conflicting_id); | |
229 if (result != NAME_CONFLICT) { | 227 if (result != NAME_CONFLICT) { |
230 return result; | 228 return result; |
231 } | 229 } |
232 syncable::MutableEntry same_path(trans, syncable::GET_BY_ID, conflicting_id); | 230 syncable::MutableEntry same_path(trans, syncable::GET_BY_ID, conflicting_id); |
233 CHECK(same_path.good()); | 231 CHECK(same_path.good()); |
234 | 232 |
235 ConflictResolver* resolver = session->resolver(); | |
236 | |
237 if (resolver && | 233 if (resolver && |
238 resolver->AttemptItemMerge(trans, &same_path, entry)) { | 234 resolver->AttemptItemMerge(trans, &same_path, entry)) { |
239 return SUCCESS; | 235 return SUCCESS; |
240 } | 236 } |
241 LOG(INFO) << "Not updating item, path collision. Update:\n" << *entry | 237 LOG(INFO) << "Not updating item, path collision. Update:\n" << *entry |
242 << "\nSame Path:\n" << same_path; | 238 << "\nSame Path:\n" << same_path; |
243 return CONFLICT; | 239 return CONFLICT; |
244 } | 240 } |
245 | 241 |
246 // static | 242 // static |
247 UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntryWithoutMerge( | 243 UpdateAttemptResponse SyncerUtil::AttemptToUpdateEntryWithoutMerge( |
248 syncable::WriteTransaction* const trans, | 244 syncable::WriteTransaction* const trans, |
249 syncable::MutableEntry* const entry, | 245 syncable::MutableEntry* const entry, |
250 SyncerSession* const session, syncable::Id* const conflicting_id) { | 246 syncable::Id* const conflicting_id) { |
251 | 247 |
252 CHECK(entry->good()); | 248 CHECK(entry->good()); |
253 if (!entry->Get(IS_UNAPPLIED_UPDATE)) | 249 if (!entry->Get(IS_UNAPPLIED_UPDATE)) |
254 return SUCCESS; // No work to do. | 250 return SUCCESS; // No work to do. |
255 syncable::Id id = entry->Get(ID); | 251 syncable::Id id = entry->Get(ID); |
256 | 252 |
257 if (entry->Get(IS_UNSYNCED)) { | 253 if (entry->Get(IS_UNSYNCED)) { |
258 LOG(INFO) << "Skipping update, returning conflict for: " << id | 254 LOG(INFO) << "Skipping update, returning conflict for: " << id |
259 << " ; it's unsynced."; | 255 << " ; it's unsynced."; |
260 return CONFLICT; | 256 return CONFLICT; |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 829 |
834 // |update_entry| is considered to be somewhere after |candidate|, so store | 830 // |update_entry| is considered to be somewhere after |candidate|, so store |
835 // it as the upper bound. | 831 // it as the upper bound. |
836 closest_sibling = candidate.Get(ID); | 832 closest_sibling = candidate.Get(ID); |
837 } | 833 } |
838 | 834 |
839 return closest_sibling; | 835 return closest_sibling; |
840 } | 836 } |
841 | 837 |
842 } // namespace browser_sync | 838 } // namespace browser_sync |
OLD | NEW |