| OLD | NEW | 
|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """An implementation of the server side of the Chromium sync protocol. | 5 """An implementation of the server side of the Chromium sync protocol. | 
| 6 | 6 | 
| 7 The details of the protocol are described mostly by comments in the protocol | 7 The details of the protocol are described mostly by comments in the protocol | 
| 8 buffer definition at chrome/browser/sync/protocol/sync.proto. | 8 buffer definition at chrome/browser/sync/protocol/sync.proto. | 
| 9 """ | 9 """ | 
| 10 | 10 | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 122 # The parent ID used to indicate a top-level node. | 122 # The parent ID used to indicate a top-level node. | 
| 123 ROOT_ID = '0' | 123 ROOT_ID = '0' | 
| 124 | 124 | 
| 125 # Unix time epoch in struct_time format. The tuple corresponds to UTC Wednesday | 125 # Unix time epoch in struct_time format. The tuple corresponds to UTC Wednesday | 
| 126 # Jan 1 1970, 00:00:00, non-dst. | 126 # Jan 1 1970, 00:00:00, non-dst. | 
| 127 UNIX_TIME_EPOCH = (1970, 1, 1, 0, 0, 0, 3, 1, 0) | 127 UNIX_TIME_EPOCH = (1970, 1, 1, 0, 0, 0, 3, 1, 0) | 
| 128 | 128 | 
| 129 # The number of characters in the server-generated encryption key. | 129 # The number of characters in the server-generated encryption key. | 
| 130 KEYSTORE_KEY_LENGTH = 16 | 130 KEYSTORE_KEY_LENGTH = 16 | 
| 131 | 131 | 
| 132 # The hashed client tag for the keystore encryption experiment node. | 132 # The hashed client tags for some experiment nodes. | 
| 133 KEYSTORE_ENCRYPTION_EXPERIMENT_TAG = "pis8ZRzh98/MKLtVEio2mr42LQA=" | 133 KEYSTORE_ENCRYPTION_EXPERIMENT_TAG = "pis8ZRzh98/MKLtVEio2mr42LQA=" | 
|  | 134 PRE_COMMIT_GU_AVOIDANCE_EXPERIMENT_TAG = "Z1xgeh3QUBa50vdEPd8C/4c7jfE=" | 
| 134 | 135 | 
| 135 class Error(Exception): | 136 class Error(Exception): | 
| 136   """Error class for this module.""" | 137   """Error class for this module.""" | 
| 137 | 138 | 
| 138 | 139 | 
| 139 class ProtobufDataTypeFieldNotUnique(Error): | 140 class ProtobufDataTypeFieldNotUnique(Error): | 
| 140   """An entry should not have more than one data type present.""" | 141   """An entry should not have more than one data type present.""" | 
| 141 | 142 | 
| 142 | 143 | 
| 143 class DataTypeIdNotRecognized(Error): | 144 class DataTypeIdNotRecognized(Error): | 
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1094     if not self.acknowledge_managed_users: | 1095     if not self.acknowledge_managed_users: | 
| 1095       return | 1096       return | 
| 1096 | 1097 | 
| 1097     managed_users = [copy.deepcopy(entry) for entry in self._entries.values() | 1098     managed_users = [copy.deepcopy(entry) for entry in self._entries.values() | 
| 1098                      if entry.specifics.HasField('managed_user') | 1099                      if entry.specifics.HasField('managed_user') | 
| 1099                      and not entry.specifics.managed_user.acknowledged] | 1100                      and not entry.specifics.managed_user.acknowledged] | 
| 1100     for user in managed_users: | 1101     for user in managed_users: | 
| 1101       user.specifics.managed_user.acknowledged = True | 1102       user.specifics.managed_user.acknowledged = True | 
| 1102       self._SaveEntry(user) | 1103       self._SaveEntry(user) | 
| 1103 | 1104 | 
|  | 1105   def TriggerEnablePreCommitGetUpdateAvoidance(self): | 
|  | 1106     """Sets the experiment to enable pre-commit GetUpdate avoidance.""" | 
|  | 1107     experiment_id = self._ServerTagToId("google_chrome_experiments") | 
|  | 1108     pre_commit_gu_avoidance_id = self._ClientTagToId( | 
|  | 1109         EXPERIMENTS, | 
|  | 1110         PRE_COMMIT_GU_AVOIDANCE_EXPERIMENT_TAG) | 
|  | 1111     entry = self._entries.get(pre_commit_gu_avoidance_id) | 
|  | 1112     if entry is None: | 
|  | 1113       entry = sync_pb2.SyncEntity() | 
|  | 1114       entry.id_string = pre_commit_gu_avoidance_id | 
|  | 1115       entry.name = "Pre-commit GU avoidance" | 
|  | 1116       entry.client_defined_unique_tag = PRE_COMMIT_GU_AVOIDANCE_EXPERIMENT_TAG | 
|  | 1117       entry.folder = False | 
|  | 1118       entry.deleted = False | 
|  | 1119       entry.specifics.CopyFrom(GetDefaultEntitySpecifics(EXPERIMENTS)) | 
|  | 1120       self._WritePosition(entry, experiment_id) | 
|  | 1121     entry.specifics.experiments.pre_commit_update_avoidance.enabled = True | 
|  | 1122     self._SaveEntry(entry) | 
|  | 1123 | 
| 1104   def SetInducedError(self, error, error_frequency, | 1124   def SetInducedError(self, error, error_frequency, | 
| 1105                       sync_count_before_errors): | 1125                       sync_count_before_errors): | 
| 1106     self.induced_error = error | 1126     self.induced_error = error | 
| 1107     self.induced_error_frequency = error_frequency | 1127     self.induced_error_frequency = error_frequency | 
| 1108     self.sync_count_before_errors = sync_count_before_errors | 1128     self.sync_count_before_errors = sync_count_before_errors | 
| 1109 | 1129 | 
| 1110   def GetInducedError(self): | 1130   def GetInducedError(self): | 
| 1111     return self.induced_error | 1131     return self.induced_error | 
| 1112 | 1132 | 
| 1113 | 1133 | 
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1274             '<H1>Rotate Keystore Keys</H1></html>') | 1294             '<H1>Rotate Keystore Keys</H1></html>') | 
| 1275 | 1295 | 
| 1276   def HandleEnableManagedUserAcknowledgement(self): | 1296   def HandleEnableManagedUserAcknowledgement(self): | 
| 1277     """Enable acknowledging newly created managed users.""" | 1297     """Enable acknowledging newly created managed users.""" | 
| 1278     self.account.acknowledge_managed_users = True | 1298     self.account.acknowledge_managed_users = True | 
| 1279     return ( | 1299     return ( | 
| 1280         200, | 1300         200, | 
| 1281         '<html><title>Enable Managed User Acknowledgement</title>' | 1301         '<html><title>Enable Managed User Acknowledgement</title>' | 
| 1282             '<h1>Enable Managed User Acknowledgement</h1></html>') | 1302             '<h1>Enable Managed User Acknowledgement</h1></html>') | 
| 1283 | 1303 | 
|  | 1304   def HandleEnablePreCommitGetUpdateAvoidance(self): | 
|  | 1305     """Enables the pre-commit GU avoidance experiment.""" | 
|  | 1306     self.account.TriggerEnablePreCommitGetUpdateAvoidance() | 
|  | 1307     return ( | 
|  | 1308         200, | 
|  | 1309         '<html><title>Enable pre-commit GU avoidance</title>' | 
|  | 1310             '<H1>Enable pre-commit GU avoidance</H1></html>') | 
|  | 1311 | 
| 1284   def HandleCommand(self, query, raw_request): | 1312   def HandleCommand(self, query, raw_request): | 
| 1285     """Decode and handle a sync command from a raw input of bytes. | 1313     """Decode and handle a sync command from a raw input of bytes. | 
| 1286 | 1314 | 
| 1287     This is the main entry point for this class.  It is safe to call this | 1315     This is the main entry point for this class.  It is safe to call this | 
| 1288     method from multiple threads. | 1316     method from multiple threads. | 
| 1289 | 1317 | 
| 1290     Args: | 1318     Args: | 
| 1291       raw_request: An iterable byte sequence to be interpreted as a sync | 1319       raw_request: An iterable byte sequence to be interpreted as a sync | 
| 1292         protocol command. | 1320         protocol command. | 
| 1293     Returns: | 1321     Returns: | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1439     sending_nigori_node = False | 1467     sending_nigori_node = False | 
| 1440     for entry in entries: | 1468     for entry in entries: | 
| 1441       if entry.name == 'Nigori': | 1469       if entry.name == 'Nigori': | 
| 1442         sending_nigori_node = True | 1470         sending_nigori_node = True | 
| 1443       reply = update_response.entries.add() | 1471       reply = update_response.entries.add() | 
| 1444       reply.CopyFrom(entry) | 1472       reply.CopyFrom(entry) | 
| 1445     update_sieve.SaveProgress(new_timestamp, update_response) | 1473     update_sieve.SaveProgress(new_timestamp, update_response) | 
| 1446 | 1474 | 
| 1447     if update_request.need_encryption_key or sending_nigori_node: | 1475     if update_request.need_encryption_key or sending_nigori_node: | 
| 1448       update_response.encryption_keys.extend(self.account.GetKeystoreKeys()) | 1476       update_response.encryption_keys.extend(self.account.GetKeystoreKeys()) | 
| OLD | NEW | 
|---|