OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/sync/glue/database_model_worker.h" | 23 #include "chrome/browser/sync/glue/database_model_worker.h" |
24 #include "chrome/browser/sync/glue/history_model_worker.h" | 24 #include "chrome/browser/sync/glue/history_model_worker.h" |
25 #include "chrome/browser/sync/glue/sync_backend_host.h" | 25 #include "chrome/browser/sync/glue/sync_backend_host.h" |
26 #include "chrome/browser/sync/glue/http_bridge.h" | 26 #include "chrome/browser/sync/glue/http_bridge.h" |
27 #include "chrome/browser/sync/glue/password_model_worker.h" | 27 #include "chrome/browser/sync/glue/password_model_worker.h" |
28 #include "chrome/browser/sync/js_arg_list.h" | 28 #include "chrome/browser/sync/js_arg_list.h" |
29 #include "chrome/browser/sync/sessions/session_state.h" | 29 #include "chrome/browser/sync/sessions/session_state.h" |
30 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. | 30 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. |
31 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. | 31 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. |
32 #include "chrome/browser/sync/syncable/model_type.h" | 32 #include "chrome/browser/sync/syncable/model_type.h" |
| 33 #include "chrome/browser/sync/syncable/nigori_util.h" |
33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/chrome_version_info.h" | 35 #include "chrome/common/chrome_version_info.h" |
35 #include "chrome/common/net/gaia/gaia_constants.h" | 36 #include "chrome/common/net/gaia/gaia_constants.h" |
36 #include "chrome/common/notification_service.h" | 37 #include "chrome/common/notification_service.h" |
37 #include "chrome/common/notification_type.h" | 38 #include "chrome/common/notification_type.h" |
38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
39 #include "webkit/glue/webkit_glue.h" | 40 #include "webkit/glue/webkit_glue.h" |
40 | 41 |
41 static const int kSaveChangesIntervalSeconds = 10; | 42 static const int kSaveChangesIntervalSeconds = 10; |
42 static const FilePath::CharType kSyncDataFolderName[] = | 43 static const FilePath::CharType kSyncDataFolderName[] = |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 it != types.end(); ++it) { | 119 it != types.end(); ++it) { |
119 registrar_.routing_info[(*it)] = GROUP_PASSIVE; | 120 registrar_.routing_info[(*it)] = GROUP_PASSIVE; |
120 } | 121 } |
121 | 122 |
122 PasswordStore* password_store = | 123 PasswordStore* password_store = |
123 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 124 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); |
124 if (password_store) { | 125 if (password_store) { |
125 registrar_.workers[GROUP_PASSWORD] = | 126 registrar_.workers[GROUP_PASSWORD] = |
126 new PasswordModelWorker(password_store); | 127 new PasswordModelWorker(password_store); |
127 } else { | 128 } else { |
128 LOG(WARNING) << "Password store not initialized, cannot sync passwords"; | 129 LOG_IF(WARNING, types.count(syncable::PASSWORDS) > 0) << "Password store " |
| 130 << "not initialized, cannot sync passwords"; |
129 registrar_.routing_info.erase(syncable::PASSWORDS); | 131 registrar_.routing_info.erase(syncable::PASSWORDS); |
130 } | 132 } |
131 | 133 |
132 // TODO(tim): Remove this special case once NIGORI is populated by | 134 // Nigori is populated by default now. |
133 // default. We piggy back off of the passwords flag for now to not | 135 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; |
134 // require both encryption and passwords flags. | |
135 bool enable_encryption = !CommandLine::ForCurrentProcess()->HasSwitch( | |
136 switches::kDisableSyncPasswords) || types.count(syncable::PASSWORDS); | |
137 if (enable_encryption) | |
138 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; | |
139 | 136 |
140 InitCore(Core::DoInitializeOptions( | 137 InitCore(Core::DoInitializeOptions( |
141 sync_service_url, | 138 sync_service_url, |
142 MakeHttpBridgeFactory(baseline_context_getter), | 139 MakeHttpBridgeFactory(baseline_context_getter), |
143 credentials, | 140 credentials, |
144 delete_sync_data_folder, | 141 delete_sync_data_folder, |
145 notifier_options, | 142 notifier_options, |
146 RestoreEncryptionBootstrapToken(), | 143 RestoreEncryptionBootstrapToken(), |
147 false)); | 144 false)); |
148 } | 145 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // downloading updates for newly added data types. Once this is | 397 // downloading updates for newly added data types. Once this is |
401 // complete, the configure_ready_task_ is run via an | 398 // complete, the configure_ready_task_ is run via an |
402 // OnInitializationComplete notification. | 399 // OnInitializationComplete notification. |
403 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) { | 400 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) { |
404 // We can only nudge when we've either deleted a dataype or added one, else | 401 // We can only nudge when we've either deleted a dataype or added one, else |
405 // we break all the profile sync unit tests. | 402 // we break all the profile sync unit tests. |
406 RequestNudge(); | 403 RequestNudge(); |
407 } | 404 } |
408 } | 405 } |
409 | 406 |
| 407 void SyncBackendHost::EncryptDataTypes( |
| 408 const syncable::ModelTypeSet& encrypted_types) { |
| 409 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 410 NewRunnableMethod(core_.get(), |
| 411 &SyncBackendHost::Core::DoEncryptDataTypes, |
| 412 encrypted_types)); |
| 413 } |
| 414 |
410 void SyncBackendHost::RequestNudge() { | 415 void SyncBackendHost::RequestNudge() { |
411 core_thread_.message_loop()->PostTask(FROM_HERE, | 416 core_thread_.message_loop()->PostTask(FROM_HERE, |
412 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); | 417 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); |
413 } | 418 } |
414 | 419 |
415 void SyncBackendHost::ActivateDataType( | 420 void SyncBackendHost::ActivateDataType( |
416 DataTypeController* data_type_controller, | 421 DataTypeController* data_type_controller, |
417 ChangeProcessor* change_processor) { | 422 ChangeProcessor* change_processor) { |
418 base::AutoLock lock(registrar_lock_); | 423 base::AutoLock lock(registrar_lock_); |
419 | 424 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 if (!host_) | 509 if (!host_) |
505 return; | 510 return; |
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
507 TokenAvailableDetails details(GaiaConstants::kSyncService, token); | 512 TokenAvailableDetails details(GaiaConstants::kSyncService, token); |
508 NotificationService::current()->Notify( | 513 NotificationService::current()->Notify( |
509 NotificationType::TOKEN_UPDATED, | 514 NotificationType::TOKEN_UPDATED, |
510 NotificationService::AllSources(), | 515 NotificationService::AllSources(), |
511 Details<const TokenAvailableDetails>(&details)); | 516 Details<const TokenAvailableDetails>(&details)); |
512 } | 517 } |
513 | 518 |
| 519 void SyncBackendHost::Core::NotifyEncryptionComplete( |
| 520 const syncable::ModelTypeSet& encrypted_types) { |
| 521 if (!host_) |
| 522 return; |
| 523 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
| 524 host_->frontend_->OnEncryptionComplete(encrypted_types); |
| 525 } |
| 526 |
514 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( | 527 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( |
515 const GURL& service_url, | 528 const GURL& service_url, |
516 sync_api::HttpPostProviderFactory* http_bridge_factory, | 529 sync_api::HttpPostProviderFactory* http_bridge_factory, |
517 const sync_api::SyncCredentials& credentials, | 530 const sync_api::SyncCredentials& credentials, |
518 bool delete_sync_data_folder, | 531 bool delete_sync_data_folder, |
519 const notifier::NotifierOptions& notifier_options, | 532 const notifier::NotifierOptions& notifier_options, |
520 std::string restored_key_for_bootstrapping, | 533 std::string restored_key_for_bootstrapping, |
521 bool setup_for_test_mode) | 534 bool setup_for_test_mode) |
522 : service_url(service_url), | 535 : service_url(service_url), |
523 http_bridge_factory(http_bridge_factory), | 536 http_bridge_factory(http_bridge_factory), |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 675 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
663 syncapi_->StartSyncing(); | 676 syncapi_->StartSyncing(); |
664 } | 677 } |
665 | 678 |
666 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, | 679 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, |
667 bool is_explicit) { | 680 bool is_explicit) { |
668 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 681 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
669 syncapi_->SetPassphrase(passphrase, is_explicit); | 682 syncapi_->SetPassphrase(passphrase, is_explicit); |
670 } | 683 } |
671 | 684 |
| 685 void SyncBackendHost::Core::DoEncryptDataTypes( |
| 686 const syncable::ModelTypeSet& encrypted_types) { |
| 687 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 688 syncapi_->EncryptDataTypes(encrypted_types); |
| 689 } |
| 690 |
672 UIModelWorker* SyncBackendHost::ui_worker() { | 691 UIModelWorker* SyncBackendHost::ui_worker() { |
673 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; | 692 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; |
674 if (w == NULL) | 693 if (w == NULL) |
675 return NULL; | 694 return NULL; |
676 if (w->GetModelSafeGroup() != GROUP_UI) | 695 if (w->GetModelSafeGroup() != GROUP_UI) |
677 NOTREACHED(); | 696 NOTREACHED(); |
678 return static_cast<UIModelWorker*>(w); | 697 return static_cast<UIModelWorker*>(w); |
679 } | 698 } |
680 | 699 |
681 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 700 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 void SyncBackendHost::Core::OnClearServerDataSucceeded() { | 900 void SyncBackendHost::Core::OnClearServerDataSucceeded() { |
882 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 901 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
883 &Core::HandleClearServerDataSucceededOnFrontendLoop)); | 902 &Core::HandleClearServerDataSucceededOnFrontendLoop)); |
884 } | 903 } |
885 | 904 |
886 void SyncBackendHost::Core::OnClearServerDataFailed() { | 905 void SyncBackendHost::Core::OnClearServerDataFailed() { |
887 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 906 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
888 &Core::HandleClearServerDataFailedOnFrontendLoop)); | 907 &Core::HandleClearServerDataFailedOnFrontendLoop)); |
889 } | 908 } |
890 | 909 |
| 910 void SyncBackendHost::Core::OnEncryptionComplete( |
| 911 const syncable::ModelTypeSet& encrypted_types) { |
| 912 host_->frontend_loop_->PostTask( |
| 913 FROM_HERE, |
| 914 NewRunnableMethod(this, &Core::NotifyEncryptionComplete, |
| 915 encrypted_types)); |
| 916 } |
| 917 |
891 void SyncBackendHost::Core::RouteJsEvent( | 918 void SyncBackendHost::Core::RouteJsEvent( |
892 const std::string& name, const JsArgList& args, | 919 const std::string& name, const JsArgList& args, |
893 const JsEventHandler* target) { | 920 const JsEventHandler* target) { |
894 host_->frontend_loop_->PostTask( | 921 host_->frontend_loop_->PostTask( |
895 FROM_HERE, NewRunnableMethod( | 922 FROM_HERE, NewRunnableMethod( |
896 this, &Core::RouteJsEventOnFrontendLoop, name, args, target)); | 923 this, &Core::RouteJsEventOnFrontendLoop, name, args, target)); |
897 } | 924 } |
898 | 925 |
899 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { | 926 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { |
900 if (!host_ || !host_->frontend_) | 927 if (!host_ || !host_->frontend_) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 } | 1054 } |
1028 | 1055 |
1029 void SyncBackendHost::Core::DoProcessMessage( | 1056 void SyncBackendHost::Core::DoProcessMessage( |
1030 const std::string& name, const JsArgList& args, | 1057 const std::string& name, const JsArgList& args, |
1031 const JsEventHandler* sender) { | 1058 const JsEventHandler* sender) { |
1032 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); | 1059 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); |
1033 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); | 1060 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); |
1034 } | 1061 } |
1035 | 1062 |
1036 } // namespace browser_sync | 1063 } // namespace browser_sync |
OLD | NEW |