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" |
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/event_names.h" | 15 #include "chrome/browser/extensions/event_names.h" |
16 #include "chrome/browser/extensions/event_router.h" | 16 #include "chrome/browser/extensions/event_router.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
19 #include "chrome/browser/extensions/extension_system_factory.h" | 19 #include "chrome/browser/extensions/extension_system_factory.h" |
20 #include "chrome/browser/extensions/token_cache/token_cache.h" | |
21 #include "chrome/browser/extensions/token_cache/token_cache_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" |
25 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 27 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
26 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/extensions/api/push_messaging.h" | 29 #include "chrome/common/extensions/api/push_messaging.h" |
28 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
29 #include "chrome/common/extensions/extension_set.h" | 31 #include "chrome/common/extensions/extension_set.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
137 fetcher_->Start(); | 143 fetcher_->Start(); |
138 | 144 |
139 // Will finish asynchronously. | 145 // Will finish asynchronously. |
140 return true; | 146 return true; |
141 } | 147 } |
(...skipping 24 matching lines...) Expand all Loading... | |
166 | 172 |
167 void PushMessagingGetChannelIdFunction::ReportResult( | 173 void PushMessagingGetChannelIdFunction::ReportResult( |
168 const std::string& gaia_id, const std::string& error_string) { | 174 const std::string& gaia_id, const std::string& error_string) { |
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
170 | 176 |
171 BuildAndSendResult(gaia_id, error_string); | 177 BuildAndSendResult(gaia_id, error_string); |
172 | 178 |
173 // Cache the obfuscated ID locally. It never changes for this user, | 179 // 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. | 180 // and if we call the web API too often, we get errors due to rate limiting. |
175 if (!gaia_id.empty()) { | 181 if (!gaia_id.empty()) { |
176 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); | 182 int timeoutDays = GaiaConstants::kObfuscatedGaiaIdTimeoutInDays; |
dcheng
2013/03/05 22:38:44
Naming is incorrect. Also, I'd suggest just doing
Pete Williamson
2013/03/06 00:09:40
Done.
| |
177 if (token_service) { | 183 TokenCacheService* token_cache = |
178 token_service->AddAuthTokenManually(GaiaConstants::kObfuscatedGaiaId, | 184 TokenCacheServiceFactory::GetForProfile(profile()); |
179 gaia_id); | 185 token_cache->StoreToken(GaiaConstants::kObfuscatedGaiaId, gaia_id, |
180 } | 186 base::TimeDelta::FromDays(timeoutDays)); |
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 Loading... | |
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 |
OLD | NEW |