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

Side by Side Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc

Issue 23382008: Making OAuth2TokenService multi-login aware, updating callers, minor fixes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing to include the update to ProfileSyncService: r224220 Created 7 years, 3 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"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DVLOG(2) << "Logged in profile name: " << profile()->GetProfileName(); 119 DVLOG(2) << "Logged in profile name: " << profile()->GetProfileName();
120 120
121 StartAccessTokenFetch(); 121 StartAccessTokenFetch();
122 return true; 122 return true;
123 } 123 }
124 124
125 void PushMessagingGetChannelIdFunction::StartAccessTokenFetch() { 125 void PushMessagingGetChannelIdFunction::StartAccessTokenFetch() {
126 std::vector<std::string> scope_vector = 126 std::vector<std::string> scope_vector =
127 extensions::ObfuscatedGaiaIdFetcher::GetScopes(); 127 extensions::ObfuscatedGaiaIdFetcher::GetScopes();
128 OAuth2TokenService::ScopeSet scopes(scope_vector.begin(), scope_vector.end()); 128 OAuth2TokenService::ScopeSet scopes(scope_vector.begin(), scope_vector.end());
129 fetcher_access_token_request_ = 129 ProfileOAuth2TokenService* token_service =
130 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) 130 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
131 ->StartRequest(scopes, this); 131 fetcher_access_token_request_ = token_service->StartRequest(
132 token_service->GetPrimaryAccountId(), scopes, this);
132 } 133 }
133 134
134 void PushMessagingGetChannelIdFunction::OnRefreshTokenAvailable( 135 void PushMessagingGetChannelIdFunction::OnRefreshTokenAvailable(
135 const std::string& account_id) { 136 const std::string& account_id) {
136 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) 137 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())
137 ->RemoveObserver(this); 138 ->RemoveObserver(this);
138 DVLOG(2) << "Newly logged in: " << profile()->GetProfileName(); 139 DVLOG(2) << "Newly logged in: " << profile()->GetProfileName();
139 StartAccessTokenFetch(); 140 StartAccessTokenFetch();
140 } 141 }
141 142
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 if (!gaia_id.empty()) { 183 if (!gaia_id.empty()) {
183 ReportResult(gaia_id, std::string()); 184 ReportResult(gaia_id, std::string());
184 return; 185 return;
185 } 186 }
186 187
187 fetcher_->Start(); 188 fetcher_->Start();
188 } 189 }
189 190
190 // Check if the user is logged in. 191 // Check if the user is logged in.
191 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const { 192 bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const {
192 return ProfileOAuth2TokenServiceFactory::GetForProfile(profile()) 193 ProfileOAuth2TokenService* token_service =
193 ->RefreshTokenIsAvailable(); 194 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
195 return token_service->RefreshTokenIsAvailable(
196 token_service->GetPrimaryAccountId());
194 } 197 }
195 198
196 void PushMessagingGetChannelIdFunction::ReportResult( 199 void PushMessagingGetChannelIdFunction::ReportResult(
197 const std::string& gaia_id, const std::string& error_string) { 200 const std::string& gaia_id, const std::string& error_string) {
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 202
200 BuildAndSendResult(gaia_id, error_string); 203 BuildAndSendResult(gaia_id, error_string);
201 204
202 // Cache the obfuscated ID locally. It never changes for this user, 205 // Cache the obfuscated ID locally. It never changes for this user,
203 // and if we call the web API too often, we get errors due to rate limiting. 206 // 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
356 handler_ = mapper.Pass(); 359 handler_ = mapper.Pass();
357 } 360 }
358 361
359 template <> 362 template <>
360 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { 363 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() {
361 DependsOn(ExtensionSystemFactory::GetInstance()); 364 DependsOn(ExtensionSystemFactory::GetInstance());
362 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); 365 DependsOn(invalidation::InvalidationServiceFactory::GetInstance());
363 } 366 }
364 367
365 } // namespace extensions 368 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | chrome/browser/google_apis/auth_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698