| Index: chrome/browser/net/gaia/token_service.cc
|
| ===================================================================
|
| --- chrome/browser/net/gaia/token_service.cc (revision 111790)
|
| +++ chrome/browser/net/gaia/token_service.cc (working copy)
|
| @@ -160,6 +160,15 @@
|
| web_data_service_->RemoveAllTokens();
|
| }
|
|
|
| +// static
|
| +int TokenService::GetServiceIndex(const std::string& service) {
|
| + for (int i = 0; i < kNumServices; ++i) {
|
| + if (kServices[i] == service)
|
| + return i;
|
| + }
|
| + return -1;
|
| +}
|
| +
|
| bool TokenService::AreCredentialsValid() const {
|
| return !credentials_.lsid.empty() && !credentials_.sid.empty();
|
| }
|
| @@ -239,6 +248,18 @@
|
| return EmptyString();
|
| }
|
|
|
| +bool TokenService::HasOAuthLoginToken() const {
|
| + return HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken);
|
| +}
|
| +
|
| +const std::string& TokenService::GetOAuth2LoginRefreshToken() const {
|
| + return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken);
|
| +}
|
| +
|
| +const std::string& TokenService::GetOAuth2LoginAccessToken() const {
|
| + return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken);
|
| +}
|
| +
|
| // Note that this can fire twice or more for any given service.
|
| // It can fire once from the DB read, and then once from the initial
|
| // fetcher. Future fetches can cause more notification firings.
|
| @@ -279,6 +300,13 @@
|
| token_map_[service] = auth_token;
|
| FireTokenAvailableNotification(service, auth_token);
|
| SaveAuthTokenToDB(service, auth_token);
|
| + // If we got ClientLogin token for "lso" service, then start fetching OAuth2
|
| + // login scoped token pair.
|
| + if (service == GaiaConstants::kLSOService) {
|
| + int index = GetServiceIndex(service);
|
| + DCHECK_NE(-1, index);
|
| + fetchers_[index]->StartOAuthLoginTokenFetch(auth_token);
|
| + }
|
| }
|
|
|
| void TokenService::OnIssueAuthTokenFailure(const std::string& service,
|
| @@ -288,6 +316,31 @@
|
| FireTokenRequestFailedNotification(service, error);
|
| }
|
|
|
| +void TokenService::OnOAuthLoginTokenSuccess(const std::string& refresh_token,
|
| + const std::string& access_token,
|
| + int expires_in_secs) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + VLOG(1) << "Got OAuth2 login token pair";
|
| + token_map_[GaiaConstants::kGaiaOAuth2LoginRefreshToken] = refresh_token;
|
| + token_map_[GaiaConstants::kGaiaOAuth2LoginAccessToken] = access_token;
|
| + SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
|
| + refresh_token);
|
| + SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginAccessToken,
|
| + access_token);
|
| + // We don't save expiration information for now.
|
| +
|
| + FireTokenAvailableNotification(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
|
| + refresh_token);
|
| +}
|
| +
|
| +void TokenService::OnOAuthLoginTokenFailure(
|
| + const GoogleServiceAuthError& error) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + LOG(WARNING) << "OAuth2 login token pair fetch failed:";
|
| + FireTokenRequestFailedNotification(
|
| + GaiaConstants::kGaiaOAuth2LoginRefreshToken, error);
|
| +}
|
| +
|
| void TokenService::OnOAuthGetAccessTokenSuccess(const std::string& token,
|
| const std::string& secret) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| @@ -348,25 +401,12 @@
|
| std::map<std::string, std::string>* in_memory_tokens) {
|
|
|
| for (int i = 0; i < kNumServices; i++) {
|
| - // OnIssueAuthTokenSuccess should come from the same thread.
|
| - // If a token is already present in the map, it could only have
|
| - // come from a DB read or from IssueAuthToken. Since we should never
|
| - // fetch from the DB twice in a browser session, it must be from
|
| - // OnIssueAuthTokenSuccess, which is a live fetcher.
|
| - //
|
| - // Network fetched tokens take priority over DB tokens, so exclude tokens
|
| - // which have already been loaded by the fetcher.
|
| - if (!in_memory_tokens->count(kServices[i]) &&
|
| - db_tokens.count(kServices[i])) {
|
| - std::string db_token = db_tokens.find(kServices[i])->second;
|
| - if (!db_token.empty()) {
|
| - VLOG(1) << "Loading " << kServices[i] << " token from DB: " << db_token;
|
| - (*in_memory_tokens)[kServices[i]] = db_token;
|
| - FireTokenAvailableNotification(kServices[i], db_token);
|
| - // Failures are only for network errors.
|
| - }
|
| - }
|
| + LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]);
|
| }
|
| + LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens,
|
| + GaiaConstants::kGaiaOAuth2LoginRefreshToken);
|
| + LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens,
|
| + GaiaConstants::kGaiaOAuth2LoginAccessToken);
|
|
|
| if (credentials_.lsid.empty() && credentials_.sid.empty()) {
|
| // Look for GAIA SID and LSID tokens. If we have both, and the current
|
| @@ -389,25 +429,7 @@
|
| }
|
|
|
| for (int i = 0; i < kNumOAuthServices; i++) {
|
| - // OnIssueAuthTokenSuccess should come from the same thread.
|
| - // If a token is already present in the map, it could only have
|
| - // come from a DB read or from IssueAuthToken. Since we should never
|
| - // fetch from the DB twice in a browser session, it must be from
|
| - // OnIssueAuthTokenSuccess, which is a live fetcher.
|
| - //
|
| - // Network fetched tokens take priority over DB tokens, so exclude tokens
|
| - // which have already been loaded by the fetcher.
|
| - if (!in_memory_tokens->count(kOAuthServices[i]) &&
|
| - db_tokens.count(kOAuthServices[i])) {
|
| - std::string db_token = db_tokens.find(kOAuthServices[i])->second;
|
| - if (!db_token.empty()) {
|
| - VLOG(1) << "Loading " << kOAuthServices[i] << " OAuth token from DB: "
|
| - << db_token;
|
| - (*in_memory_tokens)[kOAuthServices[i]] = db_token;
|
| - FireTokenAvailableNotification(kOAuthServices[i], db_token);
|
| - // Failures are only for network errors.
|
| - }
|
| - }
|
| + LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kOAuthServices[i]);
|
| }
|
|
|
| if (oauth_token_.empty() && oauth_secret_.empty()) {
|
| @@ -428,6 +450,29 @@
|
| }
|
| }
|
|
|
| +void TokenService::LoadSingleTokenIntoMemory(
|
| + const std::map<std::string, std::string>& db_tokens,
|
| + std::map<std::string, std::string>* in_memory_tokens,
|
| + const std::string& service) {
|
| + // OnIssueAuthTokenSuccess should come from the same thread.
|
| + // If a token is already present in the map, it could only have
|
| + // come from a DB read or from IssueAuthToken. Since we should never
|
| + // fetch from the DB twice in a browser session, it must be from
|
| + // OnIssueAuthTokenSuccess, which is a live fetcher.
|
| + //
|
| + // Network fetched tokens take priority over DB tokens, so exclude tokens
|
| + // which have already been loaded by the fetcher.
|
| + if (!in_memory_tokens->count(service) && db_tokens.count(service)) {
|
| + std::string db_token = db_tokens.find(service)->second;
|
| + if (!db_token.empty()) {
|
| + VLOG(1) << "Loading " << service << " token from DB: " << db_token;
|
| + (*in_memory_tokens)[service] = db_token;
|
| + FireTokenAvailableNotification(service, db_token);
|
| + // Failures are only for network errors.
|
| + }
|
| + }
|
| +}
|
| +
|
| void TokenService::Observe(int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
|
|