| 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 // Utility functions manipulating syncable::Entries, intended for use by the | 5 // Utility functions manipulating syncable::Entries, intended for use by the |
| 6 // syncer. | 6 // syncer. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ |
| 9 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | 9 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/sync/engine/syncer.h" | 16 #include "chrome/browser/sync/engine/syncer.h" |
| 17 #include "chrome/browser/sync/engine/syncer_types.h" | 17 #include "chrome/browser/sync/engine/syncer_types.h" |
| 18 #include "chrome/browser/sync/syncable/syncable.h" | 18 #include "chrome/browser/sync/syncable/syncable.h" |
| 19 #include "chrome/browser/sync/syncable/syncable_id.h" | 19 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 20 #include "chrome/browser/sync/util/path_helpers.h" | 20 #include "chrome/browser/sync/util/path_helpers.h" |
| 21 #include "chrome/browser/sync/util/sync_types.h" | 21 #include "chrome/browser/sync/util/sync_types.h" |
| 22 | 22 |
| 23 namespace browser_sync { | 23 namespace browser_sync { |
| 24 | 24 |
| 25 class SyncEntity; | 25 class SyncEntity; |
| 26 | 26 |
| 27 class SyncerUtil { | 27 class SyncerUtil { |
| 28 public: | 28 public: |
| 29 // TODO(ncarter): Remove unique-in-parent title support and name conflicts. | |
| 30 static syncable::Id GetNameConflictingItemId( | |
| 31 syncable::BaseTransaction* trans, | |
| 32 const syncable::Id& parent_id, | |
| 33 const PathString& server_name); | |
| 34 | |
| 35 static void ChangeEntryIDAndUpdateChildren( | 29 static void ChangeEntryIDAndUpdateChildren( |
| 36 syncable::WriteTransaction* trans, | 30 syncable::WriteTransaction* trans, |
| 37 syncable::MutableEntry* entry, | 31 syncable::MutableEntry* entry, |
| 38 const syncable::Id& new_id, | 32 const syncable::Id& new_id, |
| 39 syncable::Directory::ChildHandles* children); | 33 syncable::Directory::ChildHandles* children); |
| 40 | 34 |
| 41 // Returns the number of unsynced entries. | 35 // Returns the number of unsynced entries. |
| 42 static int GetUnsyncedEntries(syncable::BaseTransaction* trans, | 36 static int GetUnsyncedEntries(syncable::BaseTransaction* trans, |
| 43 std::vector<int64> *handles); | 37 std::vector<int64> *handles); |
| 44 | 38 |
| 45 static void ChangeEntryIDAndUpdateChildren(syncable::WriteTransaction* trans, | 39 static void ChangeEntryIDAndUpdateChildren(syncable::WriteTransaction* trans, |
| 46 syncable::MutableEntry* entry, | 40 syncable::MutableEntry* entry, |
| 47 const syncable::Id& new_id); | 41 const syncable::Id& new_id); |
| 48 | 42 |
| 49 static void AttemptReuniteLostCommitResponses( | 43 static void AttemptReuniteLostCommitResponses( |
| 50 syncable::WriteTransaction* trans, | 44 syncable::WriteTransaction* trans, |
| 51 const SyncEntity& server_entry, | 45 const SyncEntity& server_entry, |
| 52 const std::string& client_id); | 46 const std::string& client_id); |
| 53 | 47 |
| 54 static UpdateAttemptResponse AttemptToUpdateEntry( | 48 static UpdateAttemptResponse AttemptToUpdateEntry( |
| 55 syncable::WriteTransaction* const trans, | 49 syncable::WriteTransaction* const trans, |
| 56 syncable::MutableEntry* const entry, | 50 syncable::MutableEntry* const entry, |
| 57 ConflictResolver* resolver); | 51 ConflictResolver* resolver); |
| 58 | 52 |
| 59 static UpdateAttemptResponse AttemptToUpdateEntryWithoutMerge( | |
| 60 syncable::WriteTransaction* const trans, | |
| 61 syncable::MutableEntry* const entry, | |
| 62 syncable::Id* const conflicting_id); | |
| 63 | 53 |
| 64 // Pass in name to avoid redundant UTF8 conversion. | 54 // Pass in name to avoid redundant UTF8 conversion. |
| 65 static void UpdateServerFieldsFromUpdate( | 55 static void UpdateServerFieldsFromUpdate( |
| 66 syncable::MutableEntry* local_entry, | 56 syncable::MutableEntry* local_entry, |
| 67 const SyncEntity& server_entry, | 57 const SyncEntity& server_entry, |
| 68 const syncable::SyncName& name); | 58 const PathString& name); |
| 69 | 59 |
| 70 static void ApplyExtendedAttributes( | 60 static void ApplyExtendedAttributes( |
| 71 syncable::MutableEntry* local_entry, | 61 syncable::MutableEntry* local_entry, |
| 72 const SyncEntity& server_entry); | 62 const SyncEntity& server_entry); |
| 73 | 63 |
| 74 // Creates a new Entry iff no Entry exists with the given id. | 64 // Creates a new Entry iff no Entry exists with the given id. |
| 75 static void CreateNewEntry(syncable::WriteTransaction *trans, | 65 static void CreateNewEntry(syncable::WriteTransaction *trans, |
| 76 const syncable::Id& id); | 66 const syncable::Id& id); |
| 77 | 67 |
| 78 static bool ServerAndLocalEntriesMatch(syncable::Entry* entry); | 68 static bool ServerAndLocalEntriesMatch(syncable::Entry* entry); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // As we truncate server times on the client for posix and on the server for | 169 // As we truncate server times on the client for posix and on the server for |
| 180 // windows we need two ClientAndServerTimeMatch fucntions. | 170 // windows we need two ClientAndServerTimeMatch fucntions. |
| 181 inline bool ClientAndServerTimeMatch(int64 client_time, int64 server_time) { | 171 inline bool ClientAndServerTimeMatch(int64 client_time, int64 server_time) { |
| 182 // Compare at the coarser timescale (client) | 172 // Compare at the coarser timescale (client) |
| 183 return client_time == ServerTimeToClientTime(server_time); | 173 return client_time == ServerTimeToClientTime(server_time); |
| 184 } | 174 } |
| 185 #else | 175 #else |
| 186 // The sync server uses Java Times (ms since 1970) | 176 // The sync server uses Java Times (ms since 1970) |
| 187 // and the client uses FILETIMEs (ns since 1601) so we need to convert | 177 // and the client uses FILETIMEs (ns since 1601) so we need to convert |
| 188 // between the timescales. | 178 // between the timescales. |
| 179 // TODO(sync): Fix this. No need to use two timescales. |
| 189 inline int64 ServerTimeToClientTime(int64 server_time) { | 180 inline int64 ServerTimeToClientTime(int64 server_time) { |
| 190 return server_time * GG_LONGLONG(10000) + GG_LONGLONG(116444736000000000); | 181 return server_time * GG_LONGLONG(10000) + GG_LONGLONG(116444736000000000); |
| 191 } | 182 } |
| 192 | 183 |
| 193 inline int64 ClientTimeToServerTime(int64 client_time) { | 184 inline int64 ClientTimeToServerTime(int64 client_time) { |
| 194 return (client_time - GG_LONGLONG(116444736000000000)) / GG_LONGLONG(10000); | 185 return (client_time - GG_LONGLONG(116444736000000000)) / GG_LONGLONG(10000); |
| 195 } | 186 } |
| 196 | 187 |
| 197 inline bool ClientAndServerTimeMatch(int64 client_time, int64 server_time) { | 188 inline bool ClientAndServerTimeMatch(int64 client_time, int64 server_time) { |
| 198 // Compare at the coarser timescale (server) | 189 // Compare at the coarser timescale (server) |
| 199 return ClientTimeToServerTime(client_time) == server_time; | 190 return ClientTimeToServerTime(client_time) == server_time; |
| 200 } | 191 } |
| 201 #endif | 192 #endif |
| 202 | 193 |
| 203 } // namespace browser_sync | 194 } // namespace browser_sync |
| 204 | 195 |
| 205 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | 196 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ |
| OLD | NEW |