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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // notice that the routing info has changed and start the process of | 388 // notice that the routing info has changed and start the process of |
392 // downloading updates for newly added data types. Once this is | 389 // downloading updates for newly added data types. Once this is |
393 // complete, the configure_ready_task_ is run via an | 390 // complete, the configure_ready_task_ is run via an |
394 // OnInitializationComplete notification. | 391 // OnInitializationComplete notification. |
395 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) | 392 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) |
396 // We can only nudge when we've either deleted a dataype or added one, else | 393 // We can only nudge when we've either deleted a dataype or added one, else |
397 // we break all the profile sync unit tests. | 394 // we break all the profile sync unit tests. |
398 RequestNudge(); | 395 RequestNudge(); |
399 } | 396 } |
400 | 397 |
| 398 void SyncBackendHost::EncryptDataTypes( |
| 399 const syncable::ModelTypeSet& encrypted_types) { |
| 400 core_thread_.message_loop()->PostTask(FROM_HERE, |
| 401 NewRunnableMethod(core_.get(), |
| 402 &SyncBackendHost::Core::DoEncryptDataTypes, |
| 403 encrypted_types)); |
| 404 } |
| 405 |
401 void SyncBackendHost::RequestNudge() { | 406 void SyncBackendHost::RequestNudge() { |
402 core_thread_.message_loop()->PostTask(FROM_HERE, | 407 core_thread_.message_loop()->PostTask(FROM_HERE, |
403 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); | 408 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); |
404 } | 409 } |
405 | 410 |
406 void SyncBackendHost::ActivateDataType( | 411 void SyncBackendHost::ActivateDataType( |
407 DataTypeController* data_type_controller, | 412 DataTypeController* data_type_controller, |
408 ChangeProcessor* change_processor) { | 413 ChangeProcessor* change_processor) { |
409 base::AutoLock lock(registrar_lock_); | 414 base::AutoLock lock(registrar_lock_); |
410 | 415 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (!host_) | 500 if (!host_) |
496 return; | 501 return; |
497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
498 TokenAvailableDetails details(GaiaConstants::kSyncService, token); | 503 TokenAvailableDetails details(GaiaConstants::kSyncService, token); |
499 NotificationService::current()->Notify( | 504 NotificationService::current()->Notify( |
500 NotificationType::TOKEN_UPDATED, | 505 NotificationType::TOKEN_UPDATED, |
501 NotificationService::AllSources(), | 506 NotificationService::AllSources(), |
502 Details<const TokenAvailableDetails>(&details)); | 507 Details<const TokenAvailableDetails>(&details)); |
503 } | 508 } |
504 | 509 |
| 510 void SyncBackendHost::Core::NotifyEncryptionComplete( |
| 511 const syncable::ModelTypeSet& encrypted_types) { |
| 512 if (!host_) |
| 513 return; |
| 514 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
| 515 host_->frontend_->OnEncryptionComplete(encrypted_types); |
| 516 } |
| 517 |
505 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( | 518 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( |
506 const GURL& service_url, | 519 const GURL& service_url, |
507 sync_api::HttpPostProviderFactory* http_bridge_factory, | 520 sync_api::HttpPostProviderFactory* http_bridge_factory, |
508 const sync_api::SyncCredentials& credentials, | 521 const sync_api::SyncCredentials& credentials, |
509 bool delete_sync_data_folder, | 522 bool delete_sync_data_folder, |
510 const notifier::NotifierOptions& notifier_options, | 523 const notifier::NotifierOptions& notifier_options, |
511 std::string restored_key_for_bootstrapping, | 524 std::string restored_key_for_bootstrapping, |
512 bool setup_for_test_mode) | 525 bool setup_for_test_mode) |
513 : service_url(service_url), | 526 : service_url(service_url), |
514 http_bridge_factory(http_bridge_factory), | 527 http_bridge_factory(http_bridge_factory), |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 659 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
647 syncapi_->StartSyncing(); | 660 syncapi_->StartSyncing(); |
648 } | 661 } |
649 | 662 |
650 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, | 663 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, |
651 bool is_explicit) { | 664 bool is_explicit) { |
652 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); | 665 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
653 syncapi_->SetPassphrase(passphrase, is_explicit); | 666 syncapi_->SetPassphrase(passphrase, is_explicit); |
654 } | 667 } |
655 | 668 |
| 669 void SyncBackendHost::Core::DoEncryptDataTypes( |
| 670 const syncable::ModelTypeSet& encrypted_types) { |
| 671 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); |
| 672 syncapi_->EncryptDataTypes(encrypted_types); |
| 673 } |
| 674 |
656 UIModelWorker* SyncBackendHost::ui_worker() { | 675 UIModelWorker* SyncBackendHost::ui_worker() { |
657 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; | 676 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; |
658 if (w == NULL) | 677 if (w == NULL) |
659 return NULL; | 678 return NULL; |
660 if (w->GetModelSafeGroup() != GROUP_UI) | 679 if (w->GetModelSafeGroup() != GROUP_UI) |
661 NOTREACHED(); | 680 NOTREACHED(); |
662 return static_cast<UIModelWorker*>(w); | 681 return static_cast<UIModelWorker*>(w); |
663 } | 682 } |
664 | 683 |
665 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 684 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 void SyncBackendHost::Core::OnClearServerDataSucceeded() { | 884 void SyncBackendHost::Core::OnClearServerDataSucceeded() { |
866 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 885 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
867 &Core::HandleClearServerDataSucceededOnFrontendLoop)); | 886 &Core::HandleClearServerDataSucceededOnFrontendLoop)); |
868 } | 887 } |
869 | 888 |
870 void SyncBackendHost::Core::OnClearServerDataFailed() { | 889 void SyncBackendHost::Core::OnClearServerDataFailed() { |
871 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 890 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
872 &Core::HandleClearServerDataFailedOnFrontendLoop)); | 891 &Core::HandleClearServerDataFailedOnFrontendLoop)); |
873 } | 892 } |
874 | 893 |
| 894 void SyncBackendHost::Core::OnEncryptionComplete( |
| 895 const syncable::ModelTypeSet& encrypted_types) { |
| 896 host_->frontend_loop_->PostTask( |
| 897 FROM_HERE, |
| 898 NewRunnableMethod(this, &Core::NotifyEncryptionComplete, |
| 899 encrypted_types)); |
| 900 } |
| 901 |
875 void SyncBackendHost::Core::RouteJsEvent( | 902 void SyncBackendHost::Core::RouteJsEvent( |
876 const std::string& name, const JsArgList& args, | 903 const std::string& name, const JsArgList& args, |
877 const JsEventHandler* target) { | 904 const JsEventHandler* target) { |
878 host_->frontend_loop_->PostTask( | 905 host_->frontend_loop_->PostTask( |
879 FROM_HERE, NewRunnableMethod( | 906 FROM_HERE, NewRunnableMethod( |
880 this, &Core::RouteJsEventOnFrontendLoop, name, args, target)); | 907 this, &Core::RouteJsEventOnFrontendLoop, name, args, target)); |
881 } | 908 } |
882 | 909 |
883 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { | 910 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { |
884 if (!host_ || !host_->frontend_) | 911 if (!host_ || !host_->frontend_) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 } | 1032 } |
1006 | 1033 |
1007 void SyncBackendHost::Core::DoProcessMessage( | 1034 void SyncBackendHost::Core::DoProcessMessage( |
1008 const std::string& name, const JsArgList& args, | 1035 const std::string& name, const JsArgList& args, |
1009 const JsEventHandler* sender) { | 1036 const JsEventHandler* sender) { |
1010 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); | 1037 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); |
1011 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); | 1038 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); |
1012 } | 1039 } |
1013 | 1040 |
1014 } // namespace browser_sync | 1041 } // namespace browser_sync |
OLD | NEW |