Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4430)

Unified Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc

Issue 12380006: Build a new TokenCacheService so I can stop using TokenService for something it wasn't designed for. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Token Cache Service - post LGTM nits and merging with master Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/token_cache/token_cache_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
index 4dcbee4e6a0655fa4473406da68aee28070423da..f4bdedc2fe6f00a4ab3699bdcfd00eda183fb34a 100644
--- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
+++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
@@ -17,6 +17,8 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_system_factory.h"
+#include "chrome/browser/extensions/token_cache/token_cache_service.h"
+#include "chrome/browser/extensions/token_cache/token_cache_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/signin/token_service_factory.h"
@@ -40,6 +42,7 @@ namespace {
const char kChannelIdSeparator[] = "/";
const char kUserNotSignedIn[] = "The user is not signed in.";
const char kTokenServiceNotAvailable[] = "Failed to get token service.";
+const int kObfuscatedGaiaIdTimeoutInDays = 30;
}
namespace extensions {
@@ -130,10 +133,14 @@ bool PushMessagingGetChannelIdFunction::StartGaiaIdFetch() {
token_service->GetOAuth2LoginRefreshToken();
fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token));
+ // Get the token cache and see if we have already cached a Gaia Id.
+ TokenCacheService* token_cache =
+ TokenCacheServiceFactory::GetForProfile(profile());
+
// Check the cache, if we already have a gaia ID, use it instead of
// fetching the ID over the network.
const std::string& gaia_id =
- token_service->GetTokenForService(GaiaConstants::kObfuscatedGaiaId);
+ token_cache->RetrieveToken(GaiaConstants::kObfuscatedGaiaId);
if (!gaia_id.empty()) {
ReportResult(gaia_id, std::string());
return true;
@@ -178,11 +185,12 @@ void PushMessagingGetChannelIdFunction::ReportResult(
// Cache the obfuscated ID locally. It never changes for this user,
// and if we call the web API too often, we get errors due to rate limiting.
if (!gaia_id.empty()) {
- TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
- if (token_service) {
- token_service->AddAuthTokenManually(GaiaConstants::kObfuscatedGaiaId,
- gaia_id);
- }
+ base::TimeDelta timeout =
+ base::TimeDelta::FromDays(kObfuscatedGaiaIdTimeoutInDays);
+ TokenCacheService* token_cache =
+ TokenCacheServiceFactory::GetForProfile(profile());
+ token_cache->StoreToken(GaiaConstants::kObfuscatedGaiaId, gaia_id,
+ timeout);
}
// Balanced in RunImpl.
« no previous file with comments | « no previous file | chrome/browser/extensions/token_cache/token_cache_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698