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

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

Powered by Google App Engine
This is Rietveld 408576698