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

Side by Side 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 - CR changes per DCheng and ATWilson 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler.h" 14 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler.h"
15 #include "chrome/browser/extensions/api/token_cache/token_cache.h"
16 #include "chrome/browser/extensions/api/token_cache/token_cache_factory.h"
15 #include "chrome/browser/extensions/event_names.h" 17 #include "chrome/browser/extensions/event_names.h"
16 #include "chrome/browser/extensions/event_router.h" 18 #include "chrome/browser/extensions/event_router.h"
17 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.h"
19 #include "chrome/browser/extensions/extension_system_factory.h" 21 #include "chrome/browser/extensions/extension_system_factory.h"
20 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/signin/token_service.h" 23 #include "chrome/browser/signin/token_service.h"
22 #include "chrome/browser/signin/token_service_factory.h" 24 #include "chrome/browser/signin/token_service_factory.h"
23 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 26 #include "chrome/browser/sync/profile_sync_service_factory.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 net::URLRequestContextGetter* context = profile()->GetRequestContext(); 120 net::URLRequestContextGetter* context = profile()->GetRequestContext();
119 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); 121 TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
120 if (!token_service) { 122 if (!token_service) {
121 ReportResult(std::string(), std::string(kTokenServiceNotAvailable)); 123 ReportResult(std::string(), std::string(kTokenServiceNotAvailable));
122 return false; 124 return false;
123 } 125 }
124 const std::string& refresh_token = 126 const std::string& refresh_token =
125 token_service->GetOAuth2LoginRefreshToken(); 127 token_service->GetOAuth2LoginRefreshToken();
126 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token)); 128 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token));
127 129
130 // Get the token cache and see if we have already cached a Gaia Id.
131 TokenCacheService* token_cache =
132 TokenCacheServiceFactory::GetForProfile(profile());
133
128 // Check the cache, if we already have a gaia ID, use it instead of 134 // Check the cache, if we already have a gaia ID, use it instead of
129 // fetching the ID over the network. 135 // fetching the ID over the network.
130 const std::string& gaia_id = 136 const std::string& gaia_id =
131 token_service->GetTokenForService(GaiaConstants::kObfuscatedGaiaId); 137 token_cache->RetrieveToken(GaiaConstants::kObfuscatedGaiaId);
132 if (!gaia_id.empty()) { 138 if (!gaia_id.empty()) {
133 ReportResult(gaia_id, std::string()); 139 ReportResult(gaia_id, std::string());
134 return true; 140 return true;
135 } 141 }
136 142
143
dcheng 2013/03/04 22:40:59 Remove newline?
Pete Williamson 2013/03/05 19:42:25 Done.
137 fetcher_->Start(); 144 fetcher_->Start();
138 145
139 // Will finish asynchronously. 146 // Will finish asynchronously.
140 return true; 147 return true;
141 } 148 }
142 149
143 // Check if the user is logged in. 150 // Check if the user is logged in.
144 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const { 151 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const {
145 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); 152 TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
146 if (!token_service) 153 if (!token_service)
(...skipping 19 matching lines...) Expand all
166 173
167 void PushMessagingGetChannelIdFunction::ReportResult( 174 void PushMessagingGetChannelIdFunction::ReportResult(
168 const std::string& gaia_id, const std::string& error_string) { 175 const std::string& gaia_id, const std::string& error_string) {
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
170 177
171 BuildAndSendResult(gaia_id, error_string); 178 BuildAndSendResult(gaia_id, error_string);
172 179
173 // Cache the obfuscated ID locally. It never changes for this user, 180 // Cache the obfuscated ID locally. It never changes for this user,
174 // and if we call the web API too often, we get errors due to rate limiting. 181 // and if we call the web API too often, we get errors due to rate limiting.
175 if (!gaia_id.empty()) { 182 if (!gaia_id.empty()) {
176 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); 183 TokenCacheService* token_cache =
177 if (token_service) { 184 TokenCacheServiceFactory::GetForProfile(profile());
178 token_service->AddAuthTokenManually(GaiaConstants::kObfuscatedGaiaId, 185 token_cache->StoreToken(GaiaConstants::kObfuscatedGaiaId, gaia_id,
179 gaia_id); 186 GaiaConstants::kObfuscatedGaiaIdTimeout);
180 }
181 } 187 }
182 188
183 // Balanced in RunImpl. 189 // Balanced in RunImpl.
184 Release(); 190 Release();
185 } 191 }
186 192
187 void PushMessagingGetChannelIdFunction::BuildAndSendResult( 193 void PushMessagingGetChannelIdFunction::BuildAndSendResult(
188 const std::string& gaia_id, const std::string& error_message) { 194 const std::string& gaia_id, const std::string& error_message) {
189 std::string channel_id; 195 std::string channel_id;
190 if (!gaia_id.empty()) { 196 if (!gaia_id.empty()) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 handler_ = mapper.Pass(); 300 handler_ = mapper.Pass();
295 } 301 }
296 302
297 template <> 303 template <>
298 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { 304 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() {
299 DependsOn(ExtensionSystemFactory::GetInstance()); 305 DependsOn(ExtensionSystemFactory::GetInstance());
300 DependsOn(ProfileSyncServiceFactory::GetInstance()); 306 DependsOn(ProfileSyncServiceFactory::GetInstance());
301 } 307 }
302 308
303 } // namespace extensions 309 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698