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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DVLOG(2) << "Logged in profile name: " << profile()->GetProfileName(); | 120 DVLOG(2) << "Logged in profile name: " << profile()->GetProfileName(); |
121 | 121 |
122 StartAccessTokenFetch(); | 122 StartAccessTokenFetch(); |
123 return true; | 123 return true; |
124 } | 124 } |
125 | 125 |
126 void PushMessagingGetChannelIdFunction::StartAccessTokenFetch() { | 126 void PushMessagingGetChannelIdFunction::StartAccessTokenFetch() { |
127 std::vector<std::string> scope_vector = | 127 std::vector<std::string> scope_vector = |
128 extensions::ObfuscatedGaiaIdFetcher::GetScopes(); | 128 extensions::ObfuscatedGaiaIdFetcher::GetScopes(); |
129 OAuth2TokenService::ScopeSet scopes(scope_vector.begin(), scope_vector.end()); | 129 OAuth2TokenService::ScopeSet scopes(scope_vector.begin(), scope_vector.end()); |
130 fetcher_access_token_request_ = | 130 ProfileOAuth2TokenService* token_service = |
131 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) | 131 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
132 ->StartRequest(scopes, this); | 132 fetcher_access_token_request_ = token_service->StartRequest( |
| 133 token_service->GetPrimaryAccountId(), scopes, this); |
133 } | 134 } |
134 | 135 |
135 void PushMessagingGetChannelIdFunction::OnRefreshTokenAvailable( | 136 void PushMessagingGetChannelIdFunction::OnRefreshTokenAvailable( |
136 const std::string& account_id) { | 137 const std::string& account_id) { |
137 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) | 138 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) |
138 ->RemoveObserver(this); | 139 ->RemoveObserver(this); |
139 DVLOG(2) << "Newly logged in: " << profile()->GetProfileName(); | 140 DVLOG(2) << "Newly logged in: " << profile()->GetProfileName(); |
140 StartAccessTokenFetch(); | 141 StartAccessTokenFetch(); |
141 } | 142 } |
142 | 143 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (!gaia_id.empty()) { | 184 if (!gaia_id.empty()) { |
184 ReportResult(gaia_id, std::string()); | 185 ReportResult(gaia_id, std::string()); |
185 return; | 186 return; |
186 } | 187 } |
187 | 188 |
188 fetcher_->Start(); | 189 fetcher_->Start(); |
189 } | 190 } |
190 | 191 |
191 // Check if the user is logged in. | 192 // Check if the user is logged in. |
192 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const { | 193 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const { |
193 return ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) | 194 ProfileOAuth2TokenService* token_service = |
194 ->RefreshTokenIsAvailable(); | 195 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
| 196 return token_service->RefreshTokenIsAvailable( |
| 197 token_service->GetPrimaryAccountId()); |
195 } | 198 } |
196 | 199 |
197 void PushMessagingGetChannelIdFunction::ReportResult( | 200 void PushMessagingGetChannelIdFunction::ReportResult( |
198 const std::string& gaia_id, const std::string& error_string) { | 201 const std::string& gaia_id, const std::string& error_string) { |
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
200 | 203 |
201 BuildAndSendResult(gaia_id, error_string); | 204 BuildAndSendResult(gaia_id, error_string); |
202 | 205 |
203 // Cache the obfuscated ID locally. It never changes for this user, | 206 // Cache the obfuscated ID locally. It never changes for this user, |
204 // and if we call the web API too often, we get errors due to rate limiting. | 207 // and if we call the web API too often, we get errors due to rate limiting. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 handler_ = mapper.Pass(); | 360 handler_ = mapper.Pass(); |
358 } | 361 } |
359 | 362 |
360 template <> | 363 template <> |
361 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { | 364 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { |
362 DependsOn(ExtensionSystemFactory::GetInstance()); | 365 DependsOn(ExtensionSystemFactory::GetInstance()); |
363 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); | 366 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); |
364 } | 367 } |
365 | 368 |
366 } // namespace extensions | 369 } // namespace extensions |
OLD | NEW |