| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #include "chrome/browser/sync/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
| 55 | 55 |
| 56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
| 57 #pragma comment(lib, "iphlpapi.lib") | 57 #pragma comment(lib, "iphlpapi.lib") |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 using browser_sync::AllStatus; | 60 using browser_sync::AllStatus; |
| 61 using browser_sync::AllStatusEvent; | 61 using browser_sync::AllStatusEvent; |
| 62 using browser_sync::AuthWatcher; | 62 using browser_sync::AuthWatcher; |
| 63 using browser_sync::AuthWatcherEvent; | 63 using browser_sync::AuthWatcherEvent; |
| 64 using browser_sync::ModelSafeWorker; |
| 65 using browser_sync::ModelSafeWorkerRegistrar; |
| 64 using browser_sync::Syncer; | 66 using browser_sync::Syncer; |
| 65 using browser_sync::SyncerEvent; | 67 using browser_sync::SyncerEvent; |
| 66 using browser_sync::SyncerThread; | 68 using browser_sync::SyncerThread; |
| 67 using browser_sync::UserSettings; | 69 using browser_sync::UserSettings; |
| 68 using browser_sync::TalkMediator; | 70 using browser_sync::TalkMediator; |
| 69 using browser_sync::TalkMediatorImpl; | 71 using browser_sync::TalkMediatorImpl; |
| 70 using browser_sync::sessions::SyncSessionContext; | 72 using browser_sync::sessions::SyncSessionContext; |
| 71 using std::list; | 73 using std::list; |
| 72 using std::hex; | 74 using std::hex; |
| 73 using std::string; | 75 using std::string; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 #endif | 180 #endif |
| 179 LOG(INFO) << "The address watch thread has stopped"; | 181 LOG(INFO) << "The address watch thread has stopped"; |
| 180 } | 182 } |
| 181 | 183 |
| 182 private: | 184 private: |
| 183 AddressWatchTaskParams* const params_; | 185 AddressWatchTaskParams* const params_; |
| 184 DISALLOW_COPY_AND_ASSIGN(AddressWatchTask); | 186 DISALLOW_COPY_AND_ASSIGN(AddressWatchTask); |
| 185 }; | 187 }; |
| 186 | 188 |
| 187 namespace sync_api { | 189 namespace sync_api { |
| 188 class ModelSafeWorkerBridge; | |
| 189 | 190 |
| 190 static const FilePath::CharType kBookmarkSyncUserSettingsDatabase[] = | 191 static const FilePath::CharType kBookmarkSyncUserSettingsDatabase[] = |
| 191 FILE_PATH_LITERAL("BookmarkSyncSettings.sqlite3"); | 192 FILE_PATH_LITERAL("BookmarkSyncSettings.sqlite3"); |
| 192 static const char kDefaultNameForNewNodes[] = " "; | 193 static const char kDefaultNameForNewNodes[] = " "; |
| 193 | 194 |
| 194 // The list of names which are reserved for use by the server. | 195 // The list of names which are reserved for use by the server. |
| 195 static const char* kForbiddenServerNames[] = { "", ".", ".." }; | 196 static const char* kForbiddenServerNames[] = { "", ".", ".." }; |
| 196 | 197 |
| 197 ////////////////////////////////////////////////////////////////////////// | 198 ////////////////////////////////////////////////////////////////////////// |
| 198 // Static helper functions. | 199 // Static helper functions. |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 594 } |
| 594 | 595 |
| 595 WriteTransaction::~WriteTransaction() { | 596 WriteTransaction::~WriteTransaction() { |
| 596 delete transaction_; | 597 delete transaction_; |
| 597 } | 598 } |
| 598 | 599 |
| 599 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { | 600 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { |
| 600 return transaction_; | 601 return transaction_; |
| 601 } | 602 } |
| 602 | 603 |
| 603 // An implementation of Visitor that we use to "visit" the | |
| 604 // ModelSafeWorkerInterface provided by a client of this API. The object we | |
| 605 // visit is responsible for calling DoWork, which will invoke Run() on it's | |
| 606 // cached work closure. | |
| 607 class ModelSafeWorkerVisitor : public ModelSafeWorkerInterface::Visitor { | |
| 608 public: | |
| 609 explicit ModelSafeWorkerVisitor(Closure* work) : work_(work) { } | |
| 610 virtual ~ModelSafeWorkerVisitor() { } | |
| 611 | |
| 612 // ModelSafeWorkerInterface::Visitor implementation. | |
| 613 virtual void DoWork() { | |
| 614 work_->Run(); | |
| 615 } | |
| 616 | |
| 617 private: | |
| 618 // The work to be done. We run this on DoWork and it cleans itself up | |
| 619 // after it is run. | |
| 620 Closure* work_; | |
| 621 | |
| 622 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerVisitor); | |
| 623 }; | |
| 624 | |
| 625 // This class is declared in the cc file to allow inheritance from sync types. | |
| 626 // The ModelSafeWorkerBridge is a liason between a syncapi-client defined | |
| 627 // ModelSafeWorkerInterface and the actual ModelSafeWorker used by the Syncer | |
| 628 // for the current SyncManager. | |
| 629 class ModelSafeWorkerBridge : public browser_sync::ModelSafeWorker { | |
| 630 public: | |
| 631 // Takes ownership of |worker|. | |
| 632 explicit ModelSafeWorkerBridge(ModelSafeWorkerInterface* worker) | |
| 633 : worker_(worker) { | |
| 634 } | |
| 635 virtual ~ModelSafeWorkerBridge() { } | |
| 636 | |
| 637 // Overriding ModelSafeWorker. | |
| 638 virtual void DoWorkAndWaitUntilDone(Closure* work) { | |
| 639 // When the syncer has work to be done, we forward it to our worker who | |
| 640 // will invoke DoWork on |visitor| when appropriate (from model safe | |
| 641 // thread). | |
| 642 ModelSafeWorkerVisitor visitor(work); | |
| 643 worker_->CallDoWorkFromModelSafeThreadAndWait(&visitor); | |
| 644 } | |
| 645 | |
| 646 private: | |
| 647 // The worker that we can forward work requests to, to ensure the work | |
| 648 // is performed on an appropriate model safe thread. | |
| 649 scoped_ptr<ModelSafeWorkerInterface> worker_; | |
| 650 | |
| 651 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerBridge); | |
| 652 }; | |
| 653 | |
| 654 // A GaiaAuthenticator that uses HttpPostProviders instead of CURL. | 604 // A GaiaAuthenticator that uses HttpPostProviders instead of CURL. |
| 655 class BridgedGaiaAuthenticator : public browser_sync::GaiaAuthenticator { | 605 class BridgedGaiaAuthenticator : public browser_sync::GaiaAuthenticator { |
| 656 public: | 606 public: |
| 657 BridgedGaiaAuthenticator(const string& user_agent, const string& service_id, | 607 BridgedGaiaAuthenticator(const string& user_agent, const string& service_id, |
| 658 const string& gaia_url, | 608 const string& gaia_url, |
| 659 HttpPostProviderFactory* factory) | 609 HttpPostProviderFactory* factory) |
| 660 : GaiaAuthenticator(user_agent, service_id, gaia_url), | 610 : GaiaAuthenticator(user_agent, service_id, gaia_url), |
| 661 gaia_source_(user_agent), post_factory_(factory) { | 611 gaia_source_(user_agent), post_factory_(factory) { |
| 662 } | 612 } |
| 663 | 613 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 ~SyncInternal() { } | 660 ~SyncInternal() { } |
| 711 | 661 |
| 712 bool Init(const FilePath& database_location, | 662 bool Init(const FilePath& database_location, |
| 713 const std::string& sync_server_and_path, | 663 const std::string& sync_server_and_path, |
| 714 int port, | 664 int port, |
| 715 const char* gaia_service_id, | 665 const char* gaia_service_id, |
| 716 const char* gaia_source, | 666 const char* gaia_source, |
| 717 bool use_ssl, | 667 bool use_ssl, |
| 718 HttpPostProviderFactory* post_factory, | 668 HttpPostProviderFactory* post_factory, |
| 719 HttpPostProviderFactory* auth_post_factory, | 669 HttpPostProviderFactory* auth_post_factory, |
| 720 ModelSafeWorkerInterface* model_safe_worker, | 670 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 721 bool attempt_last_user_authentication, | 671 bool attempt_last_user_authentication, |
| 722 const char* user_agent, | 672 const char* user_agent, |
| 723 const std::string& lsid); | 673 const std::string& lsid); |
| 724 | 674 |
| 725 // Tell sync engine to submit credentials to GAIA for verification and start | 675 // Tell sync engine to submit credentials to GAIA for verification and start |
| 726 // the syncing process on success. Successful GAIA authentication will kick | 676 // the syncing process on success. Successful GAIA authentication will kick |
| 727 // off the following chain of events: | 677 // off the following chain of events: |
| 728 // 1. Cause sync engine to open the syncer database. | 678 // 1. Cause sync engine to open the syncer database. |
| 729 // 2. Trigger the AuthWatcher to create a Syncer for the directory and call | 679 // 2. Trigger the AuthWatcher to create a Syncer for the directory and call |
| 730 // SyncerThread::SyncDirectory; the SyncerThread will block until (4). | 680 // SyncerThread::SyncDirectory; the SyncerThread will block until (4). |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 } | 890 } |
| 941 | 891 |
| 942 bool SyncManager::Init(const FilePath& database_location, | 892 bool SyncManager::Init(const FilePath& database_location, |
| 943 const char* sync_server_and_path, | 893 const char* sync_server_and_path, |
| 944 int sync_server_port, | 894 int sync_server_port, |
| 945 const char* gaia_service_id, | 895 const char* gaia_service_id, |
| 946 const char* gaia_source, | 896 const char* gaia_source, |
| 947 bool use_ssl, | 897 bool use_ssl, |
| 948 HttpPostProviderFactory* post_factory, | 898 HttpPostProviderFactory* post_factory, |
| 949 HttpPostProviderFactory* auth_post_factory, | 899 HttpPostProviderFactory* auth_post_factory, |
| 950 ModelSafeWorkerInterface* model_safe_worker, | 900 ModelSafeWorkerRegistrar* registrar, |
| 951 bool attempt_last_user_authentication, | 901 bool attempt_last_user_authentication, |
| 952 const char* user_agent, | 902 const char* user_agent, |
| 953 const char* lsid) { | 903 const char* lsid) { |
| 954 DCHECK(post_factory); | 904 DCHECK(post_factory); |
| 955 | 905 |
| 956 string server_string(sync_server_and_path); | 906 string server_string(sync_server_and_path); |
| 957 return data_->Init(database_location, | 907 return data_->Init(database_location, |
| 958 server_string, | 908 server_string, |
| 959 sync_server_port, | 909 sync_server_port, |
| 960 gaia_service_id, | 910 gaia_service_id, |
| 961 gaia_source, | 911 gaia_source, |
| 962 use_ssl, | 912 use_ssl, |
| 963 post_factory, | 913 post_factory, |
| 964 auth_post_factory, | 914 auth_post_factory, |
| 965 model_safe_worker, | 915 registrar, |
| 966 attempt_last_user_authentication, | 916 attempt_last_user_authentication, |
| 967 user_agent, | 917 user_agent, |
| 968 lsid); | 918 lsid); |
| 969 } | 919 } |
| 970 | 920 |
| 971 void SyncManager::Authenticate(const char* username, const char* password, | 921 void SyncManager::Authenticate(const char* username, const char* password, |
| 972 const char* captcha) { | 922 const char* captcha) { |
| 973 data_->Authenticate(std::string(username), std::string(password), | 923 data_->Authenticate(std::string(username), std::string(password), |
| 974 std::string(captcha)); | 924 std::string(captcha)); |
| 975 } | 925 } |
| 976 | 926 |
| 977 const std::string& SyncManager::GetAuthenticatedUsername() { | 927 const std::string& SyncManager::GetAuthenticatedUsername() { |
| 978 DCHECK(data_); | 928 DCHECK(data_); |
| 979 return data_->username_for_share(); | 929 return data_->username_for_share(); |
| 980 } | 930 } |
| 981 | 931 |
| 982 bool SyncManager::SyncInternal::Init( | 932 bool SyncManager::SyncInternal::Init( |
| 983 const FilePath& database_location, | 933 const FilePath& database_location, |
| 984 const std::string& sync_server_and_path, | 934 const std::string& sync_server_and_path, |
| 985 int port, | 935 int port, |
| 986 const char* gaia_service_id, | 936 const char* gaia_service_id, |
| 987 const char* gaia_source, | 937 const char* gaia_source, |
| 988 bool use_ssl, HttpPostProviderFactory* post_factory, | 938 bool use_ssl, HttpPostProviderFactory* post_factory, |
| 989 HttpPostProviderFactory* auth_post_factory, | 939 HttpPostProviderFactory* auth_post_factory, |
| 990 ModelSafeWorkerInterface* model_safe_worker, | 940 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 991 bool attempt_last_user_authentication, | 941 bool attempt_last_user_authentication, |
| 992 const char* user_agent, | 942 const char* user_agent, |
| 993 const std::string& lsid) { | 943 const std::string& lsid) { |
| 994 | 944 |
| 995 // Set up UserSettings, creating the db if necessary. We need this to | 945 // Set up UserSettings, creating the db if necessary. We need this to |
| 996 // instantiate a URLFactory to give to the Syncer. | 946 // instantiate a URLFactory to give to the Syncer. |
| 997 FilePath settings_db_file = | 947 FilePath settings_db_file = |
| 998 database_location.Append(FilePath(kBookmarkSyncUserSettingsDatabase)); | 948 database_location.Append(FilePath(kBookmarkSyncUserSettingsDatabase)); |
| 999 user_settings_.reset(new UserSettings()); | 949 user_settings_.reset(new UserSettings()); |
| 1000 if (!user_settings_->Init(settings_db_file)) | 950 if (!user_settings_->Init(settings_db_file)) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 user_settings_.get(), | 1002 user_settings_.get(), |
| 1053 gaia_auth, | 1003 gaia_auth, |
| 1054 talk_mediator()); | 1004 talk_mediator()); |
| 1055 | 1005 |
| 1056 talk_mediator()->WatchAuthWatcher(auth_watcher()); | 1006 talk_mediator()->WatchAuthWatcher(auth_watcher()); |
| 1057 allstatus()->WatchAuthWatcher(auth_watcher()); | 1007 allstatus()->WatchAuthWatcher(auth_watcher()); |
| 1058 authwatcher_hookup_.reset(NewEventListenerHookup(auth_watcher_->channel(), | 1008 authwatcher_hookup_.reset(NewEventListenerHookup(auth_watcher_->channel(), |
| 1059 this, &SyncInternal::HandleAuthWatcherEvent)); | 1009 this, &SyncInternal::HandleAuthWatcherEvent)); |
| 1060 | 1010 |
| 1061 // Build a SyncSessionContext and store the worker in it. | 1011 // Build a SyncSessionContext and store the worker in it. |
| 1062 // We set up both sides of the "bridge" here, with the ModelSafeWorkerBridge | |
| 1063 // on the Syncer side, and |model_safe_worker| on the API client side. | |
| 1064 ModelSafeWorkerBridge* worker = new ModelSafeWorkerBridge(model_safe_worker); | |
| 1065 SyncSessionContext* context = new SyncSessionContext( | 1012 SyncSessionContext* context = new SyncSessionContext( |
| 1066 connection_manager_.get(), dir_manager(), worker); | 1013 connection_manager_.get(), dir_manager(), model_safe_worker_registrar); |
| 1067 | 1014 |
| 1068 // The SyncerThread takes ownership of |context|. | 1015 // The SyncerThread takes ownership of |context|. |
| 1069 syncer_thread_ = new SyncerThread(context, &allstatus_); | 1016 syncer_thread_ = new SyncerThread(context, &allstatus_); |
| 1070 syncer_thread()->WatchTalkMediator(talk_mediator()); | 1017 syncer_thread()->WatchTalkMediator(talk_mediator()); |
| 1071 allstatus()->WatchSyncerThread(syncer_thread()); | 1018 allstatus()->WatchSyncerThread(syncer_thread()); |
| 1072 | 1019 |
| 1073 syncer_thread()->Start(); // Start the syncer thread. This won't actually | 1020 syncer_thread()->Start(); // Start the syncer thread. This won't actually |
| 1074 // result in any syncing until at least the | 1021 // result in any syncing until at least the |
| 1075 // DirectoryManager broadcasts the OPENED event, | 1022 // DirectoryManager broadcasts the OPENED event, |
| 1076 // and a valid server connection is detected. | 1023 // and a valid server connection is detected. |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 BaseTransaction::~BaseTransaction() { | 1545 BaseTransaction::~BaseTransaction() { |
| 1599 delete lookup_; | 1546 delete lookup_; |
| 1600 } | 1547 } |
| 1601 | 1548 |
| 1602 UserShare* SyncManager::GetUserShare() const { | 1549 UserShare* SyncManager::GetUserShare() const { |
| 1603 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 1550 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
| 1604 return data_->GetUserShare(); | 1551 return data_->GetUserShare(); |
| 1605 } | 1552 } |
| 1606 | 1553 |
| 1607 } // namespace sync_api | 1554 } // namespace sync_api |
| OLD | NEW |