| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/push_messaging/push_messaging_api.h" | 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // handling for the identity related code. | 160 // handling for the identity related code. |
| 161 DVLOG(1) << "Cannot obtain access token for this user " | 161 DVLOG(1) << "Cannot obtain access token for this user " |
| 162 << error.error_message() << " " << error.state(); | 162 << error.error_message() << " " << error.state(); |
| 163 error_ = kUserAccessTokenFailure; | 163 error_ = kUserAccessTokenFailure; |
| 164 ReportResult(std::string(), error_); | 164 ReportResult(std::string(), error_); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void PushMessagingGetChannelIdFunction::StartGaiaIdFetch( | 167 void PushMessagingGetChannelIdFunction::StartGaiaIdFetch( |
| 168 const std::string& access_token) { | 168 const std::string& access_token) { |
| 169 // Start the async fetch of the Gaia Id. | 169 // Start the async fetch of the Gaia Id. |
| 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 170 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 171 net::URLRequestContextGetter* context = GetProfile()->GetRequestContext(); | 171 net::URLRequestContextGetter* context = GetProfile()->GetRequestContext(); |
| 172 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, access_token)); | 172 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, access_token)); |
| 173 | 173 |
| 174 // Get the token cache and see if we have already cached a Gaia Id. | 174 // Get the token cache and see if we have already cached a Gaia Id. |
| 175 TokenCacheService* token_cache = | 175 TokenCacheService* token_cache = |
| 176 TokenCacheServiceFactory::GetForProfile(GetProfile()); | 176 TokenCacheServiceFactory::GetForProfile(GetProfile()); |
| 177 | 177 |
| 178 // Check the cache, if we already have a Gaia ID, use it instead of | 178 // Check the cache, if we already have a Gaia ID, use it instead of |
| 179 // fetching the ID over the network. | 179 // fetching the ID over the network. |
| 180 const std::string& gaia_id = | 180 const std::string& gaia_id = |
| 181 token_cache->RetrieveToken(GaiaConstants::kObfuscatedGaiaId); | 181 token_cache->RetrieveToken(GaiaConstants::kObfuscatedGaiaId); |
| 182 if (!gaia_id.empty()) { | 182 if (!gaia_id.empty()) { |
| 183 ReportResult(gaia_id, std::string()); | 183 ReportResult(gaia_id, std::string()); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 | 186 |
| 187 fetcher_->Start(); | 187 fetcher_->Start(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Check if the user is logged in. | 190 // Check if the user is logged in. |
| 191 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() { | 191 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() { |
| 192 invalidation::InvalidationAuthProvider* auth_provider = | 192 invalidation::InvalidationAuthProvider* auth_provider = |
| 193 GetInvalidationAuthProvider(); | 193 GetInvalidationAuthProvider(); |
| 194 return auth_provider->GetTokenService()->RefreshTokenIsAvailable( | 194 return auth_provider->GetTokenService()->RefreshTokenIsAvailable( |
| 195 auth_provider->GetAccountId()); | 195 auth_provider->GetAccountId()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void PushMessagingGetChannelIdFunction::ReportResult( | 198 void PushMessagingGetChannelIdFunction::ReportResult( |
| 199 const std::string& gaia_id, const std::string& error_string) { | 199 const std::string& gaia_id, const std::string& error_string) { |
| 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 201 | 201 |
| 202 BuildAndSendResult(gaia_id, error_string); | 202 BuildAndSendResult(gaia_id, error_string); |
| 203 | 203 |
| 204 // Cache the obfuscated ID locally. It never changes for this user, | 204 // Cache the obfuscated ID locally. It never changes for this user, |
| 205 // and if we call the web API too often, we get errors due to rate limiting. | 205 // and if we call the web API too often, we get errors due to rate limiting. |
| 206 if (!gaia_id.empty()) { | 206 if (!gaia_id.empty()) { |
| 207 base::TimeDelta timeout = | 207 base::TimeDelta timeout = |
| 208 base::TimeDelta::FromDays(kObfuscatedGaiaIdTimeoutInDays); | 208 base::TimeDelta::FromDays(kObfuscatedGaiaIdTimeoutInDays); |
| 209 TokenCacheService* token_cache = | 209 TokenCacheService* token_cache = |
| 210 TokenCacheServiceFactory::GetForProfile(GetProfile()); | 210 TokenCacheServiceFactory::GetForProfile(GetProfile()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 | 362 |
| 363 template <> | 363 template <> |
| 364 void | 364 void |
| 365 BrowserContextKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { | 365 BrowserContextKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { |
| 366 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 366 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 367 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); | 367 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 } // namespace extensions | 370 } // namespace extensions |
| OLD | NEW |