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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 9956097: suppress user/password dialog when re-enabling sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve Drew's comments. Created 8 years, 8 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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 22 matching lines...) Expand all
33 #include "chrome/browser/sync/api/sync_error.h" 33 #include "chrome/browser/sync/api/sync_error.h"
34 #include "chrome/browser/sync/backend_migrator.h" 34 #include "chrome/browser/sync/backend_migrator.h"
35 #include "chrome/browser/sync/glue/change_processor.h" 35 #include "chrome/browser/sync/glue/change_processor.h"
36 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" 36 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
37 #include "chrome/browser/sync/glue/data_type_controller.h" 37 #include "chrome/browser/sync/glue/data_type_controller.h"
38 #include "chrome/browser/sync/glue/session_data_type_controller.h" 38 #include "chrome/browser/sync/glue/session_data_type_controller.h"
39 #include "chrome/browser/sync/glue/session_model_associator.h" 39 #include "chrome/browser/sync/glue/session_model_associator.h"
40 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" 40 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
41 #include "chrome/browser/sync/internal_api/configure_reason.h" 41 #include "chrome/browser/sync/internal_api/configure_reason.h"
42 #include "chrome/browser/sync/internal_api/sync_manager.h" 42 #include "chrome/browser/sync/internal_api/sync_manager.h"
43 #include "chrome/browser/sync/internal_api/write_node.h"
44 #include "chrome/browser/sync/internal_api/write_transaction.h"
43 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" 45 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
44 #include "chrome/browser/sync/sync_global_error.h" 46 #include "chrome/browser/sync/sync_global_error.h"
45 #include "chrome/browser/sync/user_selectable_sync_type.h" 47 #include "chrome/browser/sync/user_selectable_sync_type.h"
46 #include "chrome/browser/ui/browser.h" 48 #include "chrome/browser/ui/browser.h"
47 #include "chrome/browser/ui/browser_list.h" 49 #include "chrome/browser/ui/browser_list.h"
48 #include "chrome/browser/ui/browser_window.h" 50 #include "chrome/browser/ui/browser_window.h"
49 #include "chrome/browser/ui/global_error_service.h" 51 #include "chrome/browser/ui/global_error_service.h"
50 #include "chrome/browser/ui/global_error_service_factory.h" 52 #include "chrome/browser/ui/global_error_service_factory.h"
51 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 53 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
52 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 54 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 196
195 RegisterAuthNotifications(); 197 RegisterAuthNotifications();
196 198
197 if (!HasSyncSetupCompleted()) 199 if (!HasSyncSetupCompleted())
198 DisableForUser(); // Clean up in case of previous crash / setup abort. 200 DisableForUser(); // Clean up in case of previous crash / setup abort.
199 201
200 TryStart(); 202 TryStart();
201 } 203 }
202 204
203 void ProfileSyncService::TryStart() { 205 void ProfileSyncService::TryStart() {
206 LOG(WARNING) << "TryStart";
204 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) { 207 if (!sync_prefs_.IsStartSuppressed() && AreCredentialsAvailable()) {
205 if (HasSyncSetupCompleted() || auto_start_enabled_) { 208 if (HasSyncSetupCompleted() || auto_start_enabled_) {
206 // If sync setup has completed we always start the backend. 209 // If sync setup has completed we always start the backend.
207 // If autostart is enabled, but we haven't completed sync setup, we try to 210 // If autostart is enabled, but we haven't completed sync setup, we try to
208 // start sync anyway, since it's possible we crashed/shutdown after 211 // start sync anyway, since it's possible we crashed/shutdown after
209 // logging in but before the backend finished initializing the last time. 212 // logging in but before the backend finished initializing the last time.
210 // Note that if we haven't finished setting up sync, backend bring up will 213 // Note that if we haven't finished setting up sync, backend bring up will
211 // be done by the wizard. 214 // be done by the wizard.
212 StartUp(); 215 StartUp();
213 } 216 }
214 } else if (HasSyncSetupCompleted()) { 217 } else if (HasSyncSetupCompleted()) {
215 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 218 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
216 if (token_service && token_service->TokensLoadedFromDB() && 219 if (token_service && token_service->TokensLoadedFromDB() &&
217 !AreCredentialsAvailable()) { 220 !AreCredentialsAvailable()) {
218 // The token service has lost sync's tokens. We cannot recover from this 221 // The token service has lost sync's tokens. We cannot recover from this
219 // without signing back in, which is not yet supported. For now, we 222 // without signing back in, which is not yet supported. For now, we
220 // trigger an unrecoverable error. 223 // trigger an unrecoverable error.
221 OnUnrecoverableError(FROM_HERE, "Sync credentials lost."); 224 OnUnrecoverableError(FROM_HERE, "Sync credentials lost.");
222 } 225 }
226 } else {
227 LOG(WARNING) << "TryStart: did nothing.";
223 } 228 }
224 } 229 }
225 230
226 void ProfileSyncService::RegisterAuthNotifications() { 231 void ProfileSyncService::RegisterAuthNotifications() {
227 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 232 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
228 registrar_.Add(this, 233 registrar_.Add(this,
229 chrome::NOTIFICATION_TOKEN_AVAILABLE, 234 chrome::NOTIFICATION_TOKEN_AVAILABLE,
230 content::Source<TokenService>(token_service)); 235 content::Source<TokenService>(token_service));
231 registrar_.Add(this, 236 registrar_.Add(this,
232 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, 237 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 scoped_refptr<net::URLRequestContextGetter> request_context_getter( 330 scoped_refptr<net::URLRequestContextGetter> request_context_getter(
326 profile_->GetRequestContext()); 331 profile_->GetRequestContext());
327 332
328 if (delete_stale_data) 333 if (delete_stale_data)
329 ClearStaleErrors(); 334 ClearStaleErrors();
330 335
331 backend_unrecoverable_error_handler_.reset( 336 backend_unrecoverable_error_handler_.reset(
332 new browser_sync::BackendUnrecoverableErrorHandler( 337 new browser_sync::BackendUnrecoverableErrorHandler(
333 MakeWeakHandle(AsWeakPtr()))); 338 MakeWeakHandle(AsWeakPtr())));
334 339
340 LOG(WARNING) << "Initializing backend";
335 backend_->Initialize( 341 backend_->Initialize(
336 this, 342 this,
337 MakeWeakHandle(sync_js_controller_.AsWeakPtr()), 343 MakeWeakHandle(sync_js_controller_.AsWeakPtr()),
338 sync_service_url_, 344 sync_service_url_,
339 initial_types, 345 initial_types,
340 credentials, 346 credentials,
341 delete_stale_data, 347 delete_stale_data,
342 backend_unrecoverable_error_handler_.get(), 348 backend_unrecoverable_error_handler_.get(),
343 &browser_sync::ChromeReportUnrecoverableError); 349 &browser_sync::ChromeReportUnrecoverableError);
344 } 350 }
345 351
346 void ProfileSyncService::CreateBackend() { 352 void ProfileSyncService::CreateBackend() {
353 LOG(WARNING) << "CreateBackend";
347 backend_.reset( 354 backend_.reset(
348 new SyncBackendHost(profile_->GetDebugName(), 355 new SyncBackendHost(profile_->GetDebugName(),
349 profile_, sync_prefs_.AsWeakPtr())); 356 profile_, sync_prefs_.AsWeakPtr()));
350 } 357 }
351 358
352 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 359 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
353 if (encryption_pending()) 360 if (encryption_pending())
354 return true; 361 return true;
355 const syncable::ModelTypeSet preferred_types = GetPreferredDataTypes(); 362 const syncable::ModelTypeSet preferred_types = GetPreferredDataTypes();
356 const syncable::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 363 const syncable::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 619 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
613 FailedDatatypesHandler::RUNTIME); 620 FailedDatatypesHandler::RUNTIME);
614 621
615 MessageLoop::current()->PostTask(FROM_HERE, 622 MessageLoop::current()->PostTask(FROM_HERE,
616 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 623 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
617 weak_factory_.GetWeakPtr())); 624 weak_factory_.GetWeakPtr()));
618 } 625 }
619 626
620 void ProfileSyncService::OnBackendInitialized( 627 void ProfileSyncService::OnBackendInitialized(
621 const WeakHandle<JsBackend>& js_backend, bool success) { 628 const WeakHandle<JsBackend>& js_backend, bool success) {
629 LOG(WARNING) << "OnBackendInitialized() : " << success;
622 if (!HasSyncSetupCompleted()) { 630 if (!HasSyncSetupCompleted()) {
623 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 631 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
624 } else { 632 } else {
625 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 633 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
626 } 634 }
627 635
628 if (!success) { 636 if (!success) {
629 // Something went unexpectedly wrong. Play it safe: nuke our current state 637 // Something went unexpectedly wrong. Play it safe: nuke our current state
630 // and prepare ourselves to try again later. 638 // and prepare ourselves to try again later.
631 DisableForUser(); 639 DisableForUser();
(...skipping 26 matching lines...) Expand all
658 } 666 }
659 667
660 if (HasSyncSetupCompleted()) { 668 if (HasSyncSetupCompleted()) {
661 ConfigureDataTypeManager(); 669 ConfigureDataTypeManager();
662 } else { 670 } else {
663 DCHECK(FirstSetupInProgress()); 671 DCHECK(FirstSetupInProgress());
664 } 672 }
665 } 673 }
666 674
667 void ProfileSyncService::OnSyncCycleCompleted() { 675 void ProfileSyncService::OnSyncCycleCompleted() {
676 LOG(WARNING) << "OnSyncCycleCompleted";
668 UpdateLastSyncedTime(); 677 UpdateLastSyncedTime();
669 if (GetSessionModelAssociator()) { 678 if (GetSessionModelAssociator()) {
670 // Trigger garbage collection of old sessions now that we've downloaded 679 // Trigger garbage collection of old sessions now that we've downloaded
671 // any new session data. TODO(zea): Have this be a notification the session 680 // any new session data. TODO(zea): Have this be a notification the session
672 // model associator listens too. Also consider somehow plumbing the current 681 // model associator listens too. Also consider somehow plumbing the current
673 // server time as last reported by CheckServerReachable, so we don't have to 682 // server time as last reported by CheckServerReachable, so we don't have to
674 // rely on the local clock, which may be off significantly. 683 // rely on the local clock, which may be off significantly.
675 MessageLoop::current()->PostTask(FROM_HERE, 684 MessageLoop::current()->PostTask(FROM_HERE,
676 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, 685 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions,
677 GetSessionModelAssociator()->AsWeakPtr())); 686 GetSessionModelAssociator()->AsWeakPtr()));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 default: 779 default:
771 NOTREACHED(); 780 NOTREACHED();
772 return GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED); 781 return GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED);
773 } 782 }
774 } 783 }
775 784
776 } // namespace 785 } // namespace
777 786
778 void ProfileSyncService::OnConnectionStatusChange( 787 void ProfileSyncService::OnConnectionStatusChange(
779 sync_api::ConnectionStatus status) { 788 sync_api::ConnectionStatus status) {
789 LOG(WARNING) << "OnConnectionStatusChange";
780 UpdateAuthErrorState(ConnectionStatusToAuthError(status)); 790 UpdateAuthErrorState(ConnectionStatusToAuthError(status));
781 } 791 }
782 792
783 void ProfileSyncService::OnStopSyncingPermanently() { 793 void ProfileSyncService::OnStopSyncingPermanently() {
794 LOG(WARNING) << "OnStopSyncingPermanently";
784 UpdateAuthErrorState( 795 UpdateAuthErrorState(
785 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); 796 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
786 sync_prefs_.SetStartSuppressed(true); 797 sync_prefs_.SetStartSuppressed(true);
787 DisableForUser(); 798 DisableForUser();
788 } 799 }
789 800
790 void ProfileSyncService::OnClearServerDataTimeout() { 801 void ProfileSyncService::OnClearServerDataTimeout() {
802 LOG(WARNING) << "OnClearServerDataTimeout";
791 if (clear_server_data_state_ != CLEAR_SUCCEEDED && 803 if (clear_server_data_state_ != CLEAR_SUCCEEDED &&
792 clear_server_data_state_ != CLEAR_FAILED) { 804 clear_server_data_state_ != CLEAR_FAILED) {
793 clear_server_data_state_ = CLEAR_FAILED; 805 clear_server_data_state_ = CLEAR_FAILED;
794 NotifyObservers(); 806 NotifyObservers();
795 } 807 }
796 } 808 }
797 809
798 void ProfileSyncService::OnClearServerDataFailed() { 810 void ProfileSyncService::OnClearServerDataFailed() {
811 LOG(WARNING) << "OnClearServerDataFailed";
799 clear_server_data_timer_.Stop(); 812 clear_server_data_timer_.Stop();
800 813
801 // Only once clear has succeeded there is no longer a need to transition to 814 // Only once clear has succeeded there is no longer a need to transition to
802 // a failed state as sync is disabled locally. Also, no need to fire off 815 // a failed state as sync is disabled locally. Also, no need to fire off
803 // the observers if the state didn't change (i.e. it was FAILED before). 816 // the observers if the state didn't change (i.e. it was FAILED before).
804 if (clear_server_data_state_ != CLEAR_SUCCEEDED && 817 if (clear_server_data_state_ != CLEAR_SUCCEEDED &&
805 clear_server_data_state_ != CLEAR_FAILED) { 818 clear_server_data_state_ != CLEAR_FAILED) {
806 clear_server_data_state_ = CLEAR_FAILED; 819 clear_server_data_state_ = CLEAR_FAILED;
807 NotifyObservers(); 820 NotifyObservers();
808 } 821 }
809 } 822 }
810 823
811 void ProfileSyncService::OnClearServerDataSucceeded() { 824 void ProfileSyncService::OnClearServerDataSucceeded() {
825 LOG(WARNING) << "OnClearServerDataSucceeded";
812 clear_server_data_timer_.Stop(); 826 clear_server_data_timer_.Stop();
813 827
814 // Even if the timout fired, we still transition to the succeeded state as 828 // Even if the timout fired, we still transition to the succeeded state as
815 // we want UI to update itself and no longer allow the user to press "clear" 829 // we want UI to update itself and no longer allow the user to press "clear"
816 if (clear_server_data_state_ != CLEAR_SUCCEEDED) { 830 if (clear_server_data_state_ != CLEAR_SUCCEEDED) {
817 clear_server_data_state_ = CLEAR_SUCCEEDED; 831 clear_server_data_state_ = CLEAR_SUCCEEDED;
818 NotifyObservers(); 832 NotifyObservers();
819 } 833 }
820 } 834 }
821 835
822 void ProfileSyncService::OnPassphraseRequired( 836 void ProfileSyncService::OnPassphraseRequired(
823 sync_api::PassphraseRequiredReason reason, 837 sync_api::PassphraseRequiredReason reason,
824 const sync_pb::EncryptedData& pending_keys) { 838 const sync_pb::EncryptedData& pending_keys) {
839 LOG(WARNING) << "OnPassphraseRequired";
825 DCHECK(backend_.get()); 840 DCHECK(backend_.get());
826 DCHECK(backend_->IsNigoriEnabled()); 841 DCHECK(backend_->IsNigoriEnabled());
827 842
828 // TODO(lipalani) : add this check to other locations as well. 843 // TODO(lipalani) : add this check to other locations as well.
829 if (unrecoverable_error_detected_) { 844 if (unrecoverable_error_detected_) {
830 // When unrecoverable error is detected we post a task to shutdown the 845 // When unrecoverable error is detected we post a task to shutdown the
831 // backend. The task might not have executed yet. 846 // backend. The task might not have executed yet.
832 return; 847 return;
833 } 848 }
834 849
835 DVLOG(1) << "Passphrase required with reason: " 850 DVLOG(1) << "Passphrase required with reason: "
836 << sync_api::PassphraseRequiredReasonToString(reason); 851 << sync_api::PassphraseRequiredReasonToString(reason);
837 passphrase_required_reason_ = reason; 852 passphrase_required_reason_ = reason;
838 853
839 // Notify observers that the passphrase status may have changed. 854 // Notify observers that the passphrase status may have changed.
840 NotifyObservers(); 855 NotifyObservers();
841 } 856 }
842 857
843 void ProfileSyncService::OnPassphraseAccepted() { 858 void ProfileSyncService::OnPassphraseAccepted() {
859 LOG(WARNING) << "OnPassphraseAccepted";
844 DVLOG(1) << "Received OnPassphraseAccepted."; 860 DVLOG(1) << "Received OnPassphraseAccepted.";
845 // If we are not using an explicit passphrase, and we have a cache of the gaia 861 // If we are not using an explicit passphrase, and we have a cache of the gaia
846 // password, use it for encryption at this point. 862 // password, use it for encryption at this point.
847 DCHECK(cached_passphrase_.empty()) << 863 DCHECK(cached_passphrase_.empty()) <<
848 "Passphrase no longer required but there is still a cached passphrase"; 864 "Passphrase no longer required but there is still a cached passphrase";
849 865
850 // Reset passphrase_required_reason_ since we know we no longer require the 866 // Reset passphrase_required_reason_ since we know we no longer require the
851 // passphrase. We do this here rather than down in ResolvePassphraseRequired() 867 // passphrase. We do this here rather than down in ResolvePassphraseRequired()
852 // because that can be called by OnPassphraseRequired() if no encrypted data 868 // because that can be called by OnPassphraseRequired() if no encrypted data
853 // types are enabled, and we don't want to clobber the true passphrase error. 869 // types are enabled, and we don't want to clobber the true passphrase error.
(...skipping 18 matching lines...) Expand all
872 encrypted_types_ = encrypted_types; 888 encrypted_types_ = encrypted_types;
873 encrypt_everything_ = encrypt_everything; 889 encrypt_everything_ = encrypt_everything;
874 DVLOG(1) << "Encrypted types changed to " 890 DVLOG(1) << "Encrypted types changed to "
875 << syncable::ModelTypeSetToString(encrypted_types_) 891 << syncable::ModelTypeSetToString(encrypted_types_)
876 << " (encrypt everything is set to " 892 << " (encrypt everything is set to "
877 << (encrypt_everything_ ? "true" : "false") << ")"; 893 << (encrypt_everything_ ? "true" : "false") << ")";
878 DCHECK(encrypted_types_.Has(syncable::PASSWORDS)); 894 DCHECK(encrypted_types_.Has(syncable::PASSWORDS));
879 } 895 }
880 896
881 void ProfileSyncService::OnEncryptionComplete() { 897 void ProfileSyncService::OnEncryptionComplete() {
898 LOG(WARNING) << "OnEncryptionComplete";
882 DVLOG(1) << "Encryption complete"; 899 DVLOG(1) << "Encryption complete";
883 if (encryption_pending_ && encrypt_everything_) { 900 if (encryption_pending_ && encrypt_everything_) {
884 encryption_pending_ = false; 901 encryption_pending_ = false;
885 // This is to nudge the integration tests when encryption is 902 // This is to nudge the integration tests when encryption is
886 // finished. 903 // finished.
887 NotifyObservers(); 904 NotifyObservers();
888 } 905 }
889 } 906 }
890 907
891 void ProfileSyncService::OnMigrationNeededForTypes( 908 void ProfileSyncService::OnMigrationNeededForTypes(
892 syncable::ModelTypeSet types) { 909 syncable::ModelTypeSet types) {
893 DCHECK(backend_initialized_); 910 DCHECK(backend_initialized_);
894 DCHECK(data_type_manager_.get()); 911 DCHECK(data_type_manager_.get());
895 912
896 // Migrator must be valid, because we don't sync until it is created and this 913 // Migrator must be valid, because we don't sync until it is created and this
897 // callback originates from a sync cycle. 914 // callback originates from a sync cycle.
898 migrator_->MigrateTypes(types); 915 migrator_->MigrateTypes(types);
899 } 916 }
900 917
901 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) { 918 void ProfileSyncService::OnActionableError(const SyncProtocolError& error) {
919 LOG(WARNING) << "OnActionableError";
902 last_actionable_error_ = error; 920 last_actionable_error_ = error;
903 DCHECK_NE(last_actionable_error_.action, 921 DCHECK_NE(last_actionable_error_.action,
904 browser_sync::UNKNOWN_ACTION); 922 browser_sync::UNKNOWN_ACTION);
905 switch (error.action) { 923 switch (error.action) {
906 case browser_sync::UPGRADE_CLIENT: 924 case browser_sync::UPGRADE_CLIENT:
907 case browser_sync::CLEAR_USER_DATA_AND_RESYNC: 925 case browser_sync::CLEAR_USER_DATA_AND_RESYNC:
908 case browser_sync::ENABLE_SYNC_ON_ACCOUNT: 926 case browser_sync::ENABLE_SYNC_ON_ACCOUNT:
909 case browser_sync::STOP_AND_RESTART_SYNC: 927 case browser_sync::STOP_AND_RESTART_SYNC:
910 // TODO(lipalani) : if setup in progress we want to display these 928 // TODO(lipalani) : if setup in progress we want to display these
911 // actions in the popup. The current experience might not be optimal for 929 // actions in the popup. The current experience might not be optimal for
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 // Selected type has changed - log it. 1082 // Selected type has changed - log it.
1065 UMA_HISTOGRAM_ENUMERATION( 1083 UMA_HISTOGRAM_ENUMERATION(
1066 "Sync.CustomSync", 1084 "Sync.CustomSync",
1067 user_selectable_types[i], 1085 user_selectable_types[i],
1068 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1); 1086 browser_sync::user_selectable_type::SELECTABLE_DATATYPE_COUNT + 1);
1069 } 1087 }
1070 } 1088 }
1071 } 1089 }
1072 } 1090 }
1073 1091
1092 void ProfileSyncService::RefreshSpareBootstrapToken(
1093 const std::string& passphrase) {
1094 // All accesses to the cryptographer are protected by a transaction.
1095 sync_api::WriteTransaction trans(FROM_HERE, GetUserShare());
Andrew T Wilson (Slow) 2012/04/03 22:22:33 I think we want to create our own cryptographer he
kochi 2012/04/03 23:21:48 Done as Nicolas suggested. On 2012/04/03 22:22:33
1096 browser_sync::Cryptographer* cryptographer = trans.GetCryptographer();
1097 browser_sync::KeyParams key_params = {"localhost", "dummy", passphrase};
1098 sync_api::WriteNode node(&trans);
1099 if (!node.InitByTagLookup(browser_sync::kNigoriTag)) {
Andrew T Wilson (Slow) 2012/04/03 22:22:33 We don't need a real nigori node here - we can cre
kochi 2012/04/03 23:21:48 Done as Nicolas suggested. On 2012/04/03 22:22:33,
1100 NOTREACHED();
1101 return;
1102 }
1103
1104 std::string bootstrap_token;
1105 if (!cryptographer->AddKey(key_params)) {
1106 NOTREACHED() << "Failed to add key to cryptographer.";
1107 }
1108 cryptographer->GetBootstrapToken(&bootstrap_token);
1109 sync_prefs_.SetSpareBootstrapToken(bootstrap_token);
1110 }
1111
1074 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, 1112 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything,
1075 syncable::ModelTypeSet chosen_types) { 1113 syncable::ModelTypeSet chosen_types) {
1076 if (!backend_.get() && 1114 if (!backend_.get() &&
1077 unrecoverable_error_detected_ == false) { 1115 unrecoverable_error_detected_ == false) {
1078 NOTREACHED(); 1116 NOTREACHED();
1079 return; 1117 return;
1080 } 1118 }
1081 1119
1082 UpdateSelectedTypesHistogram(sync_everything, chosen_types); 1120 UpdateSelectedTypesHistogram(sync_everything, chosen_types);
1083 sync_prefs_.SetKeepEverythingSynced(sync_everything); 1121 sync_prefs_.SetKeepEverythingSynced(sync_everything);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 content::Details<const GoogleServiceSigninSuccessDetails>( 1460 content::Details<const GoogleServiceSigninSuccessDetails>(
1423 details).ptr(); 1461 details).ptr();
1424 DCHECK(!successful->password.empty()); 1462 DCHECK(!successful->password.empty());
1425 if (!sync_prefs_.IsStartSuppressed()) { 1463 if (!sync_prefs_.IsStartSuppressed()) {
1426 cached_passphrase_ = successful->password; 1464 cached_passphrase_ = successful->password;
1427 // Try to consume the passphrase we just cached. If the sync backend 1465 // Try to consume the passphrase we just cached. If the sync backend
1428 // is not running yet, the passphrase will remain cached until the 1466 // is not running yet, the passphrase will remain cached until the
1429 // backend starts up. 1467 // backend starts up.
1430 ConsumeCachedPassphraseIfPossible(); 1468 ConsumeCachedPassphraseIfPossible();
1431 } 1469 }
1470 RefreshSpareBootstrapToken(successful->password);
1432 if (!sync_initialized() || 1471 if (!sync_initialized() ||
1433 GetAuthError().state() != GoogleServiceAuthError::NONE) { 1472 GetAuthError().state() != GoogleServiceAuthError::NONE) {
1434 // Track the fact that we're still waiting for auth to complete. 1473 // Track the fact that we're still waiting for auth to complete.
1435 is_auth_in_progress_ = true; 1474 is_auth_in_progress_ = true;
1436 } 1475 }
1437 break; 1476 break;
1438 } 1477 }
1439 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { 1478 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: {
1479 LOG(WARNING) << "Got NOTIFICATION_TOKEN_REQUEST_FAILED";
1440 const TokenService::TokenRequestFailedDetails& token_details = 1480 const TokenService::TokenRequestFailedDetails& token_details =
1441 *(content::Details<const TokenService::TokenRequestFailedDetails>( 1481 *(content::Details<const TokenService::TokenRequestFailedDetails>(
1442 details).ptr()); 1482 details).ptr());
1443 if (IsTokenServiceRelevant(token_details.service())) { 1483 if (IsTokenServiceRelevant(token_details.service())) {
1444 GoogleServiceAuthError error( 1484 GoogleServiceAuthError error(
1445 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 1485 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
1446 UpdateAuthErrorState(error); 1486 UpdateAuthErrorState(error);
1447 } 1487 }
1448 break; 1488 break;
1449 } 1489 }
1450 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { 1490 case chrome::NOTIFICATION_TOKEN_AVAILABLE: {
1491 LOG(WARNING) << "Got NOTIFICATION_TOKEN_AVAILABLE";
1451 const TokenService::TokenAvailableDetails& token_details = 1492 const TokenService::TokenAvailableDetails& token_details =
1452 *(content::Details<const TokenService::TokenAvailableDetails>( 1493 *(content::Details<const TokenService::TokenAvailableDetails>(
1453 details).ptr()); 1494 details).ptr());
1454 if (IsTokenServiceRelevant(token_details.service()) && 1495 if (IsTokenServiceRelevant(token_details.service()) &&
1455 AreCredentialsAvailable()) { 1496 AreCredentialsAvailable()) {
1456 if (backend_initialized_) 1497 if (backend_initialized_)
1457 backend_->UpdateCredentials(GetCredentials()); 1498 backend_->UpdateCredentials(GetCredentials());
1458 else if (!sync_prefs_.IsStartSuppressed()) 1499 else if (!sync_prefs_.IsStartSuppressed())
1459 StartUp(); 1500 StartUp();
1460 } 1501 }
1461 break; 1502 break;
1462 } 1503 }
1463 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { 1504 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: {
1505 LOG(WARNING) << "Got NOTIFICATION_TOKEN_LOADING_FINISHED";
1464 // This notification gets fired when TokenService loads the tokens 1506 // This notification gets fired when TokenService loads the tokens
1465 // from storage. 1507 // from storage.
1466 if (AreCredentialsAvailable()) { 1508 if (AreCredentialsAvailable()) {
1467 // Initialize the backend if sync token was loaded. 1509 // Initialize the backend if sync token was loaded.
1468 if (backend_initialized_) { 1510 if (backend_initialized_) {
1469 backend_->UpdateCredentials(GetCredentials()); 1511 backend_->UpdateCredentials(GetCredentials());
1470 } 1512 }
1471 if (!sync_prefs_.IsStartSuppressed()) 1513 if (!sync_prefs_.IsStartSuppressed())
1472 StartUp(); 1514 StartUp();
1473 } else if (!auto_start_enabled_ && 1515 } else if (!auto_start_enabled_ &&
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 return false; 1570 return false;
1529 1571
1530 return data_type_manager_->state() == DataTypeManager::CONFIGURED; 1572 return data_type_manager_->state() == DataTypeManager::CONFIGURED;
1531 } 1573 }
1532 1574
1533 void ProfileSyncService::StopAndSuppress() { 1575 void ProfileSyncService::StopAndSuppress() {
1534 sync_prefs_.SetStartSuppressed(true); 1576 sync_prefs_.SetStartSuppressed(true);
1535 ShutdownImpl(false); 1577 ShutdownImpl(false);
1536 } 1578 }
1537 1579
1538 void ProfileSyncService::UnsuppressAndStart() { 1580 void ProfileSyncService::Unsuppress() {
1581 LOG(WARNING) << "Unsuppress()";
Andrew T Wilson (Slow) 2012/04/03 22:22:33 See previous comment - not sure if we should break
kochi 2012/04/03 23:21:48 Done.
1539 DCHECK(profile_); 1582 DCHECK(profile_);
1540 sync_prefs_.SetStartSuppressed(false); 1583 sync_prefs_.SetStartSuppressed(false);
1584 }
1585
1586 void ProfileSyncService::UnsuppressAndStart() {
1587 LOG(WARNING) << "UnsuppressAndStart()";
1588 Unsuppress();
1541 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess 1589 // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
1542 // is never called for some clients. 1590 // is never called for some clients.
1543 if (signin_ && signin_->GetAuthenticatedUsername().empty()) { 1591 if (signin_ && signin_->GetAuthenticatedUsername().empty()) {
1544 signin_->SetAuthenticatedUsername(sync_prefs_.GetGoogleServicesUsername()); 1592 signin_->SetAuthenticatedUsername(sync_prefs_.GetGoogleServicesUsername());
1545 } 1593 }
1546 TryStart(); 1594 TryStart();
1547 } 1595 }
1548 1596
1549 void ProfileSyncService::AcknowledgeSyncedTypes() { 1597 void ProfileSyncService::AcknowledgeSyncedTypes() {
1550 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes()); 1598 sync_prefs_.AcknowledgeSyncedTypes(GetRegisteredDataTypes());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1634 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1587 ProfileSyncService* old_this = this; 1635 ProfileSyncService* old_this = this;
1588 this->~ProfileSyncService(); 1636 this->~ProfileSyncService();
1589 new(old_this) ProfileSyncService( 1637 new(old_this) ProfileSyncService(
1590 new ProfileSyncComponentsFactoryImpl(profile, 1638 new ProfileSyncComponentsFactoryImpl(profile,
1591 CommandLine::ForCurrentProcess()), 1639 CommandLine::ForCurrentProcess()),
1592 profile, 1640 profile,
1593 signin, 1641 signin,
1594 behavior); 1642 behavior);
1595 } 1643 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698