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

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

Issue 10483015: [Sync] Refactor sync configuration logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 6 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/sync_manager.h" 5 #include "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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "sync/protocol/sync.pb.h" 51 #include "sync/protocol/sync.pb.h"
52 #include "sync/syncable/directory_change_delegate.h" 52 #include "sync/syncable/directory_change_delegate.h"
53 #include "sync/syncable/syncable.h" 53 #include "sync/syncable/syncable.h"
54 #include "sync/util/cryptographer.h" 54 #include "sync/util/cryptographer.h"
55 #include "sync/util/experiments.h" 55 #include "sync/util/experiments.h"
56 #include "sync/util/get_session_name.h" 56 #include "sync/util/get_session_name.h"
57 #include "sync/util/time.h" 57 #include "sync/util/time.h"
58 58
59 using base::TimeDelta; 59 using base::TimeDelta;
60 using browser_sync::AllStatus; 60 using browser_sync::AllStatus;
61 using browser_sync::ConfigureParams;
61 using browser_sync::Cryptographer; 62 using browser_sync::Cryptographer;
62 using browser_sync::Encryptor; 63 using browser_sync::Encryptor;
63 using browser_sync::JsArgList; 64 using browser_sync::JsArgList;
64 using browser_sync::JsBackend; 65 using browser_sync::JsBackend;
65 using browser_sync::JsEventDetails; 66 using browser_sync::JsEventDetails;
66 using browser_sync::JsEventHandler; 67 using browser_sync::JsEventHandler;
67 using browser_sync::JsEventHandler; 68 using browser_sync::JsEventHandler;
68 using browser_sync::JsReplyHandler; 69 using browser_sync::JsReplyHandler;
69 using browser_sync::JsMutationEventObserver; 70 using browser_sync::JsMutationEventObserver;
70 using browser_sync::JsSyncManagerObserver; 71 using browser_sync::JsSyncManagerObserver;
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 836
836 bool SyncManager::EncryptEverythingEnabledForTest() const { 837 bool SyncManager::EncryptEverythingEnabledForTest() const {
837 ReadTransaction trans(FROM_HERE, GetUserShare()); 838 ReadTransaction trans(FROM_HERE, GetUserShare());
838 return trans.GetCryptographer()->encrypt_everything(); 839 return trans.GetCryptographer()->encrypt_everything();
839 } 840 }
840 841
841 bool SyncManager::IsUsingExplicitPassphrase() { 842 bool SyncManager::IsUsingExplicitPassphrase() {
842 return data_ && data_->IsUsingExplicitPassphrase(); 843 return data_ && data_->IsUsingExplicitPassphrase();
843 } 844 }
844 845
845 void SyncManager::RequestCleanupDisabledTypes(
846 const browser_sync::ModelSafeRoutingInfo& routing_info) {
847 DCHECK(thread_checker_.CalledOnValidThread());
848 if (data_->scheduler()) {
849 data_->session_context()->set_routing_info(routing_info);
850 data_->scheduler()->CleanupDisabledTypes();
851 }
852 }
853
854 void SyncManager::RequestClearServerData() { 846 void SyncManager::RequestClearServerData() {
855 DCHECK(thread_checker_.CalledOnValidThread()); 847 DCHECK(thread_checker_.CalledOnValidThread());
856 if (data_->scheduler()) 848 if (data_->scheduler())
857 data_->scheduler()->ClearUserData(); 849 data_->scheduler()->ClearUserData();
858 } 850 }
859 851
860 void SyncManager::RequestConfig( 852 void SyncManager::ConfigureSyncer(
861 const browser_sync::ModelSafeRoutingInfo& routing_info, 853 ConfigureReason reason,
862 const ModelTypeSet& types, ConfigureReason reason) { 854 const syncable::ModelTypeSet& types_to_config,
855 const browser_sync::ModelSafeRoutingInfo& new_routing_info,
856 const base::Closure& ready_task,
857 const base::Closure& retry_task) {
863 DCHECK(thread_checker_.CalledOnValidThread()); 858 DCHECK(thread_checker_.CalledOnValidThread());
859 DCHECK(!ready_task.is_null());
860 DCHECK(!retry_task.is_null());
861
862 // TODO(zea): set this based on whether cryptographer has keystore
863 // encryption key or not (requires opening a transaction).
864 bool need_encryption_key = false;
865
866 ConfigureParams params(GetSourceFromReason(reason),
867 types_to_config,
868 new_routing_info,
869 need_encryption_key,
870 ready_task);
871
872 // Returns false if a retry has been scheduled. Either way, will invoke the
873 // ready task when the configure job completes.
874 if (!DoConfigureSyncer(params))
875 retry_task.Run();
876 }
877
878 bool SyncManager::DoConfigureSyncer(const ConfigureParams& params) {
864 if (!data_->scheduler()) { 879 if (!data_->scheduler()) {
865 LOG(INFO) 880 LOG(INFO)
866 << "SyncManager::RequestConfig: bailing out because scheduler is " 881 << "SyncManager::DoConfigureSyncer: could not configure because "
867 << "null"; 882 << "scheduler is null";
868 return; 883 params.ready_task.Run();
884 return true;
869 } 885 }
870 StartConfigurationMode(base::Closure());
871 data_->session_context()->set_routing_info(routing_info);
872 data_->scheduler()->Configure(types, GetSourceFromReason(reason));
873 }
874 886
875 void SyncManager::StartConfigurationMode(const base::Closure& callback) { 887 data_->scheduler()->Start(SyncScheduler::CONFIGURATION_MODE);
876 DCHECK(thread_checker_.CalledOnValidThread()); 888 return data_->scheduler()->Configure(params);
877 if (!data_->scheduler()) {
878 LOG(INFO)
879 << "SyncManager::StartConfigurationMode: could not start "
880 << "configuration mode because because scheduler is null";
881 return;
882 }
883 data_->scheduler()->Start(
884 browser_sync::SyncScheduler::CONFIGURATION_MODE, callback);
885 } 889 }
886 890
887 bool SyncManager::SyncInternal::Init( 891 bool SyncManager::SyncInternal::Init(
888 const FilePath& database_location, 892 const FilePath& database_location,
889 const WeakHandle<JsEventHandler>& event_handler, 893 const WeakHandle<JsEventHandler>& event_handler,
890 const std::string& sync_server_and_path, 894 const std::string& sync_server_and_path,
891 int port, 895 int port,
892 bool use_ssl, 896 bool use_ssl,
893 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 897 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
894 HttpPostProviderFactory* post_factory, 898 HttpPostProviderFactory* post_factory,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 &debug_info_event_listener_, 963 &debug_info_event_listener_,
960 &traffic_recorder_)); 964 &traffic_recorder_));
961 session_context()->set_account_name(credentials.email); 965 session_context()->set_account_name(credentials.email);
962 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); 966 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer()));
963 } 967 }
964 968
965 bool signed_in = SignIn(credentials); 969 bool signed_in = SignIn(credentials);
966 970
967 if (signed_in) { 971 if (signed_in) {
968 if (scheduler()) { 972 if (scheduler()) {
969 scheduler()->Start( 973 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE);
970 browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure());
971 } 974 }
972 975
973 initialized_ = true; 976 initialized_ = true;
974 977
975 // Cryptographer should only be accessed while holding a 978 // Cryptographer should only be accessed while holding a
976 // transaction. Grabbing the user share for the transaction 979 // transaction. Grabbing the user share for the transaction
977 // checks the initialization state, so this must come after 980 // checks the initialization state, so this must come after
978 // |initialized_| is set to true. 981 // |initialized_| is set to true.
979 ReadTransaction trans(FROM_HERE, GetUserShare()); 982 ReadTransaction trans(FROM_HERE, GetUserShare());
980 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); 983 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 allstatus_.SetCryptographerReady(cryptographer->is_ready()); 1137 allstatus_.SetCryptographerReady(cryptographer->is_ready());
1135 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); 1138 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys());
1136 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); 1139 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready());
1137 debug_info_event_listener_.SetCrytographerHasPendingKeys( 1140 debug_info_event_listener_.SetCrytographerHasPendingKeys(
1138 cryptographer->has_pending_keys()); 1141 cryptographer->has_pending_keys());
1139 } 1142 }
1140 1143
1141 void SyncManager::SyncInternal::StartSyncingNormally( 1144 void SyncManager::SyncInternal::StartSyncingNormally(
1142 const browser_sync::ModelSafeRoutingInfo& routing_info) { 1145 const browser_sync::ModelSafeRoutingInfo& routing_info) {
1143 // Start the sync scheduler. 1146 // Start the sync scheduler.
1144 if (scheduler()) { // NULL during certain unittests. 1147 if (scheduler()) { // NULL during certain unittests.
1148 // TODO(sync): pass this into the scheduler somehow.
rlarocque 2012/06/12 17:45:13 What is 'this' referring to?
Nicolas Zea 2012/06/12 20:44:44 This comment has been updated in the newer patch.
1145 session_context()->set_routing_info(routing_info); 1149 session_context()->set_routing_info(routing_info);
1146 scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); 1150 scheduler()->Start(SyncScheduler::NORMAL_MODE);
1147 } 1151 }
1148 } 1152 }
1149 1153
1150 bool SyncManager::SyncInternal::OpenDirectory() { 1154 bool SyncManager::SyncInternal::OpenDirectory() {
1151 DCHECK(!initialized_) << "Should only happen once"; 1155 DCHECK(!initialized_) << "Should only happen once";
1152 1156
1153 // Set before Open(). 1157 // Set before Open().
1154 change_observer_ = 1158 change_observer_ =
1155 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); 1159 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr());
1156 WeakHandle<syncable::TransactionObserver> transaction_observer( 1160 WeakHandle<syncable::TransactionObserver> transaction_observer(
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 share->directory->GetDownloadProgress(i.Get(), &marker); 2506 share->directory->GetDownloadProgress(i.Get(), &marker);
2503 2507
2504 if (marker.token().empty()) 2508 if (marker.token().empty())
2505 result.Put(i.Get()); 2509 result.Put(i.Get());
2506 2510
2507 } 2511 }
2508 return result; 2512 return result;
2509 } 2513 }
2510 2514
2511 } // namespace sync_api 2515 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698