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

Side by Side Diff: sync/internal_api/sync_manager.cc

Issue 10701085: Revert "Revert 142517 - [Sync] Refactor sync configuration logic." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile/test Created 8 years, 5 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 (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 "sync/internal_api/public/sync_manager.h" 5 #include "sync/internal_api/public/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 14 matching lines...) Expand all
25 #include "sync/engine/throttled_data_type_tracker.h" 25 #include "sync/engine/throttled_data_type_tracker.h"
26 #include "sync/internal_api/change_reorder_buffer.h" 26 #include "sync/internal_api/change_reorder_buffer.h"
27 #include "sync/internal_api/debug_info_event_listener.h" 27 #include "sync/internal_api/debug_info_event_listener.h"
28 #include "sync/internal_api/js_mutation_event_observer.h" 28 #include "sync/internal_api/js_mutation_event_observer.h"
29 #include "sync/internal_api/js_sync_manager_observer.h" 29 #include "sync/internal_api/js_sync_manager_observer.h"
30 #include "sync/internal_api/public/base/model_type.h" 30 #include "sync/internal_api/public/base/model_type.h"
31 #include "sync/internal_api/public/base/model_type_payload_map.h" 31 #include "sync/internal_api/public/base/model_type_payload_map.h"
32 #include "sync/internal_api/public/base_node.h" 32 #include "sync/internal_api/public/base_node.h"
33 #include "sync/internal_api/public/configure_reason.h" 33 #include "sync/internal_api/public/configure_reason.h"
34 #include "sync/internal_api/public/engine/polling_constants.h" 34 #include "sync/internal_api/public/engine/polling_constants.h"
35 #include "sync/internal_api/public/http_post_provider_factory.h"
35 #include "sync/internal_api/public/read_node.h" 36 #include "sync/internal_api/public/read_node.h"
36 #include "sync/internal_api/public/read_transaction.h" 37 #include "sync/internal_api/public/read_transaction.h"
37 #include "sync/internal_api/public/user_share.h" 38 #include "sync/internal_api/public/user_share.h"
38 #include "sync/internal_api/public/util/experiments.h" 39 #include "sync/internal_api/public/util/experiments.h"
39 #include "sync/internal_api/public/write_node.h" 40 #include "sync/internal_api/public/write_node.h"
40 #include "sync/internal_api/public/write_transaction.h" 41 #include "sync/internal_api/public/write_transaction.h"
41 #include "sync/internal_api/syncapi_internal.h" 42 #include "sync/internal_api/syncapi_internal.h"
42 #include "sync/internal_api/syncapi_server_connection_manager.h" 43 #include "sync/internal_api/syncapi_server_connection_manager.h"
43 #include "sync/js/js_arg_list.h" 44 #include "sync/js/js_arg_list.h"
44 #include "sync/js/js_backend.h" 45 #include "sync/js/js_backend.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 virtual ~SyncInternal() { 170 virtual ~SyncInternal() {
170 CHECK(!initialized_); 171 CHECK(!initialized_);
171 } 172 }
172 173
173 bool Init(const FilePath& database_location, 174 bool Init(const FilePath& database_location,
174 const WeakHandle<JsEventHandler>& event_handler, 175 const WeakHandle<JsEventHandler>& event_handler,
175 const std::string& sync_server_and_path, 176 const std::string& sync_server_and_path,
176 int port, 177 int port,
177 bool use_ssl, 178 bool use_ssl,
178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 179 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
179 HttpPostProviderFactory* post_factory, 180 scoped_ptr<HttpPostProviderFactory> post_factory,
180 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 181 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
181 const std::vector<syncer::ModelSafeWorker*>& workers, 182 const std::vector<syncer::ModelSafeWorker*>& workers,
182 syncer::ExtensionsActivityMonitor* 183 syncer::ExtensionsActivityMonitor*
183 extensions_activity_monitor, 184 extensions_activity_monitor,
184 ChangeDelegate* change_delegate, 185 ChangeDelegate* change_delegate,
185 const SyncCredentials& credentials, 186 const SyncCredentials& credentials,
186 syncer::SyncNotifier* sync_notifier, 187 scoped_ptr<syncer::SyncNotifier> sync_notifier,
187 const std::string& restored_key_for_bootstrapping, 188 const std::string& restored_key_for_bootstrapping,
188 TestingMode testing_mode, 189 TestingMode testing_mode,
189 Encryptor* encryptor, 190 Encryptor* encryptor,
190 UnrecoverableErrorHandler* unrecoverable_error_handler, 191 UnrecoverableErrorHandler* unrecoverable_error_handler,
191 ReportUnrecoverableErrorFunction 192 ReportUnrecoverableErrorFunction
192 report_unrecoverable_error_function); 193 report_unrecoverable_error_function);
193 194
194 // Sign into sync with given credentials. 195 // Sign into sync with given credentials.
195 // We do not verify the tokens given. After this call, the tokens are set 196 // We do not verify the tokens given. After this call, the tokens are set
196 // and the sync DB is open. True if successful, false if something 197 // and the sync DB is open. True if successful, false if something
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 SyncManager::SyncManager(const std::string& name) 688 SyncManager::SyncManager(const std::string& name)
688 : data_(new SyncInternal(name)) {} 689 : data_(new SyncInternal(name)) {}
689 690
690 bool SyncManager::Init( 691 bool SyncManager::Init(
691 const FilePath& database_location, 692 const FilePath& database_location,
692 const WeakHandle<JsEventHandler>& event_handler, 693 const WeakHandle<JsEventHandler>& event_handler,
693 const std::string& sync_server_and_path, 694 const std::string& sync_server_and_path,
694 int sync_server_port, 695 int sync_server_port,
695 bool use_ssl, 696 bool use_ssl,
696 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 697 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
697 HttpPostProviderFactory* post_factory, 698 scoped_ptr<HttpPostProviderFactory> post_factory,
698 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 699 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
699 const std::vector<syncer::ModelSafeWorker*>& workers, 700 const std::vector<syncer::ModelSafeWorker*>& workers,
700 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 701 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
701 ChangeDelegate* change_delegate, 702 ChangeDelegate* change_delegate,
702 const SyncCredentials& credentials, 703 const SyncCredentials& credentials,
703 syncer::SyncNotifier* sync_notifier, 704 scoped_ptr<syncer::SyncNotifier> sync_notifier,
704 const std::string& restored_key_for_bootstrapping, 705 const std::string& restored_key_for_bootstrapping,
705 TestingMode testing_mode, 706 TestingMode testing_mode,
706 Encryptor* encryptor, 707 Encryptor* encryptor,
707 UnrecoverableErrorHandler* unrecoverable_error_handler, 708 UnrecoverableErrorHandler* unrecoverable_error_handler,
708 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { 709 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) {
709 DCHECK(thread_checker_.CalledOnValidThread()); 710 DCHECK(thread_checker_.CalledOnValidThread());
710 DCHECK(post_factory); 711 DCHECK(post_factory.get());
711 DVLOG(1) << "SyncManager starting Init..."; 712 DVLOG(1) << "SyncManager starting Init...";
712 std::string server_string(sync_server_and_path); 713 std::string server_string(sync_server_and_path);
713 return data_->Init(database_location, 714 return data_->Init(database_location,
714 event_handler, 715 event_handler,
715 server_string, 716 server_string,
716 sync_server_port, 717 sync_server_port,
717 use_ssl, 718 use_ssl,
718 blocking_task_runner, 719 blocking_task_runner,
719 post_factory, 720 post_factory.Pass(),
720 model_safe_routing_info, 721 model_safe_routing_info,
721 workers, 722 workers,
722 extensions_activity_monitor, 723 extensions_activity_monitor,
723 change_delegate, 724 change_delegate,
724 credentials, 725 credentials,
725 sync_notifier, 726 sync_notifier.Pass(),
726 restored_key_for_bootstrapping, 727 restored_key_for_bootstrapping,
727 testing_mode, 728 testing_mode,
728 encryptor, 729 encryptor,
729 unrecoverable_error_handler, 730 unrecoverable_error_handler,
730 report_unrecoverable_error_function); 731 report_unrecoverable_error_function);
731 } 732 }
732 733
733 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { 734 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) {
734 DCHECK(thread_checker_.CalledOnValidThread()); 735 DCHECK(thread_checker_.CalledOnValidThread());
735 data_->UpdateCredentials(credentials); 736 data_->UpdateCredentials(credentials);
736 } 737 }
737 738
738 void SyncManager::UpdateEnabledTypes(const ModelTypeSet& enabled_types) { 739 void SyncManager::UpdateEnabledTypes(const ModelTypeSet& enabled_types) {
739 DCHECK(thread_checker_.CalledOnValidThread()); 740 DCHECK(thread_checker_.CalledOnValidThread());
740 data_->UpdateEnabledTypes(enabled_types); 741 data_->UpdateEnabledTypes(enabled_types);
741 } 742 }
742 743
743 void SyncManager::ThrowUnrecoverableError() { 744 void SyncManager::ThrowUnrecoverableError() {
744 DCHECK(thread_checker_.CalledOnValidThread()); 745 DCHECK(thread_checker_.CalledOnValidThread());
745 ReadTransaction trans(FROM_HERE, GetUserShare()); 746 ReadTransaction trans(FROM_HERE, GetUserShare());
746 trans.GetWrappedTrans()->OnUnrecoverableError( 747 trans.GetWrappedTrans()->OnUnrecoverableError(
747 FROM_HERE, "Simulating unrecoverable error for testing purposes."); 748 FROM_HERE, "Simulating unrecoverable error for testing purposes.");
748 } 749 }
749 750
750 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() { 751 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() {
751 return data_->InitialSyncEndedTypes(); 752 return data_->InitialSyncEndedTypes();
752 } 753 }
753 754
755 syncer::ModelTypeSet SyncManager::GetTypesWithEmptyProgressMarkerToken(
756 syncer::ModelTypeSet types) {
757 syncer::ModelTypeSet result;
758 for (syncer::ModelTypeSet::Iterator i = types.First();
759 i.Good(); i.Inc()) {
760 sync_pb::DataTypeProgressMarker marker;
761 GetUserShare()->directory->GetDownloadProgress(i.Get(), &marker);
762
763 if (marker.token().empty())
764 result.Put(i.Get());
765
766 }
767 return result;
768 }
769
754 void SyncManager::StartSyncingNormally( 770 void SyncManager::StartSyncingNormally(
755 const syncer::ModelSafeRoutingInfo& routing_info) { 771 const syncer::ModelSafeRoutingInfo& routing_info) {
756 DCHECK(thread_checker_.CalledOnValidThread()); 772 DCHECK(thread_checker_.CalledOnValidThread());
757 data_->StartSyncingNormally(routing_info); 773 data_->StartSyncingNormally(routing_info);
758 } 774 }
759 775
760 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase, 776 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase,
761 bool is_explicit) { 777 bool is_explicit) {
762 DCHECK(thread_checker_.CalledOnValidThread()); 778 DCHECK(thread_checker_.CalledOnValidThread());
763 data_->SetEncryptionPassphrase(passphrase, is_explicit); 779 data_->SetEncryptionPassphrase(passphrase, is_explicit);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 846
831 } 847 }
832 848
833 bool SyncManager::SyncInternal::Init( 849 bool SyncManager::SyncInternal::Init(
834 const FilePath& database_location, 850 const FilePath& database_location,
835 const WeakHandle<JsEventHandler>& event_handler, 851 const WeakHandle<JsEventHandler>& event_handler,
836 const std::string& sync_server_and_path, 852 const std::string& sync_server_and_path,
837 int port, 853 int port,
838 bool use_ssl, 854 bool use_ssl,
839 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 855 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
840 HttpPostProviderFactory* post_factory, 856 scoped_ptr<HttpPostProviderFactory> post_factory,
841 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 857 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
842 const std::vector<syncer::ModelSafeWorker*>& workers, 858 const std::vector<syncer::ModelSafeWorker*>& workers,
843 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 859 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
844 ChangeDelegate* change_delegate, 860 ChangeDelegate* change_delegate,
845 const SyncCredentials& credentials, 861 const SyncCredentials& credentials,
846 syncer::SyncNotifier* sync_notifier, 862 scoped_ptr<syncer::SyncNotifier> sync_notifier,
847 const std::string& restored_key_for_bootstrapping, 863 const std::string& restored_key_for_bootstrapping,
848 TestingMode testing_mode, 864 TestingMode testing_mode,
849 Encryptor* encryptor, 865 Encryptor* encryptor,
850 UnrecoverableErrorHandler* unrecoverable_error_handler, 866 UnrecoverableErrorHandler* unrecoverable_error_handler,
851 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { 867 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) {
852 CHECK(!initialized_); 868 CHECK(!initialized_);
853 869
854 DCHECK(thread_checker_.CalledOnValidThread()); 870 DCHECK(thread_checker_.CalledOnValidThread());
855 871
856 DVLOG(1) << "Starting SyncInternal initialization."; 872 DVLOG(1) << "Starting SyncInternal initialization.";
857 873
858 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); 874 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
859 875
860 blocking_task_runner_ = blocking_task_runner; 876 blocking_task_runner_ = blocking_task_runner;
861 877
862 change_delegate_ = change_delegate; 878 change_delegate_ = change_delegate;
863 testing_mode_ = testing_mode; 879 testing_mode_ = testing_mode;
864 880
865 sync_notifier_.reset(sync_notifier); 881 sync_notifier_ = sync_notifier.Pass();
866 882
867 AddObserver(&js_sync_manager_observer_); 883 AddObserver(&js_sync_manager_observer_);
868 SetJsEventHandler(event_handler); 884 SetJsEventHandler(event_handler);
869 885
870 AddObserver(&debug_info_event_listener_); 886 AddObserver(&debug_info_event_listener_);
871 887
872 database_path_ = database_location.Append( 888 database_path_ = database_location.Append(
873 syncable::Directory::kSyncDatabaseFilename); 889 syncable::Directory::kSyncDatabaseFilename);
874 encryptor_ = encryptor; 890 encryptor_ = encryptor;
875 unrecoverable_error_handler_ = unrecoverable_error_handler; 891 unrecoverable_error_handler_ = unrecoverable_error_handler;
(...skipping 13 matching lines...) Expand all
889 } 905 }
890 906
891 DCHECK(backing_store); 907 DCHECK(backing_store);
892 share_.directory.reset( 908 share_.directory.reset(
893 new syncable::Directory(encryptor_, 909 new syncable::Directory(encryptor_,
894 unrecoverable_error_handler_, 910 unrecoverable_error_handler_,
895 report_unrecoverable_error_function_, 911 report_unrecoverable_error_function_,
896 backing_store)); 912 backing_store));
897 913
898 connection_manager_.reset(new SyncAPIServerConnectionManager( 914 connection_manager_.reset(new SyncAPIServerConnectionManager(
899 sync_server_and_path, port, use_ssl, post_factory)); 915 sync_server_and_path, port, use_ssl, post_factory.release()));
900 916
901 net::NetworkChangeNotifier::AddIPAddressObserver(this); 917 net::NetworkChangeNotifier::AddIPAddressObserver(this);
902 observing_ip_address_changes_ = true; 918 observing_ip_address_changes_ = true;
903 919
904 connection_manager()->AddListener(this); 920 connection_manager()->AddListener(this);
905 921
906 // Test mode does not use a syncer context or syncer thread. 922 // Test mode does not use a syncer context or syncer thread.
907 if (testing_mode_ == NON_TEST) { 923 if (testing_mode_ == NON_TEST) {
908 // Build a SyncSessionContext and store the worker in it. 924 // Build a SyncSessionContext and store the worker in it.
909 DVLOG(1) << "Sync is bringing up SyncSessionContext."; 925 DVLOG(1) << "Sync is bringing up SyncSessionContext.";
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, 2481 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types,
2466 syncer::UserShare* share) { 2482 syncer::UserShare* share) {
2467 for (syncer::ModelTypeSet::Iterator i = types.First(); 2483 for (syncer::ModelTypeSet::Iterator i = types.First();
2468 i.Good(); i.Inc()) { 2484 i.Good(); i.Inc()) {
2469 if (!share->directory->initial_sync_ended_for_type(i.Get())) 2485 if (!share->directory->initial_sync_ended_for_type(i.Get()))
2470 return false; 2486 return false;
2471 } 2487 }
2472 return true; 2488 return true;
2473 } 2489 }
2474 2490
2475 syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
2476 syncer::ModelTypeSet types,
2477 syncer::UserShare* share) {
2478 syncer::ModelTypeSet result;
2479 for (syncer::ModelTypeSet::Iterator i = types.First();
2480 i.Good(); i.Inc()) {
2481 sync_pb::DataTypeProgressMarker marker;
2482 share->directory->GetDownloadProgress(i.Get(), &marker);
2483
2484 if (marker.token().empty())
2485 result.Put(i.Get());
2486
2487 }
2488 return result;
2489 }
2490
2491 } // namespace syncer 2491 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698