OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 // Don't start up multiple times. | 397 // Don't start up multiple times. |
391 if (backend_.get()) { | 398 if (backend_.get()) { |
392 DVLOG(1) << "Skipping bringing up backend host."; | 399 DVLOG(1) << "Skipping bringing up backend host."; |
393 return; | 400 return; |
394 } | 401 } |
395 | 402 |
396 DCHECK(AreCredentialsAvailable()); | 403 DCHECK(AreCredentialsAvailable()); |
397 | 404 |
398 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); | 405 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); |
399 | 406 |
400 CreateBackend(); | 407 CreateBackend(); |
Nicolas Zea
2012/04/03 21:00:33
Right before this is where you should probably fil
kochi
2012/04/03 22:45:43
Done.
| |
401 | 408 |
402 // Initialize the backend. Every time we start up a new SyncBackendHost, | 409 // 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 | 410 // we'll want to start from a fresh SyncDB, so delete any old one that might |
404 // be there. | 411 // be there. |
405 InitializeBackend(!HasSyncSetupCompleted()); | 412 InitializeBackend(!HasSyncSetupCompleted()); |
406 | 413 |
407 if (!sync_global_error_.get()) { | 414 if (!sync_global_error_.get()) { |
408 sync_global_error_.reset(new SyncGlobalError(this)); | 415 sync_global_error_.reset(new SyncGlobalError(this)); |
409 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 416 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
410 sync_global_error_.get()); | 417 sync_global_error_.get()); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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(const std::string& passphras e) { | |
1093 // All accesses to the cryptographer are protected by a transaction. | |
1094 sync_api::WriteTransaction trans(FROM_HERE, GetUserShare()); | |
1095 browser_sync::Cryptographer* cryptographer = trans.GetCryptographer(); | |
Nicolas Zea
2012/04/03 21:00:33
This is using the sync's internal cryptographer. I
kochi
2012/04/03 22:45:43
Thanks! This code snippet was very cryptic and I
| |
1096 browser_sync::KeyParams key_params = {"localhost", "dummy", passphrase}; | |
1097 sync_api::WriteNode node(&trans); | |
1098 if (!node.InitByTagLookup(browser_sync::kNigoriTag)) { | |
1099 NOTREACHED(); | |
1100 return; | |
1101 } | |
1102 | |
1103 std::string bootstrap_token; | |
1104 if (!cryptographer->AddKey(key_params)) { | |
1105 NOTREACHED() << "Failed to add key to cryptographer."; | |
1106 } | |
1107 cryptographer->GetBootstrapToken(&bootstrap_token); | |
1108 sync_prefs_.SetSpareBootstrapToken(bootstrap_token); | |
1109 } | |
1110 | |
1074 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, | 1111 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, |
1075 syncable::ModelTypeSet chosen_types) { | 1112 syncable::ModelTypeSet chosen_types) { |
1076 if (!backend_.get() && | 1113 if (!backend_.get() && |
1077 unrecoverable_error_detected_ == false) { | 1114 unrecoverable_error_detected_ == false) { |
1078 NOTREACHED(); | 1115 NOTREACHED(); |
1079 return; | 1116 return; |
1080 } | 1117 } |
1081 | 1118 |
1082 UpdateSelectedTypesHistogram(sync_everything, chosen_types); | 1119 UpdateSelectedTypesHistogram(sync_everything, chosen_types); |
1083 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1120 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 content::Details<const GoogleServiceSigninSuccessDetails>( | 1459 content::Details<const GoogleServiceSigninSuccessDetails>( |
1423 details).ptr(); | 1460 details).ptr(); |
1424 DCHECK(!successful->password.empty()); | 1461 DCHECK(!successful->password.empty()); |
1425 if (!sync_prefs_.IsStartSuppressed()) { | 1462 if (!sync_prefs_.IsStartSuppressed()) { |
1426 cached_passphrase_ = successful->password; | 1463 cached_passphrase_ = successful->password; |
1427 // Try to consume the passphrase we just cached. If the sync backend | 1464 // Try to consume the passphrase we just cached. If the sync backend |
1428 // is not running yet, the passphrase will remain cached until the | 1465 // is not running yet, the passphrase will remain cached until the |
1429 // backend starts up. | 1466 // backend starts up. |
1430 ConsumeCachedPassphraseIfPossible(); | 1467 ConsumeCachedPassphraseIfPossible(); |
1431 } | 1468 } |
1469 RefreshSpareBootstrapToken(successful->password); | |
Nicolas Zea
2012/04/03 21:00:33
Condition this on OS_CHROMEOS
kochi
2012/04/03 22:45:43
Done.
| |
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 Loading... | |
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 Loading... | |
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 } |
OLD | NEW |