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/signin/signin_tracker.h" | 5 #include "chrome/browser/signin/signin_tracker.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/signin/token_service.h" | 8 #include "chrome/browser/signin/token_service.h" |
9 #include "chrome/browser/signin/token_service_factory.h" | 9 #include "chrome/browser/signin/token_service_factory.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // of ProfileSyncService and over to here (http://crbug.com/114209). | 134 // of ProfileSyncService and over to here (http://crbug.com/114209). |
135 ProfileSyncService* service = | 135 ProfileSyncService* service = |
136 ProfileSyncServiceFactory::GetForProfile(profile_); | 136 ProfileSyncServiceFactory::GetForProfile(profile_); |
137 if (service->waiting_for_auth()) { | 137 if (service->waiting_for_auth()) { |
138 // Still waiting for an auth token to come in so stay in the INITIALIZING | 138 // Still waiting for an auth token to come in so stay in the INITIALIZING |
139 // state (we do this to avoid triggering an early signin error in the case | 139 // state (we do this to avoid triggering an early signin error in the case |
140 // where there's a previous auth error in the sync service that hasn't | 140 // where there's a previous auth error in the sync service that hasn't |
141 // been cleared yet). | 141 // been cleared yet). |
142 return; | 142 return; |
143 } | 143 } |
144 // If we haven't loaded all our service tokens yet, just exit (we'll be called | 144 |
145 // again when another token is loaded, or will transition to SigninFailed if | |
146 // the loading fails). | |
147 if (!AreServiceTokensLoaded(profile_)) | |
148 return; | |
149 if (!AreServicesSignedIn(profile_)) { | 145 if (!AreServicesSignedIn(profile_)) { |
150 state_ = WAITING_FOR_GAIA_VALIDATION; | 146 state_ = WAITING_FOR_GAIA_VALIDATION; |
151 observer_->SigninFailed(service->GetAuthError()); | 147 observer_->SigninFailed(service->GetAuthError()); |
152 } else if (service->sync_initialized()) { | 148 } else if (service->sync_initialized() && AreServiceTokensLoaded(profile_)) { |
153 state_ = SIGNIN_COMPLETE; | 149 state_ = SIGNIN_COMPLETE; |
154 observer_->SigninSuccess(); | 150 observer_->SigninSuccess(); |
155 } | 151 } |
156 } | 152 } |
157 | 153 |
158 // static | 154 // static |
159 bool SigninTracker::AreServiceTokensLoaded(Profile* profile) { | 155 bool SigninTracker::AreServiceTokensLoaded(Profile* profile) { |
160 // See if we have all of the tokens required. | 156 // See if we have all of the tokens required. |
161 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); | 157 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
162 for (int i = 0; i < kNumSignedInServices; ++i) { | 158 for (int i = 0; i < kNumSignedInServices; ++i) { |
163 if (!token_service->HasTokenForService(kSignedInServices[i])) { | 159 if (!token_service->HasTokenForService(kSignedInServices[i])) { |
164 // Don't have a token for one of our signed-in services. | 160 // Don't have a token for one of our signed-in services. |
165 return false; | 161 return false; |
166 } | 162 } |
167 } | 163 } |
168 return true; | 164 return true; |
169 } | 165 } |
170 | 166 |
171 // static | 167 // static |
172 bool SigninTracker::AreServicesSignedIn(Profile* profile) { | 168 bool SigninTracker::AreServicesSignedIn(Profile* profile) { |
173 if (!AreServiceTokensLoaded(profile)) | 169 if (!AreServiceTokensLoaded(profile)) |
174 return false; | 170 return false; |
175 ProfileSyncService* service = | 171 ProfileSyncService* service = |
176 ProfileSyncServiceFactory::GetForProfile(profile); | 172 ProfileSyncServiceFactory::GetForProfile(profile); |
177 return (service->IsSyncEnabledAndLoggedIn() && | 173 return (service->IsSyncEnabledAndLoggedIn() && |
178 service->IsSyncTokenAvailable() && | 174 service->IsSyncTokenAvailable() && |
179 service->GetAuthError().state() == GoogleServiceAuthError::NONE && | 175 service->GetAuthError().state() == GoogleServiceAuthError::NONE && |
180 !service->HasUnrecoverableError()); | 176 !service->HasUnrecoverableError()); |
181 } | 177 } |
OLD | NEW |