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 """ |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 all_entries = self._entries.values() | 856 all_entries = self._entries.values() |
857 self._entries.clear() | 857 self._entries.clear() |
858 for entry in all_entries: | 858 for entry in all_entries: |
859 new_id = self._RewriteVersionInId(entry.id_string) | 859 new_id = self._RewriteVersionInId(entry.id_string) |
860 entry.id_string = new_id | 860 entry.id_string = new_id |
861 if entry.HasField('parent_id_string'): | 861 if entry.HasField('parent_id_string'): |
862 entry.parent_id_string = self._RewriteVersionInId( | 862 entry.parent_id_string = self._RewriteVersionInId( |
863 entry.parent_id_string) | 863 entry.parent_id_string) |
864 self._entries[entry.id_string] = entry | 864 self._entries[entry.id_string] = entry |
865 | 865 |
866 def TriggerSyncTabs(self): | |
867 """ Set the 'sync_tabs' field to this account's nigori node. | |
ncarter (slow)
2011/08/25 00:05:09
No space after """
Nicolas Zea
2011/08/25 23:36:23
Done.
| |
868 | |
869 If the field is not currently set, will write a new nigori node entry | |
870 with the field set. Else does nothing. | |
871 """ | |
872 | |
873 nigori_tag = "google_chrome_nigori" | |
874 nigori_original = self._entries.get(self._ServerTagToId(nigori_tag)) | |
875 if (nigori_original.specifics.Extensions[nigori_specifics_pb2.nigori]. | |
876 sync_tabs): | |
877 return | |
878 nigori_new = copy.deepcopy(nigori_original) | |
879 nigori_new.specifics.Extensions[nigori_specifics_pb2.nigori].sync_tabs = ( | |
880 True) | |
881 self._SaveEntry(nigori_new) | |
866 | 882 |
867 class TestServer(object): | 883 class TestServer(object): |
ncarter (slow)
2011/08/25 00:05:09
Each top-level definition should be preceded by 2
Nicolas Zea
2011/08/25 23:36:23
Done.
| |
868 """An object to handle requests for one (and only one) Chrome Sync account. | 884 """An object to handle requests for one (and only one) Chrome Sync account. |
869 | 885 |
870 TestServer consumes the sync command messages that are the outermost | 886 TestServer consumes the sync command messages that are the outermost |
871 layers of the protocol, performs the corresponding actions on its | 887 layers of the protocol, performs the corresponding actions on its |
872 SyncDataModel, and constructs an appropropriate response message. | 888 SyncDataModel, and constructs an appropropriate response message. |
873 """ | 889 """ |
874 | 890 |
875 def __init__(self): | 891 def __init__(self): |
876 # The implementation supports exactly one account; its state is here. | 892 # The implementation supports exactly one account; its state is here. |
877 self.account = SyncDataModel() | 893 self.account = SyncDataModel() |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 return ( | 948 return ( |
933 200, | 949 200, |
934 '<html><title>Birthday error</title><H1>Birthday error</H1></html>') | 950 '<html><title>Birthday error</title><H1>Birthday error</H1></html>') |
935 | 951 |
936 def HandleSetTransientError(self): | 952 def HandleSetTransientError(self): |
937 self.transient_error = True | 953 self.transient_error = True |
938 return ( | 954 return ( |
939 200, | 955 200, |
940 '<html><title>Transient error</title><H1>Transient error</H1></html>') | 956 '<html><title>Transient error</title><H1>Transient error</H1></html>') |
941 | 957 |
958 def HandleSetSyncTabs(self): | |
959 """ Set the 'sync_tab' field of the nigori node for this account. """ | |
ncarter (slow)
2011/08/25 00:05:09
No space after opening """ and no space between .
Nicolas Zea
2011/08/25 23:36:23
Done.
| |
960 self.account.TriggerSyncTabs(); | |
ncarter (slow)
2011/08/25 00:05:09
SEMICOLON?!?!
Nicolas Zea
2011/08/25 23:36:23
Done.
| |
961 return ( | |
962 200, | |
963 '<html><title>Sync Tabs</title><H1>Sync Tabs</H1></html>') | |
964 | |
942 def HandleCommand(self, query, raw_request): | 965 def HandleCommand(self, query, raw_request): |
943 """Decode and handle a sync command from a raw input of bytes. | 966 """Decode and handle a sync command from a raw input of bytes. |
944 | 967 |
945 This is the main entry point for this class. It is safe to call this | 968 This is the main entry point for this class. It is safe to call this |
946 method from multiple threads. | 969 method from multiple threads. |
947 | 970 |
948 Args: | 971 Args: |
949 raw_request: An iterable byte sequence to be interpreted as a sync | 972 raw_request: An iterable byte sequence to be interpreted as a sync |
950 protocol command. | 973 protocol command. |
951 Returns: | 974 Returns: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1078 | 1101 |
1079 update_sieve.CheckMigrationState() | 1102 update_sieve.CheckMigrationState() |
1080 | 1103 |
1081 new_timestamp, entries, remaining = self.account.GetChanges(update_sieve) | 1104 new_timestamp, entries, remaining = self.account.GetChanges(update_sieve) |
1082 | 1105 |
1083 update_response.changes_remaining = remaining | 1106 update_response.changes_remaining = remaining |
1084 for entry in entries: | 1107 for entry in entries: |
1085 reply = update_response.entries.add() | 1108 reply = update_response.entries.add() |
1086 reply.CopyFrom(entry) | 1109 reply.CopyFrom(entry) |
1087 update_sieve.SaveProgress(new_timestamp, update_response) | 1110 update_sieve.SaveProgress(new_timestamp, update_response) |
OLD | NEW |