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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 8760019: Make the change in ProfileSyncService such that it declares success (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 } 1458 }
1436 break; 1459 break;
1437 } 1460 }
1438 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { 1461 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: {
1439 GoogleServiceAuthError error = 1462 GoogleServiceAuthError error =
1440 *(content::Details<const GoogleServiceAuthError>(details).ptr()); 1463 *(content::Details<const GoogleServiceAuthError>(details).ptr());
1441 UpdateAuthErrorState(error); 1464 UpdateAuthErrorState(error);
1442 break; 1465 break;
1443 } 1466 }
1444 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { 1467 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: {
1445 GoogleServiceAuthError error( 1468 TokenService::TokenRequestFailedDetails token_details =
Andrew T Wilson (Slow) 2011/12/02 00:52:35 I'd change this to const TokenService::TokenReques
Munjal (Google) 2011/12/02 02:14:01 Done.
1446 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 1469 *(content::Details<const TokenService::TokenRequestFailedDetails>(
1447 UpdateAuthErrorState(error); 1470 details).ptr());
1471 if (IsTokenServiceRelevant(token_details.service())) {
1472 GoogleServiceAuthError error(
1473 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
1474 UpdateAuthErrorState(error);
1475 }
1448 break; 1476 break;
1449 } 1477 }
1450 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { 1478 case chrome::NOTIFICATION_TOKEN_AVAILABLE: {
1451 if (AreCredentialsAvailable()) { 1479 TokenService::TokenAvailableDetails token_details =
Andrew T Wilson (Slow) 2011/12/02 00:52:35 See previous comment.
Munjal (Google) 2011/12/02 02:14:01 Done.
1480 *(content::Details<const TokenService::TokenAvailableDetails>(
1481 details).ptr());
1482 if (IsTokenServiceRelevant(token_details.service()) &&
1483 AreCredentialsAvailable(true)) {
1452 if (backend_initialized_) { 1484 if (backend_initialized_) {
1453 backend_->UpdateCredentials(GetCredentials()); 1485 backend_->UpdateCredentials(GetCredentials());
1454 } 1486 }
1455 if (!sync_prefs_.IsStartSuppressed()) 1487 if (!sync_prefs_.IsStartSuppressed())
1456 StartUp(); 1488 StartUp();
1457 } 1489 }
1458 break; 1490 break;
1459 } 1491 }
1460 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { 1492 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: {
1461 // If not in Chrome OS, and we have a username without tokens, 1493 // This notification gets fired when TokenService loads the tokens
Andrew T Wilson (Slow) 2011/12/02 00:52:35 nit: double-space between "loads the".
Munjal (Google) 2011/12/02 02:14:01 Done.
1462 // the user will need to signin again, so sign out. 1494 // from storage. Here we only check if the chromiumsync token is
1463 if (cros_user_.empty() && 1495 // available (versus both chromiumsync and oauth login tokens) to
1464 !signin_->GetUsername().empty() && 1496 // start up sync successfully for already logged in users who may
1465 !AreCredentialsAvailable()) { 1497 // only have chromiumsync token if they logged in before the code
1498 // to generate oauth login token released.
1499 if (AreCredentialsAvailable()) {
1500 // Initialize the backend if sync token was loaded.
1501 if (backend_initialized_) {
1502 backend_->UpdateCredentials(GetCredentials());
1503 }
1504 if (!sync_prefs_.IsStartSuppressed())
1505 StartUp();
1506 } else if (cros_user_.empty() && !signin_->GetUsername().empty()) {
1507 // If not in Chrome OS, and we have a username without tokens,
1508 // the user will need to signin again, so sign out.
1466 DisableForUser(); 1509 DisableForUser();
1467 } 1510 }
1468 break; 1511 break;
1469 } 1512 }
1470 default: { 1513 default: {
1471 NOTREACHED(); 1514 NOTREACHED();
1472 } 1515 }
1473 } 1516 }
1474 } 1517 }
1475 1518
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 << "Unrecoverable error."; 1600 << "Unrecoverable error.";
1558 } else { 1601 } else {
1559 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not " 1602 DVLOG(0) << "ConfigureDataTypeManager not invoked because backend is not "
1560 << "initialized"; 1603 << "initialized";
1561 } 1604 }
1562 } 1605 }
1563 1606
1564 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { 1607 const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() {
1565 return failed_datatypes_handler_; 1608 return failed_datatypes_handler_;
1566 } 1609 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698