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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 6465005: [Sync] Initial support for encrypting any datatype (no UI hookup yet). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 9 years, 10 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) 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 11 matching lines...) Expand all
22 #include "chrome/browser/sync/glue/change_processor.h" 22 #include "chrome/browser/sync/glue/change_processor.h"
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/sessions/session_state.h" 28 #include "chrome/browser/sync/sessions/session_state.h"
29 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. 29 // TODO(tim): Remove this! We should have a syncapi pass-thru instead.
30 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. 30 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer.
31 #include "chrome/browser/sync/syncable/model_type.h" 31 #include "chrome/browser/sync/syncable/model_type.h"
32 #include "chrome/browser/sync/syncable/nigori_util.h"
32 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/chrome_version_info.h" 34 #include "chrome/common/chrome_version_info.h"
34 #include "chrome/common/net/gaia/gaia_constants.h" 35 #include "chrome/common/net/gaia/gaia_constants.h"
35 #include "chrome/common/notification_service.h" 36 #include "chrome/common/notification_service.h"
36 #include "chrome/common/notification_type.h" 37 #include "chrome/common/notification_type.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "webkit/glue/webkit_glue.h" 39 #include "webkit/glue/webkit_glue.h"
39 40
40 static const int kSaveChangesIntervalSeconds = 10; 41 static const int kSaveChangesIntervalSeconds = 10;
41 static const FilePath::CharType kSyncDataFolderName[] = 42 static const FilePath::CharType kSyncDataFolderName[] =
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 121 }
121 122
122 // Any datatypes that we want the syncer to pull down must 123 // Any datatypes that we want the syncer to pull down must
123 // be in the routing_info map. We set them to group passive, meaning that 124 // be in the routing_info map. We set them to group passive, meaning that
124 // updates will be applied, but not dispatched to the UI thread yet. 125 // updates will be applied, but not dispatched to the UI thread yet.
125 for (syncable::ModelTypeSet::const_iterator it = types.begin(); 126 for (syncable::ModelTypeSet::const_iterator it = types.begin();
126 it != types.end(); ++it) { 127 it != types.end(); ++it) {
127 registrar_.routing_info[(*it)] = GROUP_PASSIVE; 128 registrar_.routing_info[(*it)] = GROUP_PASSIVE;
128 } 129 }
129 130
130 // TODO(tim): Remove this special case once NIGORI is populated by 131 // Nigori is populated by default now.
131 // default. We piggy back off of the passwords flag for now to not 132 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE;
132 // require both encryption and passwords flags.
133 bool enable_encryption = !CommandLine::ForCurrentProcess()->HasSwitch(
134 switches::kDisableSyncPasswords) || types.count(syncable::PASSWORDS);
135 if (enable_encryption)
136 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE;
137 133
138 InitCore(Core::DoInitializeOptions( 134 InitCore(Core::DoInitializeOptions(
139 sync_service_url, 135 sync_service_url,
140 MakeHttpBridgeFactory(baseline_context_getter), 136 MakeHttpBridgeFactory(baseline_context_getter),
141 credentials, 137 credentials,
142 delete_sync_data_folder, 138 delete_sync_data_folder,
143 notifier_options, 139 notifier_options,
144 RestoreEncryptionBootstrapToken(), 140 RestoreEncryptionBootstrapToken(),
145 false)); 141 false));
146 } 142 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // notice that the routing info has changed and start the process of 376 // notice that the routing info has changed and start the process of
381 // downloading updates for newly added data types. Once this is 377 // downloading updates for newly added data types. Once this is
382 // complete, the configure_ready_task_ is run via an 378 // complete, the configure_ready_task_ is run via an
383 // OnInitializationComplete notification. 379 // OnInitializationComplete notification.
384 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) 380 if (deleted_type || !core_->syncapi()->InitialSyncEndedForAllEnabledTypes())
385 // We can only nudge when we've either deleted a dataype or added one, else 381 // We can only nudge when we've either deleted a dataype or added one, else
386 // we break all the profile sync unit tests. 382 // we break all the profile sync unit tests.
387 RequestNudge(); 383 RequestNudge();
388 } 384 }
389 385
386 void SyncBackendHost::EncryptDataTypes(
387 const syncable::ModelTypeSet& encrypted_types) {
388 core_thread_.message_loop()->PostTask(FROM_HERE,
389 NewRunnableMethod(core_.get(),
390 &SyncBackendHost::Core::DoEncryptDataTypes,
391 encrypted_types));
392 }
393
390 void SyncBackendHost::RequestNudge() { 394 void SyncBackendHost::RequestNudge() {
391 core_thread_.message_loop()->PostTask(FROM_HERE, 395 core_thread_.message_loop()->PostTask(FROM_HERE,
392 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); 396 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge));
393 } 397 }
394 398
395 void SyncBackendHost::ActivateDataType( 399 void SyncBackendHost::ActivateDataType(
396 DataTypeController* data_type_controller, 400 DataTypeController* data_type_controller,
397 ChangeProcessor* change_processor) { 401 ChangeProcessor* change_processor) {
398 base::AutoLock lock(registrar_lock_); 402 base::AutoLock lock(registrar_lock_);
399 403
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 if (!host_) 488 if (!host_)
485 return; 489 return;
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487 TokenAvailableDetails details(GaiaConstants::kSyncService, token); 491 TokenAvailableDetails details(GaiaConstants::kSyncService, token);
488 NotificationService::current()->Notify( 492 NotificationService::current()->Notify(
489 NotificationType::TOKEN_UPDATED, 493 NotificationType::TOKEN_UPDATED,
490 NotificationService::AllSources(), 494 NotificationService::AllSources(),
491 Details<const TokenAvailableDetails>(&details)); 495 Details<const TokenAvailableDetails>(&details));
492 } 496 }
493 497
498 void SyncBackendHost::Core::NotifyEncryptionComplete(
499 const syncable::ModelTypeSet& encrypted_types) {
500 if (!host_)
501 return;
502 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
503 host_->frontend_->OnEncryptionComplete(encrypted_types);
504 }
505
494 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions( 506 SyncBackendHost::Core::DoInitializeOptions::DoInitializeOptions(
495 const GURL& service_url, 507 const GURL& service_url,
496 sync_api::HttpPostProviderFactory* http_bridge_factory, 508 sync_api::HttpPostProviderFactory* http_bridge_factory,
497 const sync_api::SyncCredentials& credentials, 509 const sync_api::SyncCredentials& credentials,
498 bool delete_sync_data_folder, 510 bool delete_sync_data_folder,
499 const notifier::NotifierOptions& notifier_options, 511 const notifier::NotifierOptions& notifier_options,
500 std::string restored_key_for_bootstrapping, 512 std::string restored_key_for_bootstrapping,
501 bool setup_for_test_mode) 513 bool setup_for_test_mode)
502 : service_url(service_url), 514 : service_url(service_url),
503 http_bridge_factory(http_bridge_factory), 515 http_bridge_factory(http_bridge_factory),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); 646 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop());
635 syncapi_->StartSyncing(); 647 syncapi_->StartSyncing();
636 } 648 }
637 649
638 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, 650 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase,
639 bool is_explicit) { 651 bool is_explicit) {
640 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); 652 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop());
641 syncapi_->SetPassphrase(passphrase, is_explicit); 653 syncapi_->SetPassphrase(passphrase, is_explicit);
642 } 654 }
643 655
656 void SyncBackendHost::Core::DoEncryptDataTypes(
657 const syncable::ModelTypeSet& encrypted_types) {
658 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop());
659 syncapi_->EncryptDataTypes(encrypted_types);
660 }
661
644 UIModelWorker* SyncBackendHost::ui_worker() { 662 UIModelWorker* SyncBackendHost::ui_worker() {
645 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; 663 ModelSafeWorker* w = registrar_.workers[GROUP_UI];
646 if (w == NULL) 664 if (w == NULL)
647 return NULL; 665 return NULL;
648 if (w->GetModelSafeGroup() != GROUP_UI) 666 if (w->GetModelSafeGroup() != GROUP_UI)
649 NOTREACHED(); 667 NOTREACHED();
650 return static_cast<UIModelWorker*>(w); 668 return static_cast<UIModelWorker*>(w);
651 } 669 }
652 670
653 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 671 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 void SyncBackendHost::Core::OnClearServerDataSucceeded() { 871 void SyncBackendHost::Core::OnClearServerDataSucceeded() {
854 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 872 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
855 &Core::HandleClearServerDataSucceededOnFrontendLoop)); 873 &Core::HandleClearServerDataSucceededOnFrontendLoop));
856 } 874 }
857 875
858 void SyncBackendHost::Core::OnClearServerDataFailed() { 876 void SyncBackendHost::Core::OnClearServerDataFailed() {
859 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 877 host_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
860 &Core::HandleClearServerDataFailedOnFrontendLoop)); 878 &Core::HandleClearServerDataFailedOnFrontendLoop));
861 } 879 }
862 880
881 void SyncBackendHost::Core::OnEncryptionComplete(
882 const syncable::ModelTypeSet& encrypted_types) {
883 host_->frontend_loop_->PostTask(
884 FROM_HERE,
885 NewRunnableMethod(this, &Core::NotifyEncryptionComplete,
886 encrypted_types));
887 }
888
863 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { 889 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() {
864 if (!host_ || !host_->frontend_) 890 if (!host_ || !host_->frontend_)
865 return; 891 return;
866 host_->frontend_->OnStopSyncingPermanently(); 892 host_->frontend_->OnStopSyncingPermanently();
867 } 893 }
868 894
869 void SyncBackendHost::Core::HandleClearServerDataSucceededOnFrontendLoop() { 895 void SyncBackendHost::Core::HandleClearServerDataSucceededOnFrontendLoop() {
870 if (!host_ || !host_->frontend_) 896 if (!host_ || !host_->frontend_)
871 return; 897 return;
872 host_->frontend_->OnClearServerDataSucceeded(); 898 host_->frontend_->OnClearServerDataSucceeded();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 } 942 }
917 943
918 void SyncBackendHost::Core::DeleteSyncDataFolder() { 944 void SyncBackendHost::Core::DeleteSyncDataFolder() {
919 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { 945 if (file_util::DirectoryExists(host_->sync_data_folder_path())) {
920 if (!file_util::Delete(host_->sync_data_folder_path(), true)) 946 if (!file_util::Delete(host_->sync_data_folder_path(), true))
921 LOG(DFATAL) << "Could not delete the Sync Data folder."; 947 LOG(DFATAL) << "Could not delete the Sync Data folder.";
922 } 948 }
923 } 949 }
924 950
925 } // namespace browser_sync 951 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698