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

Side by Side Diff: sync/internal_api/sync_manager.cc

Issue 10540149: [Sync] Persist keystore key across restarts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 HttpPostProviderFactory* post_factory, 198 HttpPostProviderFactory* post_factory,
199 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info, 199 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info,
200 const std::vector<browser_sync::ModelSafeWorker*>& workers, 200 const std::vector<browser_sync::ModelSafeWorker*>& workers,
201 browser_sync::ExtensionsActivityMonitor* 201 browser_sync::ExtensionsActivityMonitor*
202 extensions_activity_monitor, 202 extensions_activity_monitor,
203 ChangeDelegate* change_delegate, 203 ChangeDelegate* change_delegate,
204 const std::string& user_agent, 204 const std::string& user_agent,
205 const SyncCredentials& credentials, 205 const SyncCredentials& credentials,
206 sync_notifier::SyncNotifier* sync_notifier, 206 sync_notifier::SyncNotifier* sync_notifier,
207 const std::string& restored_key_for_bootstrapping, 207 const std::string& restored_key_for_bootstrapping,
208 const std::string& restored_keystore_key_for_bootstrapping,
208 bool keystore_encryption_enabled, 209 bool keystore_encryption_enabled,
209 TestingMode testing_mode, 210 TestingMode testing_mode,
210 Encryptor* encryptor, 211 Encryptor* encryptor,
211 UnrecoverableErrorHandler* unrecoverable_error_handler, 212 UnrecoverableErrorHandler* unrecoverable_error_handler,
212 ReportUnrecoverableErrorFunction 213 ReportUnrecoverableErrorFunction
213 report_unrecoverable_error_function); 214 report_unrecoverable_error_function);
214 215
215 // Sign into sync with given credentials. 216 // Sign into sync with given credentials.
216 // We do not verify the tokens given. After this call, the tokens are set 217 // We do not verify the tokens given. After this call, the tokens are set
217 // and the sync DB is open. True if successful, false if something 218 // and the sync DB is open. True if successful, false if something
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 744 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
744 HttpPostProviderFactory* post_factory, 745 HttpPostProviderFactory* post_factory,
745 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info, 746 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info,
746 const std::vector<browser_sync::ModelSafeWorker*>& workers, 747 const std::vector<browser_sync::ModelSafeWorker*>& workers,
747 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor, 748 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor,
748 ChangeDelegate* change_delegate, 749 ChangeDelegate* change_delegate,
749 const std::string& user_agent, 750 const std::string& user_agent,
750 const SyncCredentials& credentials, 751 const SyncCredentials& credentials,
751 sync_notifier::SyncNotifier* sync_notifier, 752 sync_notifier::SyncNotifier* sync_notifier,
752 const std::string& restored_key_for_bootstrapping, 753 const std::string& restored_key_for_bootstrapping,
754 const std::string& restored_keystore_key_for_bootstrapping,
753 bool keystore_encryption_enabled, 755 bool keystore_encryption_enabled,
754 TestingMode testing_mode, 756 TestingMode testing_mode,
755 Encryptor* encryptor, 757 Encryptor* encryptor,
756 UnrecoverableErrorHandler* unrecoverable_error_handler, 758 UnrecoverableErrorHandler* unrecoverable_error_handler,
757 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { 759 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) {
758 DCHECK(thread_checker_.CalledOnValidThread()); 760 DCHECK(thread_checker_.CalledOnValidThread());
759 DCHECK(post_factory); 761 DCHECK(post_factory);
760 DVLOG(1) << "SyncManager starting Init..."; 762 DVLOG(1) << "SyncManager starting Init...";
761 std::string server_string(sync_server_and_path); 763 std::string server_string(sync_server_and_path);
762 return data_->Init(database_location, 764 return data_->Init(database_location,
763 event_handler, 765 event_handler,
764 server_string, 766 server_string,
765 sync_server_port, 767 sync_server_port,
766 use_ssl, 768 use_ssl,
767 blocking_task_runner, 769 blocking_task_runner,
768 post_factory, 770 post_factory,
769 model_safe_routing_info, 771 model_safe_routing_info,
770 workers, 772 workers,
771 extensions_activity_monitor, 773 extensions_activity_monitor,
772 change_delegate, 774 change_delegate,
773 user_agent, 775 user_agent,
774 credentials, 776 credentials,
775 sync_notifier, 777 sync_notifier,
776 restored_key_for_bootstrapping, 778 restored_key_for_bootstrapping,
779 restored_keystore_key_for_bootstrapping,
777 keystore_encryption_enabled, 780 keystore_encryption_enabled,
778 testing_mode, 781 testing_mode,
779 encryptor, 782 encryptor,
780 unrecoverable_error_handler, 783 unrecoverable_error_handler,
781 report_unrecoverable_error_function); 784 report_unrecoverable_error_function);
782 } 785 }
783 786
784 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { 787 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) {
785 DCHECK(thread_checker_.CalledOnValidThread()); 788 DCHECK(thread_checker_.CalledOnValidThread());
786 data_->UpdateCredentials(credentials); 789 data_->UpdateCredentials(credentials);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 842
840 bool SyncManager::EncryptEverythingEnabledForTest() const { 843 bool SyncManager::EncryptEverythingEnabledForTest() const {
841 ReadTransaction trans(FROM_HERE, GetUserShare()); 844 ReadTransaction trans(FROM_HERE, GetUserShare());
842 return trans.GetCryptographer()->encrypt_everything(); 845 return trans.GetCryptographer()->encrypt_everything();
843 } 846 }
844 847
845 bool SyncManager::IsUsingExplicitPassphrase() { 848 bool SyncManager::IsUsingExplicitPassphrase() {
846 return data_ && data_->IsUsingExplicitPassphrase(); 849 return data_ && data_->IsUsingExplicitPassphrase();
847 } 850 }
848 851
852 bool SyncManager::GetKeystoreKeyBootstrapToken(std::string* token) {
853 ReadTransaction trans(FROM_HERE, GetUserShare());
854 return trans.GetCryptographer()->GetKeystoreKeyBootstrapToken(token);
855 }
856
849 void SyncManager::RequestClearServerData() { 857 void SyncManager::RequestClearServerData() {
850 DCHECK(thread_checker_.CalledOnValidThread()); 858 DCHECK(thread_checker_.CalledOnValidThread());
851 if (data_->scheduler()) 859 if (data_->scheduler())
852 data_->scheduler()->ClearUserData(); 860 data_->scheduler()->ClearUserData();
853 } 861 }
854 862
855 void SyncManager::ConfigureSyncer( 863 void SyncManager::ConfigureSyncer(
856 ConfigureReason reason, 864 ConfigureReason reason,
857 const syncable::ModelTypeSet& types_to_config, 865 const syncable::ModelTypeSet& types_to_config,
858 const browser_sync::ModelSafeRoutingInfo& new_routing_info, 866 const browser_sync::ModelSafeRoutingInfo& new_routing_info,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 912 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
905 HttpPostProviderFactory* post_factory, 913 HttpPostProviderFactory* post_factory,
906 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info, 914 const browser_sync::ModelSafeRoutingInfo& model_safe_routing_info,
907 const std::vector<browser_sync::ModelSafeWorker*>& workers, 915 const std::vector<browser_sync::ModelSafeWorker*>& workers,
908 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor, 916 browser_sync::ExtensionsActivityMonitor* extensions_activity_monitor,
909 ChangeDelegate* change_delegate, 917 ChangeDelegate* change_delegate,
910 const std::string& user_agent, 918 const std::string& user_agent,
911 const SyncCredentials& credentials, 919 const SyncCredentials& credentials,
912 sync_notifier::SyncNotifier* sync_notifier, 920 sync_notifier::SyncNotifier* sync_notifier,
913 const std::string& restored_key_for_bootstrapping, 921 const std::string& restored_key_for_bootstrapping,
922 const std::string& restored_keystore_key_for_bootstrapping,
914 bool keystore_encryption_enabled, 923 bool keystore_encryption_enabled,
915 TestingMode testing_mode, 924 TestingMode testing_mode,
916 Encryptor* encryptor, 925 Encryptor* encryptor,
917 UnrecoverableErrorHandler* unrecoverable_error_handler, 926 UnrecoverableErrorHandler* unrecoverable_error_handler,
918 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { 927 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) {
919 CHECK(!initialized_); 928 CHECK(!initialized_);
920 929
921 DCHECK(thread_checker_.CalledOnValidThread()); 930 DCHECK(thread_checker_.CalledOnValidThread());
922 931
923 DVLOG(1) << "Starting SyncInternal initialization."; 932 DVLOG(1) << "Starting SyncInternal initialization.";
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 } 992 }
984 993
985 initialized_ = true; 994 initialized_ = true;
986 995
987 // Cryptographer should only be accessed while holding a 996 // Cryptographer should only be accessed while holding a
988 // transaction. Grabbing the user share for the transaction 997 // transaction. Grabbing the user share for the transaction
989 // checks the initialization state, so this must come after 998 // checks the initialization state, so this must come after
990 // |initialized_| is set to true. 999 // |initialized_| is set to true.
991 ReadTransaction trans(FROM_HERE, GetUserShare()); 1000 ReadTransaction trans(FROM_HERE, GetUserShare());
992 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); 1001 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping);
1002 trans.GetCryptographer()->BootstrapKeystoreKey(
1003 restored_keystore_key_for_bootstrapping);
993 trans.GetCryptographer()->AddObserver(this); 1004 trans.GetCryptographer()->AddObserver(this);
994 } 1005 }
995 1006
996 // Notify that initialization is complete. Note: This should be the last to 1007 // Notify that initialization is complete. Note: This should be the last to
997 // execute if |signed_in| is false. Reason being in that case we would 1008 // execute if |signed_in| is false. Reason being in that case we would
998 // post a task to shutdown sync. But if this function posts any other tasks 1009 // post a task to shutdown sync. But if this function posts any other tasks
999 // on the UI thread and if shutdown wins then that tasks would execute on 1010 // on the UI thread and if shutdown wins then that tasks would execute on
1000 // a freed pointer. This is because UI thread is not shut down. 1011 // a freed pointer. This is because UI thread is not shut down.
1001 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1012 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1002 OnInitializationComplete( 1013 OnInitializationComplete(
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 share->directory->GetDownloadProgress(i.Get(), &marker); 2529 share->directory->GetDownloadProgress(i.Get(), &marker);
2519 2530
2520 if (marker.token().empty()) 2531 if (marker.token().empty())
2521 result.Put(i.Get()); 2532 result.Put(i.Get());
2522 2533
2523 } 2534 }
2524 return result; 2535 return result;
2525 } 2536 }
2526 2537
2527 } // namespace sync_api 2538 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698