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/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/signin/token_service.h" | 21 #include "chrome/browser/signin/token_service.h" |
22 #include "chrome/browser/signin/token_service_factory.h" | 22 #include "chrome/browser/signin/token_service_factory.h" |
dcheng
2013/02/28 19:18:04
Seems like we don't need these includes anymore.
Pete Williamson
2013/03/04 18:32:53
Nope, these are still used elsewhere (StartGaiaIdF
| |
23 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/token_cache/token_cache.h" | |
26 #include "chrome/browser/token_cache/token_cache_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" |
30 #include "chrome/common/extensions/permissions/api_permission.h" | 32 #include "chrome/common/extensions/permissions/api_permission.h" |
31 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
33 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
34 #include "google_apis/gaia/gaia_constants.h" | 36 #include "google_apis/gaia/gaia_constants.h" |
(...skipping 83 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 |
128 // Check the cache, if we already have a gaia ID, use it instead of | 130 // Get the token cache and see if we have already cached a Gaia Id. |
129 // fetching the ID over the network. | 131 TokenCacheService* token_cache = |
130 const std::string& gaia_id = | 132 TokenCacheServiceFactory::GetForProfile(profile()); |
131 token_service->GetTokenForService(GaiaConstants::kObfuscatedGaiaId); | 133 if (token_cache != NULL) { |
dcheng
2013/02/28 19:18:04
Why would this be NULL?
Pete Williamson
2013/03/04 18:32:53
I was thinking out of memory in the token cache se
| |
132 if (!gaia_id.empty()) { | 134 // Check the cache, if we already have a gaia ID, use it instead of |
133 ReportResult(gaia_id, std::string()); | 135 // fetching the ID over the network. |
134 return true; | 136 const std::string& gaia_id = |
137 token_cache->RetrieveToken(GaiaConstants::kObfuscatedGaiaId); | |
138 if (!gaia_id.empty()) { | |
139 ReportResult(gaia_id, std::string()); | |
140 return true; | |
141 } | |
135 } | 142 } |
136 | 143 |
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 { |
(...skipping 21 matching lines...) Expand all Loading... | |
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 if (token_cache) { |
dcheng
2013/02/28 19:18:04
Ditto. Why would this be NULL?
Pete Williamson
2013/03/04 18:32:53
Done.
| |
179 gaia_id); | 186 token_cache->StoreToken(GaiaConstants::kObfuscatedGaiaId, gaia_id, |
187 GaiaConstants::kObfuscatedGaiaIdTimeout); | |
180 } | 188 } |
181 } | 189 } |
182 | 190 |
183 // Balanced in RunImpl. | 191 // Balanced in RunImpl. |
184 Release(); | 192 Release(); |
185 } | 193 } |
186 | 194 |
187 void PushMessagingGetChannelIdFunction::BuildAndSendResult( | 195 void PushMessagingGetChannelIdFunction::BuildAndSendResult( |
188 const std::string& gaia_id, const std::string& error_message) { | 196 const std::string& gaia_id, const std::string& error_message) { |
189 std::string channel_id; | 197 std::string channel_id; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 handler_ = mapper.Pass(); | 302 handler_ = mapper.Pass(); |
295 } | 303 } |
296 | 304 |
297 template <> | 305 template <> |
298 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { | 306 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { |
299 DependsOn(ExtensionSystemFactory::GetInstance()); | 307 DependsOn(ExtensionSystemFactory::GetInstance()); |
300 DependsOn(ProfileSyncServiceFactory::GetInstance()); | 308 DependsOn(ProfileSyncServiceFactory::GetInstance()); |
301 } | 309 } |
302 | 310 |
303 } // namespace extensions | 311 } // namespace extensions |
OLD | NEW |