Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: sync/tools/testserver/chromiumsync.py

Issue 143973006: New Sync datatype for Synced Notifications App Info (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: AppInfo: CR fixes per Zea@ Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 28 matching lines...) Expand all
39 import favicon_tracking_specifics_pb2 39 import favicon_tracking_specifics_pb2
40 import history_delete_directive_specifics_pb2 40 import history_delete_directive_specifics_pb2
41 import managed_user_setting_specifics_pb2 41 import managed_user_setting_specifics_pb2
42 import managed_user_specifics_pb2 42 import managed_user_specifics_pb2
43 import managed_user_shared_setting_specifics_pb2 43 import managed_user_shared_setting_specifics_pb2
44 import nigori_specifics_pb2 44 import nigori_specifics_pb2
45 import password_specifics_pb2 45 import password_specifics_pb2
46 import preference_specifics_pb2 46 import preference_specifics_pb2
47 import priority_preference_specifics_pb2 47 import priority_preference_specifics_pb2
48 import search_engine_specifics_pb2 48 import search_engine_specifics_pb2
49 import server_app_info_specifics_pb2
49 import session_specifics_pb2 50 import session_specifics_pb2
50 import sync_pb2 51 import sync_pb2
51 import sync_enums_pb2 52 import sync_enums_pb2
52 import synced_notification_data_pb2 53 import synced_notification_data_pb2
53 import synced_notification_render_pb2 54 import synced_notification_render_pb2
54 import synced_notification_specifics_pb2 55 import synced_notification_specifics_pb2
55 import theme_specifics_pb2 56 import theme_specifics_pb2
56 import typed_url_specifics_pb2 57 import typed_url_specifics_pb2
57 58
58 # An enumeration of the various kinds of data that can be synced. 59 # An enumeration of the various kinds of data that can be synced.
(...skipping 18 matching lines...) Expand all
77 MANAGED_USER_SETTING, 78 MANAGED_USER_SETTING,
78 MANAGED_USER_SHARED_SETTING, 79 MANAGED_USER_SHARED_SETTING,
79 MANAGED_USER, 80 MANAGED_USER,
80 NIGORI, 81 NIGORI,
81 PASSWORD, 82 PASSWORD,
82 PREFERENCE, 83 PREFERENCE,
83 PRIORITY_PREFERENCE, 84 PRIORITY_PREFERENCE,
84 SEARCH_ENGINE, 85 SEARCH_ENGINE,
85 SESSION, 86 SESSION,
86 SYNCED_NOTIFICATION, 87 SYNCED_NOTIFICATION,
88 SYNCED_NOTIFICATION_APP_INFO,
87 THEME, 89 THEME,
88 TYPED_URL, 90 TYPED_URL,
89 EXTENSION_SETTINGS, 91 EXTENSION_SETTINGS,
90 FAVICON_IMAGES, 92 FAVICON_IMAGES,
91 FAVICON_TRACKING) = range(29) 93 FAVICON_TRACKING) = range(30)
92 94
93 # An enumeration on the frequency at which the server should send errors 95 # An enumeration on the frequency at which the server should send errors
94 # to the client. This would be specified by the url that triggers the error. 96 # to the client. This would be specified by the url that triggers the error.
95 # Note: This enum should be kept in the same order as the enum in sync_test.h. 97 # Note: This enum should be kept in the same order as the enum in sync_test.h.
96 SYNC_ERROR_FREQUENCY = ( 98 SYNC_ERROR_FREQUENCY = (
97 ERROR_FREQUENCY_NONE, 99 ERROR_FREQUENCY_NONE,
98 ERROR_FREQUENCY_ALWAYS, 100 ERROR_FREQUENCY_ALWAYS,
99 ERROR_FREQUENCY_TWO_THIRDS) = range(3) 101 ERROR_FREQUENCY_TWO_THIRDS) = range(3)
100 102
101 # Well-known server tag of the top level 'Google Chrome' folder. 103 # Well-known server tag of the top level 'Google Chrome' folder.
(...skipping 23 matching lines...) Expand all
125 SYNC_TYPE_FIELDS['managed_user_shared_setting'], 127 SYNC_TYPE_FIELDS['managed_user_shared_setting'],
126 MANAGED_USER_SETTING: SYNC_TYPE_FIELDS['managed_user_setting'], 128 MANAGED_USER_SETTING: SYNC_TYPE_FIELDS['managed_user_setting'],
127 MANAGED_USER: SYNC_TYPE_FIELDS['managed_user'], 129 MANAGED_USER: SYNC_TYPE_FIELDS['managed_user'],
128 NIGORI: SYNC_TYPE_FIELDS['nigori'], 130 NIGORI: SYNC_TYPE_FIELDS['nigori'],
129 PASSWORD: SYNC_TYPE_FIELDS['password'], 131 PASSWORD: SYNC_TYPE_FIELDS['password'],
130 PREFERENCE: SYNC_TYPE_FIELDS['preference'], 132 PREFERENCE: SYNC_TYPE_FIELDS['preference'],
131 PRIORITY_PREFERENCE: SYNC_TYPE_FIELDS['priority_preference'], 133 PRIORITY_PREFERENCE: SYNC_TYPE_FIELDS['priority_preference'],
132 SEARCH_ENGINE: SYNC_TYPE_FIELDS['search_engine'], 134 SEARCH_ENGINE: SYNC_TYPE_FIELDS['search_engine'],
133 SESSION: SYNC_TYPE_FIELDS['session'], 135 SESSION: SYNC_TYPE_FIELDS['session'],
134 SYNCED_NOTIFICATION: SYNC_TYPE_FIELDS["synced_notification"], 136 SYNCED_NOTIFICATION: SYNC_TYPE_FIELDS["synced_notification"],
137 SYNCED_NOTIFICATION_APP_INFO:SYNC_TYPE_FIELDS["app_info"],
135 THEME: SYNC_TYPE_FIELDS['theme'], 138 THEME: SYNC_TYPE_FIELDS['theme'],
136 TYPED_URL: SYNC_TYPE_FIELDS['typed_url'], 139 TYPED_URL: SYNC_TYPE_FIELDS['typed_url'],
137 } 140 }
138 141
139 # The parent ID used to indicate a top-level node. 142 # The parent ID used to indicate a top-level node.
140 ROOT_ID = '0' 143 ROOT_ID = '0'
141 144
142 # Unix time epoch +1 day in struct_time format. The tuple corresponds to 145 # Unix time epoch +1 day in struct_time format. The tuple corresponds to
143 # UTC Thursday Jan 2 1970, 00:00:00, non-dst. 146 # UTC Thursday Jan 2 1970, 00:00:00, non-dst.
144 # We have to add one day after start of epoch, since in timezones with positive 147 # We have to add one day after start of epoch, since in timezones with positive
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 PermanentItem('google_chrome_passwords', name='Passwords', 541 PermanentItem('google_chrome_passwords', name='Passwords',
539 parent_tag=ROOT_ID, sync_type=PASSWORD), 542 parent_tag=ROOT_ID, sync_type=PASSWORD),
540 PermanentItem('google_chrome_preferences', name='Preferences', 543 PermanentItem('google_chrome_preferences', name='Preferences',
541 parent_tag=ROOT_ID, sync_type=PREFERENCE), 544 parent_tag=ROOT_ID, sync_type=PREFERENCE),
542 PermanentItem('google_chrome_priority_preferences', 545 PermanentItem('google_chrome_priority_preferences',
543 name='Priority Preferences', 546 name='Priority Preferences',
544 parent_tag=ROOT_ID, sync_type=PRIORITY_PREFERENCE), 547 parent_tag=ROOT_ID, sync_type=PRIORITY_PREFERENCE),
545 PermanentItem('google_chrome_synced_notifications', 548 PermanentItem('google_chrome_synced_notifications',
546 name='Synced Notifications', 549 name='Synced Notifications',
547 parent_tag=ROOT_ID, sync_type=SYNCED_NOTIFICATION), 550 parent_tag=ROOT_ID, sync_type=SYNCED_NOTIFICATION),
551 PermanentItem('google_chrome_synced_notification_app_info',
552 name='Synced Notification App Info',
553 parent_tag=ROOT_ID, sync_type=SYNCED_NOTIFICATION_APP_INFO),
548 PermanentItem('google_chrome_search_engines', name='Search Engines', 554 PermanentItem('google_chrome_search_engines', name='Search Engines',
549 parent_tag=ROOT_ID, sync_type=SEARCH_ENGINE), 555 parent_tag=ROOT_ID, sync_type=SEARCH_ENGINE),
550 PermanentItem('google_chrome_sessions', name='Sessions', 556 PermanentItem('google_chrome_sessions', name='Sessions',
551 parent_tag=ROOT_ID, sync_type=SESSION), 557 parent_tag=ROOT_ID, sync_type=SESSION),
552 PermanentItem('google_chrome_themes', name='Themes', 558 PermanentItem('google_chrome_themes', name='Themes',
553 parent_tag=ROOT_ID, sync_type=THEME), 559 parent_tag=ROOT_ID, sync_type=THEME),
554 PermanentItem('google_chrome_typed_urls', name='Typed URLs', 560 PermanentItem('google_chrome_typed_urls', name='Typed URLs',
555 parent_tag=ROOT_ID, sync_type=TYPED_URL), 561 parent_tag=ROOT_ID, sync_type=TYPED_URL),
556 PermanentItem('google_chrome_dictionary', name='Dictionary', 562 PermanentItem('google_chrome_dictionary', name='Dictionary',
557 parent_tag=ROOT_ID, sync_type=DICTIONARY), 563 parent_tag=ROOT_ID, sync_type=DICTIONARY),
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 coalesced.key = unique_id 1223 coalesced.key = unique_id
1218 1224
1219 specifics = sync_pb2.EntitySpecifics() 1225 specifics = sync_pb2.EntitySpecifics()
1220 notification_specifics = \ 1226 notification_specifics = \
1221 synced_notification_specifics_pb2.SyncedNotificationSpecifics() 1227 synced_notification_specifics_pb2.SyncedNotificationSpecifics()
1222 notification_specifics.coalesced_notification.CopyFrom(coalesced) 1228 notification_specifics.coalesced_notification.CopyFrom(coalesced)
1223 specifics.synced_notification.CopyFrom(notification_specifics) 1229 specifics.synced_notification.CopyFrom(notification_specifics)
1224 1230
1225 return specifics 1231 return specifics
1226 1232
1227
1228 def _CreateSyncedNotificationClientTag(self, key): 1233 def _CreateSyncedNotificationClientTag(self, key):
1229 """Create the client_defined_unique_tag value for a SyncedNotification. 1234 """Create the client_defined_unique_tag value for a SyncedNotification.
1230 1235
1231 Args: 1236 Args:
1232 key: The entity used to create the client tag. 1237 key: The entity used to create the client tag.
1233 1238
1234 Returns: 1239 Returns:
1235 The string value of the to be used as the client_defined_unique_tag. 1240 The string value of the to be used as the client_defined_unique_tag.
1236 """ 1241 """
1237 serialized_type = sync_pb2.EntitySpecifics() 1242 serialized_type = sync_pb2.EntitySpecifics()
1238 specifics = synced_notification_specifics_pb2.SyncedNotificationSpecifics() 1243 specifics = synced_notification_specifics_pb2.SyncedNotificationSpecifics()
1239 serialized_type.synced_notification.CopyFrom(specifics) 1244 serialized_type.synced_notification.CopyFrom(specifics)
1240 hash_input = serialized_type.SerializeToString() + key 1245 hash_input = serialized_type.SerializeToString() + key
1241 return base64.b64encode(hashlib.sha1(hash_input).digest()) 1246 return base64.b64encode(hashlib.sha1(hash_input).digest())
1242 1247
1248 def AddSyncedNotificationAppInfo(self, app_info):
1249 """Adds an app info struct to the server data.
1250
1251 The notification will be delivered to the client on the next GetUpdates
1252 call.
1253
1254 Args:
1255 app_info: A serialized AppInfo.
1256
1257 Returns:
1258 The string representation of the added SyncEntity.
1259
1260 Raises:
1261 ClientNotConnectedError: if the client has not yet connected to this
1262 server
1263 """
1264 # A unique string used wherever a unique ID for this notification is
1265 # required.
1266 unique_notification_id = str(uuid.uuid4())
1267
1268 specifics = self._AppInfoEntitySpecifics(
1269 unique_notification_id, app_info)
1270
1271 # Create the root SyncEntity representing a single app info protobuf.
1272 entity = sync_pb2.SyncEntity()
1273 entity.specifics.CopyFrom(specifics)
1274 entity.parent_id_string = self._ServerTagToId(
1275 'google_chrome_synced_notifications_app_info')
1276 entity.name = 'App info added for testing'
1277 entity.server_defined_unique_tag = unique_notification_id
1278
1279 # Set the version to one more than the greatest version number already seen.
1280 entries = sorted(self._entries.values(), key=operator.attrgetter('version'))
1281 if len(entries) < 1:
1282 raise ClientNotConnectedError
1283 entity.version = entries[-1].version + 1
1284
1285 entity.client_defined_unique_tag = entity.id_string
1286 entity.id_string = entity.id_string
1287
1288 self._entries[entity.id_string] = copy.deepcopy(entity)
1289
1290 return google.protobuf.text_format.MessageToString(entity)
1291
1243 1292
1244 class TestServer(object): 1293 class TestServer(object):
1245 """An object to handle requests for one (and only one) Chrome Sync account. 1294 """An object to handle requests for one (and only one) Chrome Sync account.
1246 1295
1247 TestServer consumes the sync command messages that are the outermost 1296 TestServer consumes the sync command messages that are the outermost
1248 layers of the protocol, performs the corresponding actions on its 1297 layers of the protocol, performs the corresponding actions on its
1249 SyncDataModel, and constructs an appropriate response message. 1298 SyncDataModel, and constructs an appropriate response message.
1250 """ 1299 """
1251 1300
1252 def __init__(self): 1301 def __init__(self):
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 1690
1642 Args: 1691 Args:
1643 sessions_commit_delay_seconds: The desired sync delay time for sessions. 1692 sessions_commit_delay_seconds: The desired sync delay time for sessions.
1644 """ 1693 """
1645 if not self._client_command: 1694 if not self._client_command:
1646 self._client_command = client_commands_pb2.ClientCommand() 1695 self._client_command = client_commands_pb2.ClientCommand()
1647 1696
1648 self._client_command.sessions_commit_delay_seconds = \ 1697 self._client_command.sessions_commit_delay_seconds = \
1649 sessions_commit_delay_seconds 1698 sessions_commit_delay_seconds
1650 return self._client_command 1699 return self._client_command
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698