| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/signin/profile_oauth2_token_service.h" | 5 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 last_auth_error_(GoogleServiceAuthError::NONE) { | 61 last_auth_error_(GoogleServiceAuthError::NONE) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() { | 64 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() { |
| 65 DCHECK(!signin_global_error_.get()) << | 65 DCHECK(!signin_global_error_.get()) << |
| 66 "ProfileOAuth2TokenService::Initialize called but not " | 66 "ProfileOAuth2TokenService::Initialize called but not " |
| 67 "ProfileOAuth2TokenService::Shutdown"; | 67 "ProfileOAuth2TokenService::Shutdown"; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ProfileOAuth2TokenService::Initialize(Profile* profile) { | 70 void ProfileOAuth2TokenService::Initialize(Profile* profile) { |
| 71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 72 | |
| 73 DCHECK(profile); | 71 DCHECK(profile); |
| 74 DCHECK(!profile_); | 72 DCHECK(!profile_); |
| 75 profile_ = profile; | 73 profile_ = profile; |
| 76 | 74 |
| 77 signin_global_error_.reset(new SigninGlobalError(profile)); | 75 signin_global_error_.reset(new SigninGlobalError(profile)); |
| 78 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 76 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
| 79 signin_global_error_.get()); | 77 signin_global_error_.get()); |
| 80 signin_global_error_->AddProvider(this); | 78 signin_global_error_->AddProvider(this); |
| 81 | 79 |
| 82 content::Source<TokenService> token_service_source( | 80 content::Source<TokenService> token_service_source( |
| 83 TokenServiceFactory::GetForProfile(profile)); | 81 TokenServiceFactory::GetForProfile(profile)); |
| 84 registrar_.Add(this, | 82 registrar_.Add(this, |
| 85 chrome::NOTIFICATION_TOKENS_CLEARED, | 83 chrome::NOTIFICATION_TOKENS_CLEARED, |
| 86 token_service_source); | 84 token_service_source); |
| 87 registrar_.Add(this, | 85 registrar_.Add(this, |
| 88 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 86 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| 89 token_service_source); | 87 token_service_source); |
| 90 registrar_.Add(this, | 88 registrar_.Add(this, |
| 91 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, | 89 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
| 92 token_service_source); | 90 token_service_source); |
| 93 registrar_.Add(this, | 91 registrar_.Add(this, |
| 94 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, | 92 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
| 95 token_service_source); | 93 token_service_source); |
| 96 } | 94 } |
| 97 | 95 |
| 98 void ProfileOAuth2TokenService::Shutdown() { | 96 void ProfileOAuth2TokenService::Shutdown() { |
| 97 DCHECK(profile_) << "Shutdown() called without matching call to Initialize()"; |
| 99 CancelAllRequests(); | 98 CancelAllRequests(); |
| 100 signin_global_error_->RemoveProvider(this); | 99 signin_global_error_->RemoveProvider(this); |
| 101 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 100 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
| 102 signin_global_error_.get()); | 101 signin_global_error_.get()); |
| 103 signin_global_error_.reset(); | 102 signin_global_error_.reset(); |
| 104 } | 103 } |
| 105 | 104 |
| 106 std::string ProfileOAuth2TokenService::GetRefreshToken() { | 105 std::string ProfileOAuth2TokenService::GetRefreshToken() { |
| 107 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 106 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 108 if (!token_service || !token_service->HasOAuthLoginToken()) { | 107 if (!token_service || !token_service->HasOAuthLoginToken()) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 338 } |
| 340 } | 339 } |
| 341 | 340 |
| 342 if (!old_login_token.empty() && | 341 if (!old_login_token.empty() && |
| 343 refresh_tokens_.count(GetAccountId(profile_)) == 0) { | 342 refresh_tokens_.count(GetAccountId(profile_)) == 0) { |
| 344 UpdateCredentials(GetAccountId(profile_), old_login_token); | 343 UpdateCredentials(GetAccountId(profile_), old_login_token); |
| 345 } | 344 } |
| 346 | 345 |
| 347 FireRefreshTokensLoaded(); | 346 FireRefreshTokensLoaded(); |
| 348 } | 347 } |
| OLD | NEW |