| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 585 |
| 586 TestServer consumes the sync command messages that are the outermost | 586 TestServer consumes the sync command messages that are the outermost |
| 587 layers of the protocol, performs the corresponding actions on its | 587 layers of the protocol, performs the corresponding actions on its |
| 588 SyncDataModel, and constructs an appropropriate response message. | 588 SyncDataModel, and constructs an appropropriate response message. |
| 589 """ | 589 """ |
| 590 | 590 |
| 591 def __init__(self): | 591 def __init__(self): |
| 592 # The implementation supports exactly one account; its state is here. | 592 # The implementation supports exactly one account; its state is here. |
| 593 self.account = SyncDataModel() | 593 self.account = SyncDataModel() |
| 594 self.account_lock = threading.Lock() | 594 self.account_lock = threading.Lock() |
| 595 self.account_user_email = 'syncjuser@chromium.org' |
| 596 |
| 597 def HandleConfigure(self, config): |
| 598 """Handles various test configuration parameters sent from the client. |
| 599 |
| 600 Args: |
| 601 config: Dictionary of configuration parameters. |
| 602 Returns: |
| 603 True if configuration was successful. |
| 604 """ |
| 605 if config.has_key('user_email'): |
| 606 self.account_user_email = config['user_email'][0] |
| 607 return True |
| 595 | 608 |
| 596 def HandleCommand(self, raw_request): | 609 def HandleCommand(self, raw_request): |
| 597 """Decode and handle a sync command from a raw input of bytes. | 610 """Decode and handle a sync command from a raw input of bytes. |
| 598 | 611 |
| 599 This is the main entry point for this class. It is safe to call this | 612 This is the main entry point for this class. It is safe to call this |
| 600 method from multiple threads. | 613 method from multiple threads. |
| 601 | 614 |
| 602 Args: | 615 Args: |
| 603 raw_request: An iterable byte sequence to be interpreted as a sync | 616 raw_request: An iterable byte sequence to be interpreted as a sync |
| 604 protocol command. | 617 protocol command. |
| 605 Returns: | 618 Returns: |
| 606 A tuple (response_code, raw_response); the first value is an HTTP | 619 A tuple (response_code, raw_response); the first value is an HTTP |
| 607 result code, while the second value is a string of bytes which is the | 620 result code, while the second value is a string of bytes which is the |
| 608 serialized reply to the command. | 621 serialized reply to the command. |
| 609 """ | 622 """ |
| 610 self.account_lock.acquire() | 623 self.account_lock.acquire() |
| 611 try: | 624 try: |
| 612 request = sync_pb2.ClientToServerMessage() | 625 request = sync_pb2.ClientToServerMessage() |
| 613 request.MergeFromString(raw_request) | 626 request.MergeFromString(raw_request) |
| 614 contents = request.message_contents | 627 contents = request.message_contents |
| 615 | 628 |
| 616 response = sync_pb2.ClientToServerResponse() | 629 response = sync_pb2.ClientToServerResponse() |
| 617 response.error_code = sync_pb2.ClientToServerResponse.SUCCESS | 630 response.error_code = sync_pb2.ClientToServerResponse.SUCCESS |
| 618 response.store_birthday = self.account.store_birthday | 631 response.store_birthday = self.account.store_birthday |
| 619 | 632 |
| 620 if contents == sync_pb2.ClientToServerMessage.AUTHENTICATE: | 633 if contents == sync_pb2.ClientToServerMessage.AUTHENTICATE: |
| 621 print 'Authenticate' | 634 print 'Authenticate' |
| 622 # We accept any authentication token, and support only one account. | 635 # We accept any authentication token, and support only one account. |
| 623 # TODO(nick): Mock out the GAIA authentication as well; hook up here. | 636 # TODO(nick): Mock out the GAIA authentication as well; hook up here. |
| 624 response.authenticate.user.email = 'syncjuser@chromium' | 637 response.authenticate.user.email = self.account_user_email |
| 625 response.authenticate.user.display_name = 'Sync J User' | 638 response.authenticate.user.display_name = 'Sync J User' |
| 626 elif contents == sync_pb2.ClientToServerMessage.COMMIT: | 639 elif contents == sync_pb2.ClientToServerMessage.COMMIT: |
| 627 print 'Commit' | 640 print 'Commit' |
| 628 self.HandleCommit(request.commit, response.commit) | 641 self.HandleCommit(request.commit, response.commit) |
| 629 elif contents == sync_pb2.ClientToServerMessage.GET_UPDATES: | 642 elif contents == sync_pb2.ClientToServerMessage.GET_UPDATES: |
| 630 print ('GetUpdates from timestamp %d' % | 643 print ('GetUpdates from timestamp %d' % |
| 631 request.get_updates.from_timestamp) | 644 request.get_updates.from_timestamp) |
| 632 self.HandleGetUpdates(request.get_updates, response.get_updates) | 645 self.HandleGetUpdates(request.get_updates, response.get_updates) |
| 633 return (200, response.SerializeToString()) | 646 return (200, response.SerializeToString()) |
| 634 finally: | 647 finally: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 new_timestamp, entries = self.account.GetChangesFromTimestamp( | 705 new_timestamp, entries = self.account.GetChangesFromTimestamp( |
| 693 requested_types, update_request.from_timestamp) | 706 requested_types, update_request.from_timestamp) |
| 694 | 707 |
| 695 # If the client is up to date, we are careful not to set the | 708 # If the client is up to date, we are careful not to set the |
| 696 # new_timestamp field. | 709 # new_timestamp field. |
| 697 if new_timestamp != update_request.from_timestamp: | 710 if new_timestamp != update_request.from_timestamp: |
| 698 update_response.new_timestamp = new_timestamp | 711 update_response.new_timestamp = new_timestamp |
| 699 for e in entries: | 712 for e in entries: |
| 700 reply = update_response.entries.add() | 713 reply = update_response.entries.add() |
| 701 reply.CopyFrom(e) | 714 reply.CopyFrom(e) |
| OLD | NEW |