OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "build/build_config.h" | |
17 #include "chrome/browser/sync/engine/syncer.h" | 16 #include "chrome/browser/sync/engine/syncer.h" |
18 #include "chrome/browser/sync/engine/syncer_types.h" | 17 #include "chrome/browser/sync/engine/syncer_types.h" |
19 #include "chrome/browser/sync/syncable/syncable.h" | 18 #include "chrome/browser/sync/syncable/syncable.h" |
20 #include "chrome/browser/sync/syncable/syncable_id.h" | 19 #include "chrome/browser/sync/syncable/syncable_id.h" |
21 | 20 |
22 namespace browser_sync { | 21 namespace browser_sync { |
23 | 22 |
24 class Cryptographer; | 23 class Cryptographer; |
25 class SyncEntity; | 24 class SyncEntity; |
26 | 25 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 132 |
134 // Examine the up-to-date predecessors of this item according to the server | 133 // Examine the up-to-date predecessors of this item according to the server |
135 // position, and then again according to the local position. Return true | 134 // position, and then again according to the local position. Return true |
136 // if they match. For an up-to-date item, this should be the case. | 135 // if they match. For an up-to-date item, this should be the case. |
137 static bool ServerAndLocalOrdersMatch(syncable::Entry* entry); | 136 static bool ServerAndLocalOrdersMatch(syncable::Entry* entry); |
138 | 137 |
139 private: | 138 private: |
140 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncerUtil); | 139 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncerUtil); |
141 }; | 140 }; |
142 | 141 |
143 #ifndef OS_WIN | |
144 | |
145 // time.h on Linux and Mac both return seconds since the epoch, this should | |
146 // be converted to milliseconds. | |
147 inline int64 ServerTimeToClientTime(int64 server_time) { | |
148 return server_time / GG_LONGLONG(1000); | |
149 } | |
150 | |
151 inline int64 ClientTimeToServerTime(int64 client_time) { | |
152 return client_time * GG_LONGLONG(1000); | |
153 } | |
154 | |
155 // As we truncate server times on the client for posix and on the server for | |
156 // windows we need two ClientAndServerTimeMatch fucntions. | |
157 inline bool ClientAndServerTimeMatch(int64 client_time, int64 server_time) { | |
158 // Compare at the coarser timescale (client) | |
159 return client_time == ServerTimeToClientTime(server_time); | |
160 } | |
161 #else | |
162 // The sync server uses Java Times (ms since 1970) | |
163 // and the client uses FILETIMEs (ns since 1601) so we need to convert | |
164 // between the timescales. | |
165 // TODO(sync): Fix this. No need to use two timescales. | |
166 inline int64 ServerTimeToClientTime(int64 server_time) { | |
167 return server_time * GG_LONGLONG(10000) + GG_LONGLONG(116444736000000000); | |
168 } | |
169 | |
170 inline int64 ClientTimeToServerTime(int64 client_time) { | |
171 return (client_time - GG_LONGLONG(116444736000000000)) / GG_LONGLONG(10000); | |
172 } | |
173 | |
174 inline bool ClientAndServerTimeMatch(int64 client_time, int64 server_time) { | |
175 // Compare at the coarser timescale (server) | |
176 return ClientTimeToServerTime(client_time) == server_time; | |
177 } | |
178 #endif | |
179 | |
180 } // namespace browser_sync | 142 } // namespace browser_sync |
181 | 143 |
182 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | 144 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ |
OLD | NEW |