| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/net/gaia/token_service.h" | 5 #include "chrome/browser/net/gaia/token_service.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/common/net/gaia/gaia_authenticator2.h" | 8 #include "chrome/common/net/gaia/gaia_authenticator2.h" |
| 9 #include "chrome/common/net/gaia/gaia_constants.h" | 9 #include "chrome/common/net/gaia/gaia_constants.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| 11 | 11 |
| 12 void TokenService::Initialize( | 12 void TokenService::Initialize( |
| 13 const char* const source, | 13 const char* const source, |
| 14 URLRequestContextGetter* getter, | 14 URLRequestContextGetter* getter, |
| 15 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 15 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
| 16 | 16 |
| 17 credentials_ = credentials; | 17 credentials_ = credentials; |
| 18 source_ = std::string(source); | 18 source_ = std::string(source); |
| 19 sync_token_fetcher_.reset(new GaiaAuthenticator2(this, source_, getter)); | 19 sync_token_fetcher_.reset(new GaiaAuthenticator2(this, source_, getter)); |
| 20 talk_token_fetcher_.reset(new GaiaAuthenticator2(this, source_, getter)); | 20 talk_token_fetcher_.reset(new GaiaAuthenticator2(this, source_, getter)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 const bool TokenService::AreCredentialsValid() const { | 23 bool TokenService::AreCredentialsValid() const { |
| 24 return !credentials_.lsid.empty() && !credentials_.sid.empty(); | 24 return !credentials_.lsid.empty() && !credentials_.sid.empty(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 const bool TokenService::HasLsid() const { | 27 bool TokenService::HasLsid() const { |
| 28 return !credentials_.lsid.empty(); | 28 return !credentials_.lsid.empty(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 const std::string& TokenService::GetLsid() const { | 31 const std::string& TokenService::GetLsid() const { |
| 32 return credentials_.lsid; | 32 return credentials_.lsid; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void TokenService::StartFetchingTokens() { | 35 void TokenService::StartFetchingTokens() { |
| 36 DCHECK(AreCredentialsValid()); | 36 DCHECK(AreCredentialsValid()); |
| 37 sync_token_fetcher_->StartIssueAuthToken(credentials_.sid, | 37 sync_token_fetcher_->StartIssueAuthToken(credentials_.sid, |
| 38 credentials_.lsid, | 38 credentials_.lsid, |
| 39 GaiaConstants::kSyncService); | 39 GaiaConstants::kSyncService); |
| 40 talk_token_fetcher_->StartIssueAuthToken(credentials_.sid, | 40 talk_token_fetcher_->StartIssueAuthToken(credentials_.sid, |
| 41 credentials_.lsid, | 41 credentials_.lsid, |
| 42 GaiaConstants::kTalkService); | 42 GaiaConstants::kTalkService); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Services dependent on a token will check if a token is available. | 45 // Services dependent on a token will check if a token is available. |
| 46 // If it isn't, they'll go to sleep until they get a token event. | 46 // If it isn't, they'll go to sleep until they get a token event. |
| 47 const bool TokenService::HasTokenForService(const char* const service) const { | 47 bool TokenService::HasTokenForService(const char* const service) const { |
| 48 return token_map_.count(service) > 0; | 48 return token_map_.count(service) > 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 const std::string& TokenService::GetTokenForService( | 51 const std::string& TokenService::GetTokenForService( |
| 52 const char* const service) const { | 52 const char* const service) const { |
| 53 | 53 |
| 54 if (token_map_.count(service) > 0) { | 54 if (token_map_.count(service) > 0) { |
| 55 // map[key] is not const | 55 // map[key] is not const |
| 56 return (*token_map_.find(service)).second; | 56 return (*token_map_.find(service)).second; |
| 57 } | 57 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 } | 70 } |
| 71 void TokenService::OnIssueAuthTokenFailure(const std::string& service, | 71 void TokenService::OnIssueAuthTokenFailure(const std::string& service, |
| 72 const GaiaAuthError& error) { | 72 const GaiaAuthError& error) { |
| 73 LOG(WARNING) << "Auth token issuing failed for service:" << service; | 73 LOG(WARNING) << "Auth token issuing failed for service:" << service; |
| 74 TokenRequestFailedDetails details(service, error); | 74 TokenRequestFailedDetails details(service, error); |
| 75 NotificationService::current()->Notify( | 75 NotificationService::current()->Notify( |
| 76 NotificationType::TOKEN_REQUEST_FAILED, | 76 NotificationType::TOKEN_REQUEST_FAILED, |
| 77 Source<TokenService>(this), | 77 Source<TokenService>(this), |
| 78 Details<const TokenRequestFailedDetails>(&details)); | 78 Details<const TokenRequestFailedDetails>(&details)); |
| 79 } | 79 } |
| OLD | NEW |