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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 registered_types); | 257 registered_types); |
258 } | 258 } |
259 | 259 |
260 void ProfileSyncService::TryStart() { | 260 void ProfileSyncService::TryStart() { |
261 if (!IsSyncEnabledAndLoggedIn()) | 261 if (!IsSyncEnabledAndLoggedIn()) |
262 return; | 262 return; |
263 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 263 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
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. Note 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 return; |
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 | |
277 // start sync anyway, since it's possible we crashed/shutdown after | |
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 | |
280 // be done by the wizard. | |
281 StartUp(); | |
282 } | |
283 } | 275 } |
| 276 |
| 277 // If sync setup has completed we always start the backend. If the user is in |
| 278 // the process of setting up now, we should start the backend to download |
| 279 // account control state / encryption information). If autostart is enabled, |
| 280 // but we haven't completed sync setup, we try to start sync anyway, since |
| 281 // it's possible we crashed/shutdown after logging in but before the backend |
| 282 // finished initializing the last time. |
| 283 if (!HasSyncSetupCompleted() && !setup_in_progress_ && !auto_start_enabled_) |
| 284 return; |
| 285 |
| 286 // All systems Go for launch. |
| 287 StartUp(); |
| 288 |
284 } | 289 } |
285 | 290 |
286 void ProfileSyncService::StartSyncingWithServer() { | 291 void ProfileSyncService::StartSyncingWithServer() { |
287 if (backend_.get()) | 292 if (backend_.get()) |
288 backend_->StartSyncingWithServer(); | 293 backend_->StartSyncingWithServer(); |
289 } | 294 } |
290 | 295 |
291 void ProfileSyncService::RegisterAuthNotifications() { | 296 void ProfileSyncService::RegisterAuthNotifications() { |
292 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 297 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
293 registrar_.Add(this, | 298 registrar_.Add(this, |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); | 1714 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); |
1710 // We may be called during the setup process before we're | 1715 // We may be called during the setup process before we're |
1711 // initialized. In this case, we default to the sensitive types. | 1716 // initialized. In this case, we default to the sensitive types. |
1712 return encrypted_types_; | 1717 return encrypted_types_; |
1713 } | 1718 } |
1714 | 1719 |
1715 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { | 1720 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { |
1716 NotifyObservers(); | 1721 NotifyObservers(); |
1717 if (is_sync_managed) { | 1722 if (is_sync_managed) { |
1718 DisableForUser(); | 1723 DisableForUser(); |
1719 } else if (HasSyncSetupCompleted() && | 1724 } else { |
1720 IsSyncEnabledAndLoggedIn() && | 1725 // Sync is no longer disabled by policy. Try starting it up if appropriate. |
1721 IsSyncTokenAvailable()) { | 1726 TryStart(); |
1722 // Previously-configured sync has been re-enabled, so start sync now. | |
1723 StartUp(); | |
1724 } | 1727 } |
1725 } | 1728 } |
1726 | 1729 |
1727 void ProfileSyncService::Observe(int type, | 1730 void ProfileSyncService::Observe(int type, |
1728 const content::NotificationSource& source, | 1731 const content::NotificationSource& source, |
1729 const content::NotificationDetails& details) { | 1732 const content::NotificationDetails& details) { |
1730 switch (type) { | 1733 switch (type) { |
1731 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 1734 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
1732 const GoogleServiceSigninSuccessDetails* successful = | 1735 const GoogleServiceSigninSuccessDetails* successful = |
1733 content::Details<const GoogleServiceSigninSuccessDetails>( | 1736 content::Details<const GoogleServiceSigninSuccessDetails>( |
(...skipping 30 matching lines...) Expand all Loading... |
1764 // from the sync backend. | 1767 // from the sync backend. |
1765 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); | 1768 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); |
1766 UpdateAuthErrorState(error); | 1769 UpdateAuthErrorState(error); |
1767 } | 1770 } |
1768 break; | 1771 break; |
1769 } | 1772 } |
1770 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1773 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
1771 const TokenService::TokenAvailableDetails& token_details = | 1774 const TokenService::TokenAvailableDetails& token_details = |
1772 *(content::Details<const TokenService::TokenAvailableDetails>( | 1775 *(content::Details<const TokenService::TokenAvailableDetails>( |
1773 details).ptr()); | 1776 details).ptr()); |
1774 if (IsTokenServiceRelevant(token_details.service()) && | 1777 if (!IsTokenServiceRelevant(token_details.service())) |
1775 IsSyncEnabledAndLoggedIn() && | 1778 break; |
1776 IsSyncTokenAvailable()) { | 1779 } // 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: { | 1780 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1785 // This notification gets fired when TokenService loads the tokens | 1781 // This notification gets fired when TokenService loads the tokens |
1786 // from storage. | 1782 // from storage. |
1787 if (IsSyncEnabledAndLoggedIn()) { | 1783 // 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 | 1784 // not loaded, GetCredentials() will generate invalid credentials to |
1789 // platforms as they have their own way to resolve TokenService errors. | 1785 // cause the backend to generate an auth error (crbug.com/121755). |
1790 // (crbug.com/128592). | 1786 if (backend_initialized_) |
1791 if (auto_start_enabled_ && !IsSyncTokenAvailable()) | 1787 backend_->UpdateCredentials(GetCredentials()); |
1792 break; | 1788 else |
1793 | 1789 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; | 1790 break; |
1803 } | 1791 } |
1804 default: { | 1792 default: { |
1805 NOTREACHED(); | 1793 NOTREACHED(); |
1806 } | 1794 } |
1807 } | 1795 } |
1808 } | 1796 } |
1809 | 1797 |
1810 void ProfileSyncService::AddObserver(Observer* observer) { | 1798 void ProfileSyncService::AddObserver(Observer* observer) { |
1811 observers_.AddObserver(observer); | 1799 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. | 1913 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
1926 ProfileSyncService* old_this = this; | 1914 ProfileSyncService* old_this = this; |
1927 this->~ProfileSyncService(); | 1915 this->~ProfileSyncService(); |
1928 new(old_this) ProfileSyncService( | 1916 new(old_this) ProfileSyncService( |
1929 new ProfileSyncComponentsFactoryImpl(profile, | 1917 new ProfileSyncComponentsFactoryImpl(profile, |
1930 CommandLine::ForCurrentProcess()), | 1918 CommandLine::ForCurrentProcess()), |
1931 profile, | 1919 profile, |
1932 signin, | 1920 signin, |
1933 behavior); | 1921 behavior); |
1934 } | 1922 } |
OLD | NEW |