OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 typedef GoogleServiceAuthError AuthError; | 77 typedef GoogleServiceAuthError AuthError; |
78 | 78 |
79 const char* ProfileSyncService::kSyncServerUrl = | 79 const char* ProfileSyncService::kSyncServerUrl = |
80 "https://clients4.google.com/chrome-sync"; | 80 "https://clients4.google.com/chrome-sync"; |
81 | 81 |
82 const char* ProfileSyncService::kDevServerUrl = | 82 const char* ProfileSyncService::kDevServerUrl = |
83 "https://clients4.google.com/chrome-sync/dev"; | 83 "https://clients4.google.com/chrome-sync/dev"; |
84 | 84 |
85 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 85 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
86 | 86 |
| 87 static const char* kRelevantTokenServices[] = { |
| 88 GaiaConstants::kSyncService, |
| 89 GaiaConstants::kGaiaOAuth2LoginRefreshToken}; |
| 90 static const int kRelevantTokenServicesCount = |
| 91 arraysize(kRelevantTokenServices); |
| 92 |
| 93 // Helper to check if the given token service is relevant for sync. |
| 94 static bool IsTokenServiceRelevant(const std::string& service) { |
| 95 for (int i = 0; i < kRelevantTokenServicesCount; ++i) { |
| 96 if (service == kRelevantTokenServices[i]) |
| 97 return true; |
| 98 } |
| 99 return false; |
| 100 } |
87 | 101 |
88 bool ShouldShowActionOnUI( | 102 bool ShouldShowActionOnUI( |
89 const browser_sync::SyncProtocolError& error) { | 103 const browser_sync::SyncProtocolError& error) { |
90 return (error.action != browser_sync::UNKNOWN_ACTION && | 104 return (error.action != browser_sync::UNKNOWN_ACTION && |
91 error.action != browser_sync::DISABLE_SYNC_ON_CLIENT); | 105 error.action != browser_sync::DISABLE_SYNC_ON_CLIENT); |
92 } | 106 } |
93 | 107 |
94 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, | 108 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, |
95 Profile* profile, | 109 Profile* profile, |
96 SigninManager* signin_manager, | 110 SigninManager* signin_manager, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (!cros_user_.empty()) | 148 if (!cros_user_.empty()) |
135 auto_start_enabled_ = true; | 149 auto_start_enabled_ = true; |
136 } | 150 } |
137 | 151 |
138 ProfileSyncService::~ProfileSyncService() { | 152 ProfileSyncService::~ProfileSyncService() { |
139 sync_prefs_.RemoveSyncPrefObserver(this); | 153 sync_prefs_.RemoveSyncPrefObserver(this); |
140 Shutdown(false); | 154 Shutdown(false); |
141 } | 155 } |
142 | 156 |
143 bool ProfileSyncService::AreCredentialsAvailable() { | 157 bool ProfileSyncService::AreCredentialsAvailable() { |
| 158 return AreCredentialsAvailable(false); |
| 159 } |
| 160 |
| 161 bool ProfileSyncService::AreCredentialsAvailable( |
| 162 bool check_oauth_login_token) { |
144 if (IsManaged()) { | 163 if (IsManaged()) { |
145 return false; | 164 return false; |
146 } | 165 } |
147 | 166 |
148 // CrOS user is always logged in. Chrome uses signin_ to check logged in. | 167 // CrOS user is always logged in. Chrome uses signin_ to check logged in. |
149 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { | 168 if (cros_user_.empty() && signin_->GetUsername().empty()) |
150 // TODO(chron): Verify CrOS unit test behavior. | 169 return false; |
151 return profile()->GetTokenService() && | 170 |
152 profile()->GetTokenService()->HasTokenForService( | 171 TokenService* token_service = profile()->GetTokenService(); |
153 browser_sync::SyncServiceName()); | 172 if (!token_service) |
154 } | 173 return false; |
155 return false; | 174 |
| 175 // TODO(chron): Verify CrOS unit test behavior. |
| 176 if (!token_service->HasTokenForService(browser_sync::SyncServiceName())) |
| 177 return false; |
| 178 return !check_oauth_login_token || token_service->HasOAuthLoginToken(); |
156 } | 179 } |
157 | 180 |
158 void ProfileSyncService::Initialize() { | 181 void ProfileSyncService::Initialize() { |
159 InitSettings(); | 182 InitSettings(); |
160 | 183 |
161 // We clear this here (vs Shutdown) because we want to remember that an error | 184 // We clear this here (vs Shutdown) because we want to remember that an error |
162 // happened on shutdown so we can display details (message, location) about it | 185 // happened on shutdown so we can display details (message, location) about it |
163 // in about:sync. | 186 // in about:sync. |
164 ClearStaleErrors(); | 187 ClearStaleErrors(); |
165 | 188 |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 } | 1451 } |
1429 break; | 1452 break; |
1430 } | 1453 } |
1431 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { | 1454 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
1432 GoogleServiceAuthError error = | 1455 GoogleServiceAuthError error = |
1433 *(content::Details<const GoogleServiceAuthError>(details).ptr()); | 1456 *(content::Details<const GoogleServiceAuthError>(details).ptr()); |
1434 UpdateAuthErrorState(error); | 1457 UpdateAuthErrorState(error); |
1435 break; | 1458 break; |
1436 } | 1459 } |
1437 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1460 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
1438 GoogleServiceAuthError error( | 1461 const TokenService::TokenRequestFailedDetails& token_details = |
1439 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 1462 *(content::Details<const TokenService::TokenRequestFailedDetails>( |
1440 UpdateAuthErrorState(error); | 1463 details).ptr()); |
| 1464 if (IsTokenServiceRelevant(token_details.service())) { |
| 1465 GoogleServiceAuthError error( |
| 1466 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 1467 UpdateAuthErrorState(error); |
| 1468 } |
1441 break; | 1469 break; |
1442 } | 1470 } |
1443 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1471 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
1444 if (AreCredentialsAvailable()) { | 1472 const TokenService::TokenAvailableDetails& token_details = |
| 1473 *(content::Details<const TokenService::TokenAvailableDetails>( |
| 1474 details).ptr()); |
| 1475 if (IsTokenServiceRelevant(token_details.service()) && |
| 1476 AreCredentialsAvailable(true)) { |
1445 if (backend_initialized_) { | 1477 if (backend_initialized_) { |
1446 backend_->UpdateCredentials(GetCredentials()); | 1478 backend_->UpdateCredentials(GetCredentials()); |
1447 } | 1479 } |
1448 if (!sync_prefs_.IsStartSuppressed()) | 1480 if (!sync_prefs_.IsStartSuppressed()) |
1449 StartUp(); | 1481 StartUp(); |
1450 } | 1482 } |
1451 break; | 1483 break; |
1452 } | 1484 } |
1453 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1485 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1454 // If not in Chrome OS, and we have a username without tokens, | 1486 // This notification gets fired when TokenService loads the tokens |
1455 // the user will need to signin again, so sign out. | 1487 // from storage. Here we only check if the chromiumsync token is |
1456 if (cros_user_.empty() && | 1488 // available (versus both chromiumsync and oauth login tokens) to |
1457 !signin_->GetUsername().empty() && | 1489 // start up sync successfully for already logged in users who may |
1458 !AreCredentialsAvailable()) { | 1490 // only have chromiumsync token if they logged in before the code |
| 1491 // to generate oauth login token released. |
| 1492 if (AreCredentialsAvailable()) { |
| 1493 // Initialize the backend if sync token was loaded. |
| 1494 if (backend_initialized_) { |
| 1495 backend_->UpdateCredentials(GetCredentials()); |
| 1496 } |
| 1497 if (!sync_prefs_.IsStartSuppressed()) |
| 1498 StartUp(); |
| 1499 } else if (cros_user_.empty() && !signin_->GetUsername().empty()) { |
| 1500 // If not in Chrome OS, and we have a username without tokens, |
| 1501 // the user will need to signin again, so sign out. |
1459 DisableForUser(); | 1502 DisableForUser(); |
1460 } | 1503 } |
1461 break; | 1504 break; |
1462 } | 1505 } |
1463 default: { | 1506 default: { |
1464 NOTREACHED(); | 1507 NOTREACHED(); |
1465 } | 1508 } |
1466 } | 1509 } |
1467 } | 1510 } |
1468 | 1511 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 << "Unrecoverable error."; | 1593 << "Unrecoverable error."; |
1551 } else { | 1594 } else { |
1552 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " | 1595 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " |
1553 << "initialized"; | 1596 << "initialized"; |
1554 } | 1597 } |
1555 } | 1598 } |
1556 | 1599 |
1557 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { | 1600 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { |
1558 return failed_datatypes_handler_; | 1601 return failed_datatypes_handler_; |
1559 } | 1602 } |
OLD | NEW |