| 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 "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/invalidation/invalidation_service_util.h" | 10 #include "chrome/browser/invalidation/invalidation_service_util.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 void TiclInvalidationService::RequestAccessToken() { | 164 void TiclInvalidationService::RequestAccessToken() { |
| 165 // Only one active request at a time. | 165 // Only one active request at a time. |
| 166 if (access_token_request_ != NULL) | 166 if (access_token_request_ != NULL) |
| 167 return; | 167 return; |
| 168 request_access_token_retry_timer_.Stop(); | 168 request_access_token_retry_timer_.Stop(); |
| 169 OAuth2TokenService::ScopeSet oauth2_scopes; | 169 OAuth2TokenService::ScopeSet oauth2_scopes; |
| 170 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) | 170 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) |
| 171 oauth2_scopes.insert(kOAuth2Scopes[i]); | 171 oauth2_scopes.insert(kOAuth2Scopes[i]); |
| 172 // Invalidate previous token, otherwise token service will return the same | 172 // Invalidate previous token, otherwise token service will return the same |
| 173 // token again. | 173 // token again. |
| 174 const std::string& account_id = oauth2_token_service_->GetPrimaryAccountId(); | 174 const std::string& account_id = signin_manager_->GetAuthenticatedAccountId(); |
| 175 oauth2_token_service_->InvalidateToken(account_id, | 175 oauth2_token_service_->InvalidateToken(account_id, |
| 176 oauth2_scopes, | 176 oauth2_scopes, |
| 177 access_token_); | 177 access_token_); |
| 178 access_token_.clear(); | 178 access_token_.clear(); |
| 179 access_token_request_ = oauth2_token_service_->StartRequest(account_id, | 179 access_token_request_ = oauth2_token_service_->StartRequest(account_id, |
| 180 oauth2_scopes, | 180 oauth2_scopes, |
| 181 this); | 181 this); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void TiclInvalidationService::OnGetTokenSuccess( | 184 void TiclInvalidationService::OnGetTokenSuccess( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 break; | 222 break; |
| 223 } | 223 } |
| 224 default: { | 224 default: { |
| 225 // We have no way to notify the user of this. Do nothing. | 225 // We have no way to notify the user of this. Do nothing. |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 void TiclInvalidationService::OnRefreshTokenAvailable( | 230 void TiclInvalidationService::OnRefreshTokenAvailable( |
| 231 const std::string& account_id) { | 231 const std::string& account_id) { |
| 232 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { | 232 if (signin_manager_->GetAuthenticatedAccountId() == account_id) { |
| 233 if (!IsStarted() && IsReadyToStart()) { | 233 if (!IsStarted() && IsReadyToStart()) { |
| 234 StartInvalidator(PUSH_CLIENT_CHANNEL); | 234 StartInvalidator(PUSH_CLIENT_CHANNEL); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 void TiclInvalidationService::OnRefreshTokenRevoked( | 239 void TiclInvalidationService::OnRefreshTokenRevoked( |
| 240 const std::string& account_id) { | 240 const std::string& account_id) { |
| 241 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { | 241 if (signin_manager_->GetAuthenticatedAccountId() == account_id) { |
| 242 access_token_.clear(); | 242 access_token_.clear(); |
| 243 if (IsStarted()) { | 243 if (IsStarted()) { |
| 244 UpdateInvalidatorCredentials(); | 244 UpdateInvalidatorCredentials(); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 void TiclInvalidationService::OnInvalidatorStateChange( | 249 void TiclInvalidationService::OnInvalidatorStateChange( |
| 250 syncer::InvalidatorState state) { | 250 syncer::InvalidatorState state) { |
| 251 if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) { | 251 if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 294 } |
| 295 | 295 |
| 296 if (!oauth2_token_service_) { | 296 if (!oauth2_token_service_) { |
| 297 DVLOG(2) | 297 DVLOG(2) |
| 298 << "Not starting TiclInvalidationService: " | 298 << "Not starting TiclInvalidationService: " |
| 299 << "OAuth2TokenService unavailable."; | 299 << "OAuth2TokenService unavailable."; |
| 300 return false; | 300 return false; |
| 301 } | 301 } |
| 302 | 302 |
| 303 if (!oauth2_token_service_->RefreshTokenIsAvailable( | 303 if (!oauth2_token_service_->RefreshTokenIsAvailable( |
| 304 oauth2_token_service_->GetPrimaryAccountId())) { | 304 signin_manager_->GetAuthenticatedAccountId())) { |
| 305 DVLOG(2) | 305 DVLOG(2) |
| 306 << "Not starting TiclInvalidationServce: Waiting for refresh token."; | 306 << "Not starting TiclInvalidationServce: Waiting for refresh token."; |
| 307 return false; | 307 return false; |
| 308 } | 308 } |
| 309 | 309 |
| 310 return true; | 310 return true; |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool TiclInvalidationService::IsStarted() { | 313 bool TiclInvalidationService::IsStarted() { |
| 314 return invalidator_.get() != NULL; | 314 return invalidator_.get() != NULL; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 399 } |
| 400 | 400 |
| 401 // This service always expects to have a valid invalidator storage. | 401 // This service always expects to have a valid invalidator storage. |
| 402 // So we must not only clear the old one, but also start a new one. | 402 // So we must not only clear the old one, but also start a new one. |
| 403 invalidator_storage_->Clear(); | 403 invalidator_storage_->Clear(); |
| 404 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); | 404 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); |
| 405 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); | 405 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 } // namespace invalidation | 408 } // namespace invalidation |
| OLD | NEW |