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" |
16 #include "chrome/browser/sync/engine/syncer.h" | 17 #include "chrome/browser/sync/engine/syncer.h" |
17 #include "chrome/browser/sync/engine/syncer_types.h" | 18 #include "chrome/browser/sync/engine/syncer_types.h" |
18 #include "chrome/browser/sync/syncable/syncable.h" | 19 #include "chrome/browser/sync/syncable/syncable.h" |
19 #include "chrome/browser/sync/syncable/syncable_id.h" | 20 #include "chrome/browser/sync/syncable/syncable_id.h" |
20 | 21 |
21 namespace browser_sync { | 22 namespace browser_sync { |
22 | 23 |
23 class Cryptographer; | 24 class Cryptographer; |
24 class SyncEntity; | 25 class SyncEntity; |
25 | 26 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 // Examine the up-to-date predecessors of this item according to the server | 134 // Examine the up-to-date predecessors of this item according to the server |
134 // position, and then again according to the local position. Return true | 135 // position, and then again according to the local position. Return true |
135 // if they match. For an up-to-date item, this should be the case. | 136 // if they match. For an up-to-date item, this should be the case. |
136 static bool ServerAndLocalOrdersMatch(syncable::Entry* entry); | 137 static bool ServerAndLocalOrdersMatch(syncable::Entry* entry); |
137 | 138 |
138 private: | 139 private: |
139 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncerUtil); | 140 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncerUtil); |
140 }; | 141 }; |
141 | 142 |
| 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 |
142 } // namespace browser_sync | 180 } // namespace browser_sync |
143 | 181 |
144 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ | 182 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_UTIL_H_ |
OLD | NEW |