| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file defines the "sync API", an interface to the syncer | 5 // This file defines the "sync API", an interface to the syncer |
| 6 // backend that exposes (1) the core functionality of maintaining a consistent | 6 // backend that exposes (1) the core functionality of maintaining a consistent |
| 7 // local snapshot of a hierarchical object set; (2) a means to transactionally | 7 // local snapshot of a hierarchical object set; (2) a means to transactionally |
| 8 // access and modify those objects; (3) a means to control client/server | 8 // access and modify those objects; (3) a means to control client/server |
| 9 // synchronization tasks, namely: pushing local object modifications to a | 9 // synchronization tasks, namely: pushing local object modifications to a |
| 10 // server, pulling nonlocal object modifications from a server to this client, | 10 // server, pulling nonlocal object modifications from a server to this client, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 // A UserShare encapsulates the syncable pieces that represent an authenticated | 101 // A UserShare encapsulates the syncable pieces that represent an authenticated |
| 102 // user and their data (share). | 102 // user and their data (share). |
| 103 // This encompasses all pieces required to build transaction objects on the | 103 // This encompasses all pieces required to build transaction objects on the |
| 104 // syncable share. | 104 // syncable share. |
| 105 struct UserShare { | 105 struct UserShare { |
| 106 // The DirectoryManager itself, which is the parent of Transactions and can | 106 // The DirectoryManager itself, which is the parent of Transactions and can |
| 107 // be shared across multiple threads (unlike Directory). | 107 // be shared across multiple threads (unlike Directory). |
| 108 scoped_ptr<syncable::DirectoryManager> dir_manager; | 108 scoped_ptr<syncable::DirectoryManager> dir_manager; |
| 109 | 109 |
| 110 // The username of the sync user. This is empty until we have performed at | 110 // The username of the sync user. |
| 111 // least one successful GAIA authentication with this username, which means | 111 std::string name; |
| 112 // on first-run it is empty until an AUTH_SUCCEEDED event and on future runs | 112 }; |
| 113 // it is set as soon as the client instructs us to authenticate for the last | 113 |
| 114 // known valid user (AuthenticateForLastKnownUser()). | 114 // Contains everything needed to talk to and identify a user account. |
| 115 std::string authenticated_name; | 115 struct SyncCredentials { |
| 116 std::string email; |
| 117 std::string sync_token; |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 // A valid BaseNode will never have an ID of zero. | 120 // A valid BaseNode will never have an ID of zero. |
| 119 static const int64 kInvalidId = 0; | 121 static const int64 kInvalidId = 0; |
| 120 | 122 |
| 121 // BaseNode wraps syncable::Entry, and corresponds to a single object's state. | 123 // BaseNode wraps syncable::Entry, and corresponds to a single object's state. |
| 122 // This, like syncable::Entry, is intended for use on the stack. A valid | 124 // This, like syncable::Entry, is intended for use on the stack. A valid |
| 123 // transaction is necessary to create a BaseNode or any of its children. | 125 // transaction is necessary to create a BaseNode or any of its children. |
| 124 // Unlike syncable::Entry, a sync API BaseNode is identified primarily by its | 126 // Unlike syncable::Entry, a sync API BaseNode is identified primarily by its |
| 125 // int64 metahandle, which we call an ID here. | 127 // int64 metahandle, which we call an ID here. |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 int change_count) = 0; | 664 int change_count) = 0; |
| 663 | 665 |
| 664 // A round-trip sync-cycle took place and the syncer has resolved any | 666 // A round-trip sync-cycle took place and the syncer has resolved any |
| 665 // conflicts that may have arisen. | 667 // conflicts that may have arisen. |
| 666 virtual void OnSyncCycleCompleted( | 668 virtual void OnSyncCycleCompleted( |
| 667 const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0; | 669 const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0; |
| 668 | 670 |
| 669 // Called when user interaction may be required due to an auth problem. | 671 // Called when user interaction may be required due to an auth problem. |
| 670 virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0; | 672 virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0; |
| 671 | 673 |
| 674 // Called when a new auth token is provided by the sync server. |
| 675 virtual void OnUpdatedToken(const std::string& token) = 0; |
| 676 |
| 672 // Called when user interaction is required to obtain a valid passphrase. | 677 // Called when user interaction is required to obtain a valid passphrase. |
| 673 virtual void OnPassphraseRequired() = 0; | 678 virtual void OnPassphraseRequired() = 0; |
| 674 | 679 |
| 675 // Called when the passphrase provided by the user has been accepted and is | 680 // Called when the passphrase provided by the user has been accepted and is |
| 676 // now used to encrypt sync data. |bootstrap_token| is an opaque base64 | 681 // now used to encrypt sync data. |bootstrap_token| is an opaque base64 |
| 677 // encoded representation of the key generated by the accepted passphrase, | 682 // encoded representation of the key generated by the accepted passphrase, |
| 678 // and is provided to the observer for persistence purposes and use in a | 683 // and is provided to the observer for persistence purposes and use in a |
| 679 // future initialization of sync (e.g. after restart). | 684 // future initialization of sync (e.g. after restart). |
| 680 virtual void OnPassphraseAccepted(const std::string& bootstrap_token) = 0; | 685 virtual void OnPassphraseAccepted(const std::string& bootstrap_token) = 0; |
| 681 | 686 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 708 SyncManager(); | 713 SyncManager(); |
| 709 virtual ~SyncManager(); | 714 virtual ~SyncManager(); |
| 710 | 715 |
| 711 // Initialize the sync manager. |database_location| specifies the path of | 716 // Initialize the sync manager. |database_location| specifies the path of |
| 712 // the directory in which to locate a sqlite repository storing the syncer | 717 // the directory in which to locate a sqlite repository storing the syncer |
| 713 // backend state. Initialization will open the database, or create it if it | 718 // backend state. Initialization will open the database, or create it if it |
| 714 // does not already exist. Returns false on failure. | 719 // does not already exist. Returns false on failure. |
| 715 // |sync_server_and_path| and |sync_server_port| represent the Chrome sync | 720 // |sync_server_and_path| and |sync_server_port| represent the Chrome sync |
| 716 // server to use, and |use_ssl| specifies whether to communicate securely; | 721 // server to use, and |use_ssl| specifies whether to communicate securely; |
| 717 // the default is false. | 722 // the default is false. |
| 718 // |gaia_service_id| is the service id used for GAIA authentication. If it's | |
| 719 // null then default will be used. | |
| 720 // |post_factory| will be owned internally and used to create | 723 // |post_factory| will be owned internally and used to create |
| 721 // instances of an HttpPostProvider. | 724 // instances of an HttpPostProvider. |
| 722 // |auth_post_factory| will be owned internally and used to create | |
| 723 // instances of an HttpPostProvider for communicating with GAIA. | |
| 724 // TODO(timsteele): It seems like one factory should suffice, but for now to | |
| 725 // avoid having to deal with threading issues since the auth code and syncer | |
| 726 // code live on separate threads that run simultaneously, we just dedicate | |
| 727 // one to each component. Long term we may want to reconsider the HttpBridge | |
| 728 // API to take all the params in one chunk in a threadsafe manner.. which is | |
| 729 // still suboptimal as there will be high contention between the two threads | |
| 730 // on startup; so maybe what we have now is the best solution- it does mirror | |
| 731 // the CURL implementation as each thread creates their own internet handle. | |
| 732 // Investigate. | |
| 733 // |model_safe_worker| ownership is given to the SyncManager. | 725 // |model_safe_worker| ownership is given to the SyncManager. |
| 734 // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent | 726 // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent |
| 735 // HTTP header. Used internally when collecting stats to classify clients. | 727 // HTTP header. Used internally when collecting stats to classify clients. |
| 736 // As a fallback when no cached auth information is available, try to | |
| 737 // bootstrap authentication using |lsid|, if it isn't empty. | |
| 738 // | |
| 739 // |invalidate_last_user_auth_token| makes it so that any auth token | |
| 740 // read from user settings is invalidated. This is used for testing | |
| 741 // code paths related to authentication failures. | |
| 742 // | |
| 743 // |invalidate_xmpp_auth_token| makes it so that any auth token | |
| 744 // used to log into XMPP is invalidated. This is used for testing | |
| 745 // code paths related to authentication failures for XMPP only. | |
| 746 // | |
| 747 // |try_ssltcp_first| indicates that the SSLTCP port (443) is tried before the | 728 // |try_ssltcp_first| indicates that the SSLTCP port (443) is tried before the |
| 748 // the XMPP port (5222) during login. It is used by the sync tests that are | 729 // the XMPP port (5222) during login. It is used by the sync tests that are |
| 749 // run on the chromium builders because port 5222 is blocked. | 730 // run on the chromium builders because port 5222 is blocked. |
| 750 bool Init(const FilePath& database_location, | 731 bool Init(const FilePath& database_location, |
| 751 const char* sync_server_and_path, | 732 const char* sync_server_and_path, |
| 752 int sync_server_port, | 733 int sync_server_port, |
| 753 const char* gaia_service_id, | |
| 754 const char* gaia_source, | |
| 755 bool use_ssl, | 734 bool use_ssl, |
| 756 HttpPostProviderFactory* post_factory, | 735 HttpPostProviderFactory* post_factory, |
| 757 HttpPostProviderFactory* auth_post_factory, | |
| 758 browser_sync::ModelSafeWorkerRegistrar* registrar, | 736 browser_sync::ModelSafeWorkerRegistrar* registrar, |
| 759 bool attempt_last_user_authentication, | |
| 760 bool invalidate_last_user_auth_token, | |
| 761 bool invalidate_xmpp_auth_token, | |
| 762 const char* user_agent, | 737 const char* user_agent, |
| 763 const char* lsid, | 738 const SyncCredentials& credentials, |
| 764 bool use_chrome_async_socket, | 739 bool use_chrome_async_socket, |
| 765 bool try_ssltcp_first, | 740 bool try_ssltcp_first, |
| 766 browser_sync::NotificationMethod notification_method, | 741 browser_sync::NotificationMethod notification_method, |
| 767 const std::string& restored_key_for_bootstrapping); | 742 const std::string& restored_key_for_bootstrapping); |
| 768 | 743 |
| 769 // Returns the username last used for a successful authentication. | 744 // Returns the username last used for a successful authentication. |
| 770 // Returns empty if there is no such username. | 745 // Returns empty if there is no such username. |
| 771 const std::string& GetAuthenticatedUsername(); | 746 const std::string& GetAuthenticatedUsername(); |
| 772 | 747 |
| 773 // Check if the database has been populated with a full "initial" download of | 748 // Check if the database has been populated with a full "initial" download of |
| 774 // sync items for each data type currently present in the routing info. | 749 // sync items for each data type currently present in the routing info. |
| 775 // Prerequisite for calling this is that OnInitializationComplete has been | 750 // Prerequisite for calling this is that OnInitializationComplete has been |
| 776 // called. | 751 // called. |
| 777 bool InitialSyncEndedForAllEnabledTypes(); | 752 bool InitialSyncEndedForAllEnabledTypes(); |
| 778 | 753 |
| 779 // Submit credentials to GAIA for verification. On success, both |username| | 754 // Migrate tokens from user settings DB to the token service. |
| 780 // and the obtained auth token are persisted on disk for future re-use. | 755 void MigrateTokens(); |
| 781 // If authentication fails, OnAuthProblem is called on our Observer. | 756 |
| 782 // The Observer may, in turn, decide to try again with new | 757 // Update tokens that we're using in Sync. Email must stay the same. |
| 783 // credentials. Calling this method again is the appropriate course of action | 758 void UpdateCredentials(const SyncCredentials& credentials); |
| 784 // to "retry". | |
| 785 // |username|, |password|, and |captcha| are owned by the caller. | |
| 786 void Authenticate(const char* username, const char* password, | |
| 787 const char* captcha); | |
| 788 | 759 |
| 789 // Start the SyncerThread. | 760 // Start the SyncerThread. |
| 790 void StartSyncing(); | 761 void StartSyncing(); |
| 791 | 762 |
| 792 // Attempt to set the passphrase. If the passphrase is valid, | 763 // Attempt to set the passphrase. If the passphrase is valid, |
| 793 // OnPassphraseAccepted will be fired to notify the ProfileSyncService and the | 764 // OnPassphraseAccepted will be fired to notify the ProfileSyncService and the |
| 794 // syncer will be nudged so that any update that was waiting for this | 765 // syncer will be nudged so that any update that was waiting for this |
| 795 // passphrase gets applied as soon as possible. | 766 // passphrase gets applied as soon as possible. |
| 796 // If the passphrase in invalid, OnPassphraseRequired will be fired. | 767 // If the passphrase in invalid, OnPassphraseRequired will be fired. |
| 797 // Calling this metdod again is the appropriate course of action to "retry" | 768 // Calling this metdod again is the appropriate course of action to "retry" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 // This allows actual HttpPostProvider subclass implementations to be | 900 // This allows actual HttpPostProvider subclass implementations to be |
| 930 // reference counted, which is useful if a particular implementation uses | 901 // reference counted, which is useful if a particular implementation uses |
| 931 // multiple threads to serve network requests. | 902 // multiple threads to serve network requests. |
| 932 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 903 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
| 933 virtual ~HttpPostProviderFactory() { } | 904 virtual ~HttpPostProviderFactory() { } |
| 934 }; | 905 }; |
| 935 | 906 |
| 936 } // namespace sync_api | 907 } // namespace sync_api |
| 937 | 908 |
| 938 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 909 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
| OLD | NEW |