OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/internal_api/sync_manager.h" | 5 #include "chrome/browser/sync/internal_api/sync_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "chrome/browser/sync/notifier/sync_notifier.h" | 43 #include "chrome/browser/sync/notifier/sync_notifier.h" |
44 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 44 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
45 #include "chrome/browser/sync/protocol/encryption.pb.h" | 45 #include "chrome/browser/sync/protocol/encryption.pb.h" |
46 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 46 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
47 #include "chrome/browser/sync/protocol/sync.pb.h" | 47 #include "chrome/browser/sync/protocol/sync.pb.h" |
48 #include "chrome/browser/sync/syncable/directory_change_delegate.h" | 48 #include "chrome/browser/sync/syncable/directory_change_delegate.h" |
49 #include "chrome/browser/sync/syncable/model_type.h" | 49 #include "chrome/browser/sync/syncable/model_type.h" |
50 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 50 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
51 #include "chrome/browser/sync/syncable/syncable.h" | 51 #include "chrome/browser/sync/syncable/syncable.h" |
52 #include "chrome/browser/sync/util/cryptographer.h" | 52 #include "chrome/browser/sync/util/cryptographer.h" |
53 #include "chrome/browser/sync/util/get_session_name_task.h" | 53 #include "chrome/browser/sync/util/get_session_name.h" |
54 #include "chrome/browser/sync/util/time.h" | 54 #include "chrome/browser/sync/util/time.h" |
55 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
56 #include "chrome/common/chrome_version_info.h" | 56 #include "chrome/common/chrome_version_info.h" |
57 #include "content/public/browser/browser_thread.h" | |
58 #include "net/base/network_change_notifier.h" | 57 #include "net/base/network_change_notifier.h" |
59 | 58 |
60 using std::string; | 59 using std::string; |
61 | 60 |
62 using base::TimeDelta; | 61 using base::TimeDelta; |
63 using browser_sync::AllStatus; | 62 using browser_sync::AllStatus; |
64 using browser_sync::Cryptographer; | 63 using browser_sync::Cryptographer; |
65 using browser_sync::Encryptor; | 64 using browser_sync::Encryptor; |
66 using browser_sync::JsArgList; | 65 using browser_sync::JsArgList; |
67 using browser_sync::JsBackend; | 66 using browser_sync::JsBackend; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 179 |
181 virtual ~SyncInternal() { | 180 virtual ~SyncInternal() { |
182 CHECK(!initialized_); | 181 CHECK(!initialized_); |
183 } | 182 } |
184 | 183 |
185 bool Init(const FilePath& database_location, | 184 bool Init(const FilePath& database_location, |
186 const WeakHandle<JsEventHandler>& event_handler, | 185 const WeakHandle<JsEventHandler>& event_handler, |
187 const std::string& sync_server_and_path, | 186 const std::string& sync_server_and_path, |
188 int port, | 187 int port, |
189 bool use_ssl, | 188 bool use_ssl, |
| 189 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
190 HttpPostProviderFactory* post_factory, | 190 HttpPostProviderFactory* post_factory, |
191 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 191 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
192 browser_sync::ExtensionsActivityMonitor* | 192 browser_sync::ExtensionsActivityMonitor* |
193 extensions_activity_monitor, | 193 extensions_activity_monitor, |
194 ChangeDelegate* change_delegate, | 194 ChangeDelegate* change_delegate, |
195 const std::string& user_agent, | 195 const std::string& user_agent, |
196 const SyncCredentials& credentials, | 196 const SyncCredentials& credentials, |
197 sync_notifier::SyncNotifier* sync_notifier, | 197 sync_notifier::SyncNotifier* sync_notifier, |
198 const std::string& restored_key_for_bootstrapping, | 198 const std::string& restored_key_for_bootstrapping, |
199 bool setup_for_test_mode, | 199 bool setup_for_test_mode, |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // HandleCalculateChangesChangeEventFromSyncApi(), which can be | 526 // HandleCalculateChangesChangeEventFromSyncApi(), which can be |
527 // called from any thread. Valid only between between calls to | 527 // called from any thread. Valid only between between calls to |
528 // Init() and Shutdown(). | 528 // Init() and Shutdown(). |
529 // | 529 // |
530 // TODO(akalin): Ideally, we wouldn't need to store this; instead, | 530 // TODO(akalin): Ideally, we wouldn't need to store this; instead, |
531 // we'd have another worker class which implements | 531 // we'd have another worker class which implements |
532 // HandleCalculateChangesChangeEventFromSyncApi() and we'd pass it a | 532 // HandleCalculateChangesChangeEventFromSyncApi() and we'd pass it a |
533 // WeakHandle when we construct it. | 533 // WeakHandle when we construct it. |
534 WeakHandle<SyncInternal> weak_handle_this_; | 534 WeakHandle<SyncInternal> weak_handle_this_; |
535 | 535 |
| 536 // |blocking_task_runner| is a TaskRunner to be used for tasks that |
| 537 // may block on disk I/O. |
| 538 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 539 |
536 // We give a handle to share_ to clients of the API for use when constructing | 540 // We give a handle to share_ to clients of the API for use when constructing |
537 // any transaction type. | 541 // any transaction type. |
538 UserShare share_; | 542 UserShare share_; |
539 | 543 |
540 // This can be called from any thread, but only between calls to | 544 // This can be called from any thread, but only between calls to |
541 // OpenDirectory() and ShutdownOnSyncThread(). | 545 // OpenDirectory() and ShutdownOnSyncThread(). |
542 browser_sync::WeakHandle<SyncManager::ChangeObserver> change_observer_; | 546 browser_sync::WeakHandle<SyncManager::ChangeObserver> change_observer_; |
543 | 547 |
544 ObserverList<SyncManager::Observer> observers_; | 548 ObserverList<SyncManager::Observer> observers_; |
545 | 549 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 718 |
715 SyncManager::Status::~Status() { | 719 SyncManager::Status::~Status() { |
716 } | 720 } |
717 | 721 |
718 bool SyncManager::Init( | 722 bool SyncManager::Init( |
719 const FilePath& database_location, | 723 const FilePath& database_location, |
720 const WeakHandle<JsEventHandler>& event_handler, | 724 const WeakHandle<JsEventHandler>& event_handler, |
721 const std::string& sync_server_and_path, | 725 const std::string& sync_server_and_path, |
722 int sync_server_port, | 726 int sync_server_port, |
723 bool use_ssl, | 727 bool use_ssl, |
| 728 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
724 HttpPostProviderFactory* post_factory, | 729 HttpPostProviderFactory* post_factory, |
725 ModelSafeWorkerRegistrar* registrar, | 730 ModelSafeWorkerRegistrar* registrar, |
726 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor, | 731 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor, |
727 ChangeDelegate* change_delegate, | 732 ChangeDelegate* change_delegate, |
728 const std::string& user_agent, | 733 const std::string& user_agent, |
729 const SyncCredentials& credentials, | 734 const SyncCredentials& credentials, |
730 sync_notifier::SyncNotifier* sync_notifier, | 735 sync_notifier::SyncNotifier* sync_notifier, |
731 const std::string& restored_key_for_bootstrapping, | 736 const std::string& restored_key_for_bootstrapping, |
732 bool setup_for_test_mode, | 737 bool setup_for_test_mode, |
733 Encryptor* encryptor, | 738 Encryptor* encryptor, |
734 UnrecoverableErrorHandler* unrecoverable_error_handler, | 739 UnrecoverableErrorHandler* unrecoverable_error_handler, |
735 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 740 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
736 DCHECK(thread_checker_.CalledOnValidThread()); | 741 DCHECK(thread_checker_.CalledOnValidThread()); |
737 DCHECK(post_factory); | 742 DCHECK(post_factory); |
738 DVLOG(1) << "SyncManager starting Init..."; | 743 DVLOG(1) << "SyncManager starting Init..."; |
739 string server_string(sync_server_and_path); | 744 string server_string(sync_server_and_path); |
740 return data_->Init(database_location, | 745 return data_->Init(database_location, |
741 event_handler, | 746 event_handler, |
742 server_string, | 747 server_string, |
743 sync_server_port, | 748 sync_server_port, |
744 use_ssl, | 749 use_ssl, |
| 750 blocking_task_runner, |
745 post_factory, | 751 post_factory, |
746 registrar, | 752 registrar, |
747 extensions_activity_monitor, | 753 extensions_activity_monitor, |
748 change_delegate, | 754 change_delegate, |
749 user_agent, | 755 user_agent, |
750 credentials, | 756 credentials, |
751 sync_notifier, | 757 sync_notifier, |
752 restored_key_for_bootstrapping, | 758 restored_key_for_bootstrapping, |
753 setup_for_test_mode, | 759 setup_for_test_mode, |
754 encryptor, | 760 encryptor, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 data_->scheduler()->Start( | 857 data_->scheduler()->Start( |
852 browser_sync::SyncScheduler::CONFIGURATION_MODE, callback); | 858 browser_sync::SyncScheduler::CONFIGURATION_MODE, callback); |
853 } | 859 } |
854 | 860 |
855 bool SyncManager::SyncInternal::Init( | 861 bool SyncManager::SyncInternal::Init( |
856 const FilePath& database_location, | 862 const FilePath& database_location, |
857 const WeakHandle<JsEventHandler>& event_handler, | 863 const WeakHandle<JsEventHandler>& event_handler, |
858 const std::string& sync_server_and_path, | 864 const std::string& sync_server_and_path, |
859 int port, | 865 int port, |
860 bool use_ssl, | 866 bool use_ssl, |
| 867 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
861 HttpPostProviderFactory* post_factory, | 868 HttpPostProviderFactory* post_factory, |
862 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 869 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
863 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor, | 870 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor, |
864 ChangeDelegate* change_delegate, | 871 ChangeDelegate* change_delegate, |
865 const std::string& user_agent, | 872 const std::string& user_agent, |
866 const SyncCredentials& credentials, | 873 const SyncCredentials& credentials, |
867 sync_notifier::SyncNotifier* sync_notifier, | 874 sync_notifier::SyncNotifier* sync_notifier, |
868 const std::string& restored_key_for_bootstrapping, | 875 const std::string& restored_key_for_bootstrapping, |
869 bool setup_for_test_mode, | 876 bool setup_for_test_mode, |
870 Encryptor* encryptor, | 877 Encryptor* encryptor, |
871 UnrecoverableErrorHandler* unrecoverable_error_handler, | 878 UnrecoverableErrorHandler* unrecoverable_error_handler, |
872 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 879 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
873 CHECK(!initialized_); | 880 CHECK(!initialized_); |
874 | 881 |
875 DCHECK(thread_checker_.CalledOnValidThread()); | 882 DCHECK(thread_checker_.CalledOnValidThread()); |
876 | 883 |
877 DVLOG(1) << "Starting SyncInternal initialization."; | 884 DVLOG(1) << "Starting SyncInternal initialization."; |
878 | 885 |
879 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 886 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
880 | 887 |
| 888 blocking_task_runner_ = blocking_task_runner; |
| 889 |
881 registrar_ = model_safe_worker_registrar; | 890 registrar_ = model_safe_worker_registrar; |
882 change_delegate_ = change_delegate; | 891 change_delegate_ = change_delegate; |
883 setup_for_test_mode_ = setup_for_test_mode; | 892 setup_for_test_mode_ = setup_for_test_mode; |
884 | 893 |
885 sync_notifier_.reset(sync_notifier); | 894 sync_notifier_.reset(sync_notifier); |
886 | 895 |
887 AddObserver(&js_sync_manager_observer_); | 896 AddObserver(&js_sync_manager_observer_); |
888 SetJsEventHandler(event_handler); | 897 SetJsEventHandler(event_handler); |
889 | 898 |
890 AddObserver(&debug_info_event_listener_); | 899 AddObserver(&debug_info_event_listener_); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 trans.GetWrappedTrans()->OnUnrecoverableError(FROM_HERE, | 982 trans.GetWrappedTrans()->OnUnrecoverableError(FROM_HERE, |
974 "Simulating unrecoverable error for testing purpose."); | 983 "Simulating unrecoverable error for testing purpose."); |
975 } | 984 } |
976 | 985 |
977 return signed_in; | 986 return signed_in; |
978 } | 987 } |
979 | 988 |
980 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( | 989 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( |
981 const base::Callback<void(bool)>& done_callback) { | 990 const base::Callback<void(bool)>& done_callback) { |
982 DCHECK(initialized_); | 991 DCHECK(initialized_); |
983 scoped_refptr<browser_sync::GetSessionNameTask> task = | 992 browser_sync::GetSessionName( |
984 new browser_sync::GetSessionNameTask(base::Bind( | 993 blocking_task_runner_, |
| 994 base::Bind( |
985 &SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback, | 995 &SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback, |
986 weak_ptr_factory_.GetWeakPtr(), | 996 weak_ptr_factory_.GetWeakPtr(), |
987 done_callback)); | 997 done_callback)); |
988 content::BrowserThread::PostTask( | |
989 content::BrowserThread::FILE, | |
990 FROM_HERE, | |
991 base::Bind(&browser_sync::GetSessionNameTask::GetSessionNameAsync, | |
992 task.get())); | |
993 } | 998 } |
994 | 999 |
995 void SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback( | 1000 void SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback( |
996 const base::Callback<void(bool)>& done_callback, | 1001 const base::Callback<void(bool)>& done_callback, |
997 const std::string& session_name) { | 1002 const std::string& session_name) { |
998 if (!directory()->initial_sync_ended_for_type(syncable::NIGORI)) { | 1003 if (!directory()->initial_sync_ended_for_type(syncable::NIGORI)) { |
999 done_callback.Run(false); // Should only happen during first time sync. | 1004 done_callback.Run(false); // Should only happen during first time sync. |
1000 return; | 1005 return; |
1001 } | 1006 } |
1002 | 1007 |
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2471 share->directory->GetDownloadProgress(i.Get(), &marker); | 2476 share->directory->GetDownloadProgress(i.Get(), &marker); |
2472 | 2477 |
2473 if (marker.token().empty()) | 2478 if (marker.token().empty()) |
2474 result.Put(i.Get()); | 2479 result.Put(i.Get()); |
2475 | 2480 |
2476 } | 2481 } |
2477 return result; | 2482 return result; |
2478 } | 2483 } |
2479 | 2484 |
2480 } // namespace sync_api | 2485 } // namespace sync_api |
OLD | NEW |