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/gcm_network_channel_delegate_impl.h" | 10 #include "chrome/browser/invalidation/gcm_network_channel_delegate_impl.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 void TiclInvalidationService::RequestAccessToken() { | 172 void TiclInvalidationService::RequestAccessToken() { |
173 // Only one active request at a time. | 173 // Only one active request at a time. |
174 if (access_token_request_ != NULL) | 174 if (access_token_request_ != NULL) |
175 return; | 175 return; |
176 request_access_token_retry_timer_.Stop(); | 176 request_access_token_retry_timer_.Stop(); |
177 OAuth2TokenService::ScopeSet oauth2_scopes; | 177 OAuth2TokenService::ScopeSet oauth2_scopes; |
178 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) | 178 for (size_t i = 0; i < arraysize(kOAuth2Scopes); i++) |
179 oauth2_scopes.insert(kOAuth2Scopes[i]); | 179 oauth2_scopes.insert(kOAuth2Scopes[i]); |
180 // Invalidate previous token, otherwise token service will return the same | 180 // Invalidate previous token, otherwise token service will return the same |
181 // token again. | 181 // token again. |
182 const std::string& account_id = oauth2_token_service_->GetPrimaryAccountId(); | 182 const std::string& account_id = signin_manager_->GetAuthenticatedAccountId(); |
183 oauth2_token_service_->InvalidateToken(account_id, | 183 oauth2_token_service_->InvalidateToken(account_id, |
184 oauth2_scopes, | 184 oauth2_scopes, |
185 access_token_); | 185 access_token_); |
186 access_token_.clear(); | 186 access_token_.clear(); |
187 access_token_request_ = oauth2_token_service_->StartRequest(account_id, | 187 access_token_request_ = oauth2_token_service_->StartRequest(account_id, |
188 oauth2_scopes, | 188 oauth2_scopes, |
189 this); | 189 this); |
190 } | 190 } |
191 | 191 |
192 void TiclInvalidationService::OnGetTokenSuccess( | 192 void TiclInvalidationService::OnGetTokenSuccess( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 break; | 230 break; |
231 } | 231 } |
232 default: { | 232 default: { |
233 // We have no way to notify the user of this. Do nothing. | 233 // We have no way to notify the user of this. Do nothing. |
234 } | 234 } |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 void TiclInvalidationService::OnRefreshTokenAvailable( | 238 void TiclInvalidationService::OnRefreshTokenAvailable( |
239 const std::string& account_id) { | 239 const std::string& account_id) { |
240 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { | 240 if (signin_manager_->GetAuthenticatedAccountId() == account_id) { |
241 if (!IsStarted() && IsReadyToStart()) { | 241 if (!IsStarted() && IsReadyToStart()) { |
242 StartInvalidator(PUSH_CLIENT_CHANNEL); | 242 StartInvalidator(PUSH_CLIENT_CHANNEL); |
243 } | 243 } |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void TiclInvalidationService::OnRefreshTokenRevoked( | 247 void TiclInvalidationService::OnRefreshTokenRevoked( |
248 const std::string& account_id) { | 248 const std::string& account_id) { |
249 if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { | 249 if (signin_manager_->GetAuthenticatedAccountId() == account_id) { |
250 access_token_.clear(); | 250 access_token_.clear(); |
251 if (IsStarted()) { | 251 if (IsStarted()) { |
252 UpdateInvalidatorCredentials(); | 252 UpdateInvalidatorCredentials(); |
253 } | 253 } |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 void TiclInvalidationService::OnInvalidatorStateChange( | 257 void TiclInvalidationService::OnInvalidatorStateChange( |
258 syncer::InvalidatorState state) { | 258 syncer::InvalidatorState state) { |
259 if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) { | 259 if (state == syncer::INVALIDATION_CREDENTIALS_REJECTED) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 305 } |
306 | 306 |
307 if (!oauth2_token_service_) { | 307 if (!oauth2_token_service_) { |
308 DVLOG(2) | 308 DVLOG(2) |
309 << "Not starting TiclInvalidationService: " | 309 << "Not starting TiclInvalidationService: " |
310 << "OAuth2TokenService unavailable."; | 310 << "OAuth2TokenService unavailable."; |
311 return false; | 311 return false; |
312 } | 312 } |
313 | 313 |
314 if (!oauth2_token_service_->RefreshTokenIsAvailable( | 314 if (!oauth2_token_service_->RefreshTokenIsAvailable( |
315 oauth2_token_service_->GetPrimaryAccountId())) { | 315 signin_manager_->GetAuthenticatedAccountId())) { |
316 DVLOG(2) | 316 DVLOG(2) |
317 << "Not starting TiclInvalidationServce: Waiting for refresh token."; | 317 << "Not starting TiclInvalidationServce: Waiting for refresh token."; |
318 return false; | 318 return false; |
319 } | 319 } |
320 | 320 |
321 return true; | 321 return true; |
322 } | 322 } |
323 | 323 |
324 bool TiclInvalidationService::IsStarted() { | 324 bool TiclInvalidationService::IsStarted() { |
325 return invalidator_.get() != NULL; | 325 return invalidator_.get() != NULL; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 409 } |
410 | 410 |
411 // This service always expects to have a valid invalidator storage. | 411 // This service always expects to have a valid invalidator storage. |
412 // So we must not only clear the old one, but also start a new one. | 412 // So we must not only clear the old one, but also start a new one. |
413 invalidator_storage_->Clear(); | 413 invalidator_storage_->Clear(); |
414 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); | 414 invalidator_storage_.reset(new InvalidatorStorage(profile_->GetPrefs())); |
415 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); | 415 invalidator_storage_->SetInvalidatorClientId(GenerateInvalidatorClientId()); |
416 } | 416 } |
417 | 417 |
418 } // namespace invalidation | 418 } // namespace invalidation |
OLD | NEW |