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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 if (!token_service) | 264 if (!token_service) |
265 return; | 265 return; |
266 // Don't start the backend if the token service hasn't finished loading tokens | 266 // Don't start the backend if the token service hasn't finished loading tokens |
267 // yet (if the backend is started before the sync token has been loaded, | 267 // yet (if the backend is started before the sync token has been loaded, |
268 // GetCredentials() will return bogus credentials). On auto_start platforms | 268 // GetCredentials() will return bogus credentials). On auto_start platforms |
269 // (like ChromeOS) we don't start sync until tokens are loaded, because the | 269 // (like ChromeOS) we don't start sync until tokens are loaded, because the |
270 // user can be "signed in" on those platforms long before the tokens get | 270 // user can be "signed in" on those platforms long before the tokens get |
271 // loaded, and we don't want to generate spurious auth errors. | 271 // loaded, and we don't want to generate spurious auth errors. |
272 if (IsSyncTokenAvailable() || | 272 if (IsSyncTokenAvailable() || |
273 (!auto_start_enabled_ && token_service->TokensLoadedFromDB())) { | 273 (!auto_start_enabled_ && token_service->TokensLoadedFromDB())) { |
274 if (HasSyncSetupCompleted() || auto_start_enabled_) { | 274 if (HasSyncSetupCompleted() || setup_in_progress_ || auto_start_enabled_) { |
Nicolas Zea
2012/11/29 19:43:08
Presumably this is necessary for when we bring up
tim (not reviewing)
2012/11/29 21:00:34
Correct! Added comment.
| |
275 // If sync setup has completed we always start the backend. | 275 // If sync setup has completed we always start the backend. |
276 // If autostart is enabled, but we haven't completed sync setup, we try to | 276 // If autostart is enabled, but we haven't completed sync setup, we try to |
277 // start sync anyway, since it's possible we crashed/shutdown after | 277 // start sync anyway, since it's possible we crashed/shutdown after |
278 // logging in but before the backend finished initializing the last time. | 278 // logging in but before the backend finished initializing the last time. |
279 // Note that if we haven't finished setting up sync, backend bring up will | 279 // Note that if we haven't finished setting up sync, backend bring up will |
280 // be done by the wizard. | 280 // be done by the wizard. |
281 StartUp(); | 281 StartUp(); |
282 } | 282 } |
283 } | 283 } |
284 } | 284 } |
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1709 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); | 1709 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
1710 // We may be called during the setup process before we're | 1710 // We may be called during the setup process before we're |
1711 // initialized. In this case, we default to the sensitive types. | 1711 // initialized. In this case, we default to the sensitive types. |
1712 return encrypted_types_; | 1712 return encrypted_types_; |
1713 } | 1713 } |
1714 | 1714 |
1715 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 1715 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
1716 NotifyObservers(); | 1716 NotifyObservers(); |
1717 if (is_sync_managed) { | 1717 if (is_sync_managed) { |
1718 DisableForUser(); | 1718 DisableForUser(); |
1719 } else if (HasSyncSetupCompleted() && | 1719 } else { |
1720 IsSyncEnabledAndLoggedIn() && | |
1721 IsSyncTokenAvailable()) { | |
1722 // Previously-configured sync has been re-enabled, so start sync now. | 1720 // Previously-configured sync has been re-enabled, so start sync now. |
1723 StartUp(); | 1721 TryStart(); |
1724 } | 1722 } |
1725 } | 1723 } |
1726 | 1724 |
1727 void ProfileSyncService::Observe(int type, | 1725 void ProfileSyncService::Observe(int type, |
1728 const content::NotificationSource& source, | 1726 const content::NotificationSource& source, |
1729 const content::NotificationDetails& details) { | 1727 const content::NotificationDetails& details) { |
1730 switch (type) { | 1728 switch (type) { |
1731 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 1729 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
1732 const GoogleServiceSigninSuccessDetails* successful = | 1730 const GoogleServiceSigninSuccessDetails* successful = |
1733 content::Details<const GoogleServiceSigninSuccessDetails>( | 1731 content::Details<const GoogleServiceSigninSuccessDetails>( |
(...skipping 30 matching lines...) Expand all Loading... | |
1764 // from the sync backend. | 1762 // from the sync backend. |
1765 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); | 1763 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); |
1766 UpdateAuthErrorState(error); | 1764 UpdateAuthErrorState(error); |
1767 } | 1765 } |
1768 break; | 1766 break; |
1769 } | 1767 } |
1770 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1768 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
1771 const TokenService::TokenAvailableDetails& token_details = | 1769 const TokenService::TokenAvailableDetails& token_details = |
1772 *(content::Details<const TokenService::TokenAvailableDetails>( | 1770 *(content::Details<const TokenService::TokenAvailableDetails>( |
1773 details).ptr()); | 1771 details).ptr()); |
1774 if (IsTokenServiceRelevant(token_details.service()) && | 1772 if (!IsTokenServiceRelevant(token_details.service())) |
1775 IsSyncEnabledAndLoggedIn() && | 1773 break; |
1776 IsSyncTokenAvailable()) { | 1774 } // Fall through. |
1777 if (backend_initialized_) | |
1778 backend_->UpdateCredentials(GetCredentials()); | |
1779 else | |
1780 StartUp(); | |
1781 } | |
1782 break; | |
1783 } | |
1784 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1775 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1785 // This notification gets fired when TokenService loads the tokens | 1776 // This notification gets fired when TokenService loads the tokens |
1786 // from storage. | 1777 // from storage. |
1787 if (IsSyncEnabledAndLoggedIn()) { | 1778 // Initialize the backend if sync is enabled. If the sync token was |
1788 // Don't start up sync and generate an auth error on auto_start | 1779 // not loaded, GetCredentials() will generate invalid credentials to |
1789 // platforms as they have their own way to resolve TokenService errors. | 1780 // cause the backend to generate an auth error (crbug.com/121755). |
1790 // (crbug.com/128592). | 1781 if (backend_initialized_) |
1791 if (auto_start_enabled_ && !IsSyncTokenAvailable()) | 1782 backend_->UpdateCredentials(GetCredentials()); |
1792 break; | 1783 else |
1793 | 1784 TryStart(); |
1794 // Initialize the backend if sync is enabled. If the sync token was | |
1795 // not loaded, GetCredentials() will generate invalid credentials to | |
1796 // cause the backend to generate an auth error (crbug.com/121755). | |
1797 if (backend_initialized_) | |
1798 backend_->UpdateCredentials(GetCredentials()); | |
1799 else | |
1800 StartUp(); | |
1801 } | |
1802 break; | 1785 break; |
1803 } | 1786 } |
1804 default: { | 1787 default: { |
1805 NOTREACHED(); | 1788 NOTREACHED(); |
1806 } | 1789 } |
1807 } | 1790 } |
1808 } | 1791 } |
1809 | 1792 |
1810 void ProfileSyncService::AddObserver(Observer* observer) { | 1793 void ProfileSyncService::AddObserver(Observer* observer) { |
1811 observers_.AddObserver(observer); | 1794 observers_.AddObserver(observer); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1925 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. | 1908 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. |
1926 ProfileSyncService* old_this = this; | 1909 ProfileSyncService* old_this = this; |
1927 this->~ProfileSyncService(); | 1910 this->~ProfileSyncService(); |
1928 new(old_this) ProfileSyncService( | 1911 new(old_this) ProfileSyncService( |
1929 new ProfileSyncComponentsFactoryImpl(profile, | 1912 new ProfileSyncComponentsFactoryImpl(profile, |
1930 CommandLine::ForCurrentProcess()), | 1913 CommandLine::ForCurrentProcess()), |
1931 profile, | 1914 profile, |
1932 signin, | 1915 signin, |
1933 behavior); | 1916 behavior); |
1934 } | 1917 } |
OLD | NEW |