OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """An implementation of the server side of the Chromium sync protocol. | 6 """An implementation of the server side of the Chromium sync protocol. |
7 | 7 |
8 The details of the protocol are described mostly by comments in the protocol | 8 The details of the protocol are described mostly by comments in the protocol |
9 buffer definition at chrome/browser/sync/protocol/sync.proto. | 9 buffer definition at chrome/browser/sync/protocol/sync.proto. |
10 """ | 10 """ |
11 | 11 |
12 import cgi | 12 import cgi |
13 import copy | 13 import copy |
14 import operator | 14 import operator |
15 import pickle | 15 import pickle |
16 import random | 16 import random |
17 import sys | 17 import sys |
18 import threading | 18 import threading |
| 19 import time |
19 import urlparse | 20 import urlparse |
20 | 21 |
21 import app_notification_specifics_pb2 | 22 import app_notification_specifics_pb2 |
22 import app_setting_specifics_pb2 | 23 import app_setting_specifics_pb2 |
23 import app_specifics_pb2 | 24 import app_specifics_pb2 |
24 import autofill_specifics_pb2 | 25 import autofill_specifics_pb2 |
25 import bookmark_specifics_pb2 | 26 import bookmark_specifics_pb2 |
26 import extension_setting_specifics_pb2 | 27 import extension_setting_specifics_pb2 |
27 import extension_specifics_pb2 | 28 import extension_specifics_pb2 |
28 import nigori_specifics_pb2 | 29 import nigori_specifics_pb2 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 PREFERENCE: preference_specifics_pb2.preference, | 76 PREFERENCE: preference_specifics_pb2.preference, |
76 SEARCH_ENGINE: search_engine_specifics_pb2.search_engine, | 77 SEARCH_ENGINE: search_engine_specifics_pb2.search_engine, |
77 SESSION: session_specifics_pb2.session, | 78 SESSION: session_specifics_pb2.session, |
78 THEME: theme_specifics_pb2.theme, | 79 THEME: theme_specifics_pb2.theme, |
79 TYPED_URL: typed_url_specifics_pb2.typed_url, | 80 TYPED_URL: typed_url_specifics_pb2.typed_url, |
80 } | 81 } |
81 | 82 |
82 # The parent ID used to indicate a top-level node. | 83 # The parent ID used to indicate a top-level node. |
83 ROOT_ID = '0' | 84 ROOT_ID = '0' |
84 | 85 |
| 86 # Unix time epoch in struct_time format. The tuple corresponds to UTC Wednesday |
| 87 # Jan 1 1970, 00:00:00, non-dst. |
| 88 UNIX_TIME_EPOCH = (1970, 1, 1, 0, 0, 0, 3, 1, 0) |
85 | 89 |
86 class Error(Exception): | 90 class Error(Exception): |
87 """Error class for this module.""" | 91 """Error class for this module.""" |
88 | 92 |
89 | 93 |
90 class ProtobufExtensionNotUnique(Error): | 94 class ProtobufExtensionNotUnique(Error): |
91 """An entry should not have more than one protobuf extension present.""" | 95 """An entry should not have more than one protobuf extension present.""" |
92 | 96 |
93 | 97 |
94 class DataTypeIdNotRecognized(Error): | 98 class DataTypeIdNotRecognized(Error): |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 entry.sync_timestamp = self._version | 459 entry.sync_timestamp = self._version |
456 | 460 |
457 # Preserve the originator info, which the client is not required to send | 461 # Preserve the originator info, which the client is not required to send |
458 # when updating. | 462 # when updating. |
459 base_entry = self._entries.get(entry.id_string) | 463 base_entry = self._entries.get(entry.id_string) |
460 if base_entry: | 464 if base_entry: |
461 entry.originator_cache_guid = base_entry.originator_cache_guid | 465 entry.originator_cache_guid = base_entry.originator_cache_guid |
462 entry.originator_client_item_id = base_entry.originator_client_item_id | 466 entry.originator_client_item_id = base_entry.originator_client_item_id |
463 | 467 |
464 self._entries[entry.id_string] = copy.deepcopy(entry) | 468 self._entries[entry.id_string] = copy.deepcopy(entry) |
| 469 # Store the current time since the Unix epoch in milliseconds. |
| 470 self._entries[entry.id_string].mtime = (int((time.mktime(time.gmtime()) - |
| 471 time.mktime(UNIX_TIME_EPOCH))*1000)) |
465 | 472 |
466 def _ServerTagToId(self, tag): | 473 def _ServerTagToId(self, tag): |
467 """Determine the server ID from a server-unique tag. | 474 """Determine the server ID from a server-unique tag. |
468 | 475 |
469 The resulting value is guaranteed not to collide with the other ID | 476 The resulting value is guaranteed not to collide with the other ID |
470 generation methods. | 477 generation methods. |
471 | 478 |
472 Args: | 479 Args: |
473 datatype: The sync type (python enum) of the identified object. | 480 datatype: The sync type (python enum) of the identified object. |
474 tag: The unique, known-to-the-client tag of a server-generated item. | 481 tag: The unique, known-to-the-client tag of a server-generated item. |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 | 1189 |
1183 update_sieve.CheckMigrationState() | 1190 update_sieve.CheckMigrationState() |
1184 | 1191 |
1185 new_timestamp, entries, remaining = self.account.GetChanges(update_sieve) | 1192 new_timestamp, entries, remaining = self.account.GetChanges(update_sieve) |
1186 | 1193 |
1187 update_response.changes_remaining = remaining | 1194 update_response.changes_remaining = remaining |
1188 for entry in entries: | 1195 for entry in entries: |
1189 reply = update_response.entries.add() | 1196 reply = update_response.entries.add() |
1190 reply.CopyFrom(entry) | 1197 reply.CopyFrom(entry) |
1191 update_sieve.SaveProgress(new_timestamp, update_response) | 1198 update_sieve.SaveProgress(new_timestamp, update_response) |
OLD | NEW |