| 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 "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 Loading... |
| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 virtual void OnServerConnectionEvent( | 391 virtual void OnServerConnectionEvent( |
| 391 const ServerConnectionEvent& event) OVERRIDE; | 392 const ServerConnectionEvent& event) OVERRIDE; |
| 392 | 393 |
| 393 // JsBackend implementation. | 394 // JsBackend implementation. |
| 394 virtual void SetJsEventHandler( | 395 virtual void SetJsEventHandler( |
| 395 const WeakHandle<JsEventHandler>& event_handler) OVERRIDE; | 396 const WeakHandle<JsEventHandler>& event_handler) OVERRIDE; |
| 396 virtual void ProcessJsMessage( | 397 virtual void ProcessJsMessage( |
| 397 const std::string& name, const JsArgList& args, | 398 const std::string& name, const JsArgList& args, |
| 398 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE; | 399 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE; |
| 399 | 400 |
| 401 void SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler); |
| 402 |
| 400 private: | 403 private: |
| 401 struct NotificationInfo { | 404 struct NotificationInfo { |
| 402 int total_count; | 405 int total_count; |
| 403 std::string payload; | 406 std::string payload; |
| 404 | 407 |
| 405 NotificationInfo() : total_count(0) {} | 408 NotificationInfo() : total_count(0) {} |
| 406 | 409 |
| 407 ~NotificationInfo() {} | 410 ~NotificationInfo() {} |
| 408 | 411 |
| 409 // Returned pointer owned by the caller. | 412 // Returned pointer owned by the caller. |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 | 812 |
| 810 bool SyncManager::EncryptEverythingEnabledForTest() const { | 813 bool SyncManager::EncryptEverythingEnabledForTest() const { |
| 811 ReadTransaction trans(FROM_HERE, GetUserShare()); | 814 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 812 return trans.GetCryptographer()->encrypt_everything(); | 815 return trans.GetCryptographer()->encrypt_everything(); |
| 813 } | 816 } |
| 814 | 817 |
| 815 bool SyncManager::IsUsingExplicitPassphrase() { | 818 bool SyncManager::IsUsingExplicitPassphrase() { |
| 816 return data_ && data_->IsUsingExplicitPassphrase(); | 819 return data_ && data_->IsUsingExplicitPassphrase(); |
| 817 } | 820 } |
| 818 | 821 |
| 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() { | 822 void SyncManager::RequestClearServerData() { |
| 829 DCHECK(thread_checker_.CalledOnValidThread()); | 823 DCHECK(thread_checker_.CalledOnValidThread()); |
| 830 if (data_->scheduler()) | 824 if (data_->scheduler()) |
| 831 data_->scheduler()->ClearUserData(); | 825 data_->scheduler()->ClearUserData(); |
| 832 } | 826 } |
| 833 | 827 |
| 834 void SyncManager::RequestConfig( | 828 void SyncManager::ConfigureSyncer( |
| 835 const browser_sync::ModelSafeRoutingInfo& routing_info, | 829 ConfigureReason reason, |
| 836 const ModelTypeSet& types, ConfigureReason reason) { | 830 const syncable::ModelTypeSet& types_to_config, |
| 831 const browser_sync::ModelSafeRoutingInfo& new_routing_info, |
| 832 const base::Closure& ready_task, |
| 833 const base::Closure& retry_task) { |
| 837 DCHECK(thread_checker_.CalledOnValidThread()); | 834 DCHECK(thread_checker_.CalledOnValidThread()); |
| 835 DCHECK(!ready_task.is_null()); |
| 836 DCHECK(!retry_task.is_null()); |
| 837 |
| 838 // TODO(zea): set this based on whether cryptographer has keystore |
| 839 // encryption key or not (requires opening a transaction). crbug.com/129665. |
| 840 ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| 841 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; |
| 842 |
| 843 ConfigurationParams params(GetSourceFromReason(reason), |
| 844 types_to_config, |
| 845 new_routing_info, |
| 846 keystore_key_status, |
| 847 ready_task); |
| 848 |
| 838 if (!data_->scheduler()) { | 849 if (!data_->scheduler()) { |
| 839 LOG(INFO) | 850 LOG(INFO) |
| 840 << "SyncManager::RequestConfig: bailing out because scheduler is " | 851 << "SyncManager::ConfigureSyncer: could not configure because " |
| 841 << "null"; | 852 << "scheduler is null"; |
| 853 params.ready_task.Run(); |
| 842 return; | 854 return; |
| 843 } | 855 } |
| 844 StartConfigurationMode(base::Closure()); | |
| 845 data_->session_context()->set_routing_info(routing_info); | |
| 846 data_->scheduler()->ScheduleConfiguration(types, GetSourceFromReason(reason)); | |
| 847 } | |
| 848 | 856 |
| 849 void SyncManager::StartConfigurationMode(const base::Closure& callback) { | 857 data_->scheduler()->Start(SyncScheduler::CONFIGURATION_MODE); |
| 850 DCHECK(thread_checker_.CalledOnValidThread()); | 858 if (!data_->scheduler()->ScheduleConfiguration(params)) |
| 851 if (!data_->scheduler()) { | 859 retry_task.Run(); |
| 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 } | 860 } |
| 860 | 861 |
| 861 bool SyncManager::SyncInternal::Init( | 862 bool SyncManager::SyncInternal::Init( |
| 862 const FilePath& database_location, | 863 const FilePath& database_location, |
| 863 const WeakHandle<JsEventHandler>& event_handler, | 864 const WeakHandle<JsEventHandler>& event_handler, |
| 864 const std::string& sync_server_and_path, | 865 const std::string& sync_server_and_path, |
| 865 int port, | 866 int port, |
| 866 bool use_ssl, | 867 bool use_ssl, |
| 867 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 868 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 868 HttpPostProviderFactory* post_factory, | 869 HttpPostProviderFactory* post_factory, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 &debug_info_event_listener_, | 935 &debug_info_event_listener_, |
| 935 &traffic_recorder_)); | 936 &traffic_recorder_)); |
| 936 session_context()->set_account_name(credentials.email); | 937 session_context()->set_account_name(credentials.email); |
| 937 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); | 938 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); |
| 938 } | 939 } |
| 939 | 940 |
| 940 bool signed_in = SignIn(credentials); | 941 bool signed_in = SignIn(credentials); |
| 941 | 942 |
| 942 if (signed_in) { | 943 if (signed_in) { |
| 943 if (scheduler()) { | 944 if (scheduler()) { |
| 944 scheduler()->Start( | 945 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE); |
| 945 browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure()); | |
| 946 } | 946 } |
| 947 | 947 |
| 948 initialized_ = true; | 948 initialized_ = true; |
| 949 | 949 |
| 950 // Cryptographer should only be accessed while holding a | 950 // Cryptographer should only be accessed while holding a |
| 951 // transaction. Grabbing the user share for the transaction | 951 // transaction. Grabbing the user share for the transaction |
| 952 // checks the initialization state, so this must come after | 952 // checks the initialization state, so this must come after |
| 953 // |initialized_| is set to true. | 953 // |initialized_| is set to true. |
| 954 ReadTransaction trans(FROM_HERE, GetUserShare()); | 954 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 955 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); | 955 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1109 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 1110 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1110 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 1111 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); | 1111 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); |
| 1112 debug_info_event_listener_.SetCrytographerHasPendingKeys( | 1112 debug_info_event_listener_.SetCrytographerHasPendingKeys( |
| 1113 cryptographer->has_pending_keys()); | 1113 cryptographer->has_pending_keys()); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 void SyncManager::SyncInternal::StartSyncingNormally( | 1116 void SyncManager::SyncInternal::StartSyncingNormally( |
| 1117 const browser_sync::ModelSafeRoutingInfo& routing_info) { | 1117 const browser_sync::ModelSafeRoutingInfo& routing_info) { |
| 1118 // Start the sync scheduler. | 1118 // Start the sync scheduler. |
| 1119 if (scheduler()) { // NULL during certain unittests. | 1119 if (scheduler()) { // NULL during certain unittests. |
| 1120 // TODO(sync): We always want the newest set of routes when we switch back |
| 1121 // to normal mode. Figure out how to enforce set_routing_info is always |
| 1122 // appropriately set and that it's only modified when switching to normal |
| 1123 // mode. |
| 1120 session_context()->set_routing_info(routing_info); | 1124 session_context()->set_routing_info(routing_info); |
| 1121 scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); | 1125 scheduler()->Start(SyncScheduler::NORMAL_MODE); |
| 1122 } | 1126 } |
| 1123 } | 1127 } |
| 1124 | 1128 |
| 1125 bool SyncManager::SyncInternal::OpenDirectory() { | 1129 bool SyncManager::SyncInternal::OpenDirectory() { |
| 1126 DCHECK(!initialized_) << "Should only happen once"; | 1130 DCHECK(!initialized_) << "Should only happen once"; |
| 1127 | 1131 |
| 1128 // Set before Open(). | 1132 // Set before Open(). |
| 1129 change_observer_ = | 1133 change_observer_ = |
| 1130 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); | 1134 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); |
| 1131 WeakHandle<syncable::TransactionObserver> transaction_observer( | 1135 WeakHandle<syncable::TransactionObserver> transaction_observer( |
| (...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 void SyncManager::SyncInternal::AddObserver( | 2350 void SyncManager::SyncInternal::AddObserver( |
| 2347 SyncManager::Observer* observer) { | 2351 SyncManager::Observer* observer) { |
| 2348 observers_.AddObserver(observer); | 2352 observers_.AddObserver(observer); |
| 2349 } | 2353 } |
| 2350 | 2354 |
| 2351 void SyncManager::SyncInternal::RemoveObserver( | 2355 void SyncManager::SyncInternal::RemoveObserver( |
| 2352 SyncManager::Observer* observer) { | 2356 SyncManager::Observer* observer) { |
| 2353 observers_.RemoveObserver(observer); | 2357 observers_.RemoveObserver(observer); |
| 2354 } | 2358 } |
| 2355 | 2359 |
| 2360 void SyncManager::SyncInternal::SetSyncSchedulerForTest( |
| 2361 scoped_ptr<SyncScheduler> sync_scheduler) { |
| 2362 scheduler_ = sync_scheduler.Pass(); |
| 2363 } |
| 2364 |
| 2356 SyncStatus SyncManager::GetDetailedStatus() const { | 2365 SyncStatus SyncManager::GetDetailedStatus() const { |
| 2357 return data_->GetStatus(); | 2366 return data_->GetStatus(); |
| 2358 } | 2367 } |
| 2359 | 2368 |
| 2360 void SyncManager::SaveChanges() { | 2369 void SyncManager::SaveChanges() { |
| 2361 DCHECK(thread_checker_.CalledOnValidThread()); | 2370 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2362 data_->SaveChanges(); | 2371 data_->SaveChanges(); |
| 2363 } | 2372 } |
| 2364 | 2373 |
| 2365 void SyncManager::SyncInternal::SaveChanges() { | 2374 void SyncManager::SyncInternal::SaveChanges() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2376 data_->UpdateCryptographerAndNigori( | 2385 data_->UpdateCryptographerAndNigori( |
| 2377 chrome_version, | 2386 chrome_version, |
| 2378 done_callback); | 2387 done_callback); |
| 2379 } | 2388 } |
| 2380 | 2389 |
| 2381 TimeDelta SyncManager::GetNudgeDelayTimeDelta( | 2390 TimeDelta SyncManager::GetNudgeDelayTimeDelta( |
| 2382 const ModelType& model_type) { | 2391 const ModelType& model_type) { |
| 2383 return data_->GetNudgeDelayTimeDelta(model_type); | 2392 return data_->GetNudgeDelayTimeDelta(model_type); |
| 2384 } | 2393 } |
| 2385 | 2394 |
| 2395 void SyncManager::SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler) { |
| 2396 data_->SetSyncSchedulerForTest(scheduler.Pass()); |
| 2397 } |
| 2398 |
| 2386 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { | 2399 syncable::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { |
| 2387 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2400 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2388 return GetEncryptedTypes(&trans); | 2401 return GetEncryptedTypes(&trans); |
| 2389 } | 2402 } |
| 2390 | 2403 |
| 2391 bool SyncManager::ReceivedExperiment(browser_sync::Experiments* experiments) | 2404 bool SyncManager::ReceivedExperiment(browser_sync::Experiments* experiments) |
| 2392 const { | 2405 const { |
| 2393 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2406 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2394 ReadNode node(&trans); | 2407 ReadNode node(&trans); |
| 2395 if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { | 2408 if (node.InitByTagLookup(kNigoriTag) != sync_api::BaseNode::INIT_OK) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 share->directory->GetDownloadProgress(i.Get(), &marker); | 2490 share->directory->GetDownloadProgress(i.Get(), &marker); |
| 2478 | 2491 |
| 2479 if (marker.token().empty()) | 2492 if (marker.token().empty()) |
| 2480 result.Put(i.Get()); | 2493 result.Put(i.Get()); |
| 2481 | 2494 |
| 2482 } | 2495 } |
| 2483 return result; | 2496 return result; |
| 2484 } | 2497 } |
| 2485 | 2498 |
| 2486 } // namespace sync_api | 2499 } // namespace sync_api |
| OLD | NEW |