Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/invalidation/ticl_invalidation_service.h" | 5 #include "chrome/browser/invalidation/ticl_invalidation_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/invalidation/invalidation_service_util.h" | 9 #include "chrome/browser/invalidation/invalidation_service_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 if (access_token_request_ != NULL) | 198 if (access_token_request_ != NULL) |
| 199 return; | 199 return; |
| 200 request_access_token_retry_timer_.Stop(); | 200 request_access_token_retry_timer_.Stop(); |
| 201 OAuth2TokenService::ScopeSet oauth2_scopes; | 201 OAuth2TokenService::ScopeSet oauth2_scopes; |
| 202 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) | 202 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) |
| 203 oauth2_scopes.insert(kOAuth2Scopes[i]); | 203 oauth2_scopes.insert(kOAuth2Scopes[i]); |
| 204 // Invalidate previous token, otherwise token service will return the same | 204 // Invalidate previous token, otherwise token service will return the same |
| 205 // token again. | 205 // token again. |
| 206 oauth2_token_service_->InvalidateToken(oauth2_scopes, access_token_); | 206 oauth2_token_service_->InvalidateToken(oauth2_scopes, access_token_); |
| 207 access_token_.clear(); | 207 access_token_.clear(); |
| 208 access_token_request_ = | 208 access_token_request_ = oauth2_token_service_->StartRequest( |
| 209 oauth2_token_service_->StartRequest(oauth2_scopes, this); | 209 signin_manager_->GetAuthenticatedUsername(), oauth2_scopes, this); |
|
Andrew T Wilson (Slow)
2013/08/23 09:38:13
Why are we using GetAuthenticatedUsername() instea
fgorski
2013/08/23 19:13:35
Done. I left it in that way as a case study, antic
| |
| 210 } | 210 } |
| 211 | 211 |
| 212 void TiclInvalidationService::OnGetTokenSuccess( | 212 void TiclInvalidationService::OnGetTokenSuccess( |
| 213 const OAuth2TokenService::Request* request, | 213 const OAuth2TokenService::Request* request, |
| 214 const std::string& access_token, | 214 const std::string& access_token, |
| 215 const base::Time& expiration_time) { | 215 const base::Time& expiration_time) { |
| 216 DCHECK_EQ(access_token_request_, request); | 216 DCHECK_EQ(access_token_request_, request); |
| 217 access_token_request_.reset(); | 217 access_token_request_.reset(); |
| 218 // Reset backoff time after successful response. | 218 // Reset backoff time after successful response. |
| 219 request_access_token_backoff_.Reset(); | 219 request_access_token_backoff_.Reset(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 invalidator_storage_.reset(); | 289 invalidator_storage_.reset(); |
| 290 invalidator_registrar_.reset(); | 290 invalidator_registrar_.reset(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool TiclInvalidationService::IsReadyToStart() { | 293 bool TiclInvalidationService::IsReadyToStart() { |
| 294 if (profile_->IsManaged()) { | 294 if (profile_->IsManaged()) { |
| 295 DVLOG(2) << "Not starting TiclInvalidationService: User is managed."; | 295 DVLOG(2) << "Not starting TiclInvalidationService: User is managed."; |
| 296 return false; | 296 return false; |
| 297 } | 297 } |
| 298 | 298 |
| 299 if (signin_manager_->GetAuthenticatedUsername().empty()) { | 299 const std::string& account_id = signin_manager_->GetAuthenticatedUsername(); |
| 300 if (account_id.empty()) { | |
| 300 DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in."; | 301 DVLOG(2) << "Not starting TiclInvalidationService: User is not signed in."; |
| 301 return false; | 302 return false; |
| 302 } | 303 } |
| 303 | 304 |
| 304 if (!oauth2_token_service_) { | 305 if (!oauth2_token_service_) { |
| 305 DVLOG(2) | 306 DVLOG(2) |
| 306 << "Not starting TiclInvalidationService: TokenService unavailable."; | 307 << "Not starting TiclInvalidationService: TokenService unavailable."; |
| 307 return false; | 308 return false; |
| 308 } | 309 } |
| 309 | 310 |
| 310 if (!oauth2_token_service_->RefreshTokenIsAvailable()) { | 311 if (!oauth2_token_service_->RefreshTokenIsAvailable(account_id)) { |
| 311 DVLOG(2) | 312 DVLOG(2) |
| 312 << "Not starting TiclInvalidationServce: Waiting for refresh token."; | 313 << "Not starting TiclInvalidationServce: Waiting for refresh token."; |
| 313 return false; | 314 return false; |
| 314 } | 315 } |
| 315 | 316 |
| 316 return true; | 317 return true; |
| 317 } | 318 } |
| 318 | 319 |
| 319 bool TiclInvalidationService::IsStarted() { | 320 bool TiclInvalidationService::IsStarted() { |
| 320 return invalidator_.get() != NULL; | 321 return invalidator_.get() != NULL; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 } | 380 } |
| 380 | 381 |
| 381 // This service always expects to have a valid invalidator storage. | 382 // This service always expects to have a valid invalidator storage. |
| 382 // So we must not only clear the old one, but also start a new one. | 383 // So we must not only clear the old one, but also start a new one. |
| 383 invalidator_storage_->Clear(); | 384 invalidator_storage_->Clear(); |
| 384 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); | 385 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); |
| 385 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); | 386 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); |
| 386 } | 387 } |
| 387 | 388 |
| 388 } // namespace invalidation | 389 } // namespace invalidation |
| OLD | NEW |