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

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: Address comments + 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "sync/protocol/sync.pb.h" 52 #include "sync/protocol/sync.pb.h"
53 #include "sync/syncable/directory_change_delegate.h" 53 #include "sync/syncable/directory_change_delegate.h"
54 #include "sync/syncable/syncable.h" 54 #include "sync/syncable/syncable.h"
55 #include "sync/util/cryptographer.h" 55 #include "sync/util/cryptographer.h"
56 #include "sync/util/experiments.h" 56 #include "sync/util/experiments.h"
57 #include "sync/util/get_session_name.h" 57 #include "sync/util/get_session_name.h"
58 #include "sync/util/time.h" 58 #include "sync/util/time.h"
59 59
60 using base::TimeDelta; 60 using base::TimeDelta;
61 using browser_sync::AllStatus; 61 using browser_sync::AllStatus;
62 using browser_sync::ConfigurationParams;
62 using browser_sync::Cryptographer; 63 using browser_sync::Cryptographer;
63 using browser_sync::Encryptor; 64 using browser_sync::Encryptor;
64 using browser_sync::JsArgList; 65 using browser_sync::JsArgList;
65 using browser_sync::JsBackend; 66 using browser_sync::JsBackend;
66 using browser_sync::JsEventDetails; 67 using browser_sync::JsEventDetails;
67 using browser_sync::JsEventHandler; 68 using browser_sync::JsEventHandler;
68 using browser_sync::JsEventHandler; 69 using browser_sync::JsEventHandler;
69 using browser_sync::JsReplyHandler; 70 using browser_sync::JsReplyHandler;
70 using browser_sync::JsMutationEventObserver; 71 using browser_sync::JsMutationEventObserver;
71 using browser_sync::JsSyncManagerObserver; 72 using browser_sync::JsSyncManagerObserver;
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 810
810 bool SyncManager::EncryptEverythingEnabledForTest() const { 811 bool SyncManager::EncryptEverythingEnabledForTest() const {
811 ReadTransaction trans(FROM_HERE, GetUserShare()); 812 ReadTransaction trans(FROM_HERE, GetUserShare());
812 return trans.GetCryptographer()->encrypt_everything(); 813 return trans.GetCryptographer()->encrypt_everything();
813 } 814 }
814 815
815 bool SyncManager::IsUsingExplicitPassphrase() { 816 bool SyncManager::IsUsingExplicitPassphrase() {
816 return data_ && data_->IsUsingExplicitPassphrase(); 817 return data_ && data_->IsUsingExplicitPassphrase();
817 } 818 }
818 819
819 void SyncManager::RequestCleanupDisabledTypes(
820 const browser_sync::ModelSafeRoutingInfo& routing_info) {
821 DCHECK(thread_checker_.CalledOnValidThread());
822 if (data_->scheduler()) {
823 data_->session_context()->set_routing_info(routing_info);
824 data_->scheduler()->CleanupDisabledTypes();
825 }
826 }
827
828 void SyncManager::RequestClearServerData() { 820 void SyncManager::RequestClearServerData() {
829 DCHECK(thread_checker_.CalledOnValidThread()); 821 DCHECK(thread_checker_.CalledOnValidThread());
830 if (data_->scheduler()) 822 if (data_->scheduler())
831 data_->scheduler()->ClearUserData(); 823 data_->scheduler()->ClearUserData();
832 } 824 }
833 825
834 void SyncManager::RequestConfig( 826 void SyncManager::ConfigureSyncer(
835 const browser_sync::ModelSafeRoutingInfo& routing_info, 827 ConfigureReason reason,
836 const ModelTypeSet& types, ConfigureReason reason) { 828 const syncable::ModelTypeSet& types_to_config,
829 const browser_sync::ModelSafeRoutingInfo& new_routing_info,
830 const base::Closure& ready_task,
831 const base::Closure& retry_task) {
837 DCHECK(thread_checker_.CalledOnValidThread()); 832 DCHECK(thread_checker_.CalledOnValidThread());
833 DCHECK(!ready_task.is_null());
834 DCHECK(!retry_task.is_null());
835
836 // TODO(zea): set this based on whether cryptographer has keystore
837 // encryption key or not (requires opening a transaction). crbug.com/129665.
838 ConfigurationParams::KeystoreKeyStatus keystore_key_status =
839 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY;
840
841 ConfigurationParams params(GetSourceFromReason(reason),
842 types_to_config,
843 new_routing_info,
844 keystore_key_status,
845 ready_task);
846
847 // Returns false if a retry has been scheduled. Either way, will invoke the
848 // ready task when the configure job completes.
849 if (!DoConfigureSyncer(params))
850 retry_task.Run();
851 }
852
853 bool SyncManager::DoConfigureSyncer(const ConfigurationParams& params) {
838 if (!data_->scheduler()) { 854 if (!data_->scheduler()) {
839 LOG(INFO) 855 LOG(INFO)
840 << "SyncManager::RequestConfig: bailing out because scheduler is " 856 << "SyncManager::DoConfigureSyncer: could not configure because "
841 << "null"; 857 << "scheduler is null";
842 return; 858 params.ready_task.Run();
859 return true;
843 } 860 }
844 StartConfigurationMode(base::Closure());
845 data_->session_context()->set_routing_info(routing_info);
846 data_->scheduler()->ScheduleConfiguration(types, GetSourceFromReason(reason));
847 }
848 861
849 void SyncManager::StartConfigurationMode(const base::Closure& callback) { 862 data_->scheduler()->Start(SyncScheduler::CONFIGURATION_MODE);
850 DCHECK(thread_checker_.CalledOnValidThread()); 863 return data_->scheduler()->ScheduleConfiguration(params);
851 if (!data_->scheduler()) {
852 LOG(INFO)
853 << "SyncManager::StartConfigurationMode: could not start "
854 << "configuration mode because because scheduler is null";
855 return;
856 }
857 data_->scheduler()->Start(
858 browser_sync::SyncScheduler::CONFIGURATION_MODE, callback);
859 } 864 }
860 865
861 bool SyncManager::SyncInternal::Init( 866 bool SyncManager::SyncInternal::Init(
862 const FilePath& database_location, 867 const FilePath& database_location,
863 const WeakHandle<JsEventHandler>& event_handler, 868 const WeakHandle<JsEventHandler>& event_handler,
864 const std::string& sync_server_and_path, 869 const std::string& sync_server_and_path,
865 int port, 870 int port,
866 bool use_ssl, 871 bool use_ssl,
867 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 872 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
868 HttpPostProviderFactory* post_factory, 873 HttpPostProviderFactory* post_factory,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 &debug_info_event_listener_, 939 &debug_info_event_listener_,
935 &traffic_recorder_)); 940 &traffic_recorder_));
936 session_context()->set_account_name(credentials.email); 941 session_context()->set_account_name(credentials.email);
937 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); 942 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer()));
938 } 943 }
939 944
940 bool signed_in = SignIn(credentials); 945 bool signed_in = SignIn(credentials);
941 946
942 if (signed_in) { 947 if (signed_in) {
943 if (scheduler()) { 948 if (scheduler()) {
944 scheduler()->Start( 949 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE);
945 browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure());
946 } 950 }
947 951
948 initialized_ = true; 952 initialized_ = true;
949 953
950 // Cryptographer should only be accessed while holding a 954 // Cryptographer should only be accessed while holding a
951 // transaction. Grabbing the user share for the transaction 955 // transaction. Grabbing the user share for the transaction
952 // checks the initialization state, so this must come after 956 // checks the initialization state, so this must come after
953 // |initialized_| is set to true. 957 // |initialized_| is set to true.
954 ReadTransaction trans(FROM_HERE, GetUserShare()); 958 ReadTransaction trans(FROM_HERE, GetUserShare());
955 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); 959 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 allstatus_.SetCryptographerReady(cryptographer->is_ready()); 1113 allstatus_.SetCryptographerReady(cryptographer->is_ready());
1110 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); 1114 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys());
1111 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); 1115 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready());
1112 debug_info_event_listener_.SetCrytographerHasPendingKeys( 1116 debug_info_event_listener_.SetCrytographerHasPendingKeys(
1113 cryptographer->has_pending_keys()); 1117 cryptographer->has_pending_keys());
1114 } 1118 }
1115 1119
1116 void SyncManager::SyncInternal::StartSyncingNormally( 1120 void SyncManager::SyncInternal::StartSyncingNormally(
1117 const browser_sync::ModelSafeRoutingInfo& routing_info) { 1121 const browser_sync::ModelSafeRoutingInfo& routing_info) {
1118 // Start the sync scheduler. 1122 // Start the sync scheduler.
1119 if (scheduler()) { // NULL during certain unittests. 1123 if (scheduler()) { // NULL during certain unittests.
1124 // TODO(sync): We always want the newest set of routes when we switch back
1125 // to normal mode. Figure out how to enforce set_routing_info is always
1126 // appropriately set and that it's only modified when switching to normal
1127 // mode.
1120 session_context()->set_routing_info(routing_info); 1128 session_context()->set_routing_info(routing_info);
1121 scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); 1129 scheduler()->Start(SyncScheduler::NORMAL_MODE);
1122 } 1130 }
1123 } 1131 }
1124 1132
1125 bool SyncManager::SyncInternal::OpenDirectory() { 1133 bool SyncManager::SyncInternal::OpenDirectory() {
1126 DCHECK(!initialized_) << "Should only happen once"; 1134 DCHECK(!initialized_) << "Should only happen once";
1127 1135
1128 // Set before Open(). 1136 // Set before Open().
1129 change_observer_ = 1137 change_observer_ =
1130 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); 1138 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr());
1131 WeakHandle<syncable::TransactionObserver> transaction_observer( 1139 WeakHandle<syncable::TransactionObserver> transaction_observer(
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 share->directory->GetDownloadProgress(i.Get(), &marker); 2485 share->directory->GetDownloadProgress(i.Get(), &marker);
2478 2486
2479 if (marker.token().empty()) 2487 if (marker.token().empty())
2480 result.Put(i.Get()); 2488 result.Put(i.Get());
2481 2489
2482 } 2490 }
2483 return result; 2491 return result;
2484 } 2492 }
2485 2493
2486 } // namespace sync_api 2494 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698