Chromium Code Reviews| Index: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| index 1ba50c88fec7aee9d982dea9e15363259f7014f4..19b48e6e7c002c99edb5d14216ad67352adc6edb 100644 |
| --- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| @@ -11,11 +11,13 @@ |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/values.h" |
| +#include "chrome/browser/browser_process.h" |
|
dcheng
2014/03/20 17:33:36
What is this include for?
Mattias Nissler (ping if slow)
2014/03/20 17:40:09
Development artifact. Removed.
|
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/token_cache/token_cache_service.h" |
| #include "chrome/browser/extensions/token_cache/token_cache_service_factory.h" |
| +#include "chrome/browser/invalidation/invalidation_auth_provider.h" |
| #include "chrome/browser/invalidation/invalidation_service.h" |
| #include "chrome/browser/invalidation/invalidation_service_factory.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -23,7 +25,6 @@ |
| #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| #include "chrome/browser/signin/signin_manager.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| -#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| #include "chrome/common/extensions/api/push_messaging.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_details.h" |
| @@ -103,10 +104,10 @@ bool PushMessagingGetChannelIdFunction::RunImpl() { |
| AddRef(); |
| if (!IsUserLoggedIn()) { |
| - if (interactive_) { |
| - ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()) |
| - ->AddObserver(this); |
| - LoginUIServiceFactory::GetForProfile(GetProfile())->ShowLoginPopup(); |
| + invalidation::InvalidationAuthProvider* auth_provider = |
| + GetInvalidationAuthProvider(); |
| + if (interactive_ && auth_provider->ShowLoginUI()) { |
| + auth_provider->GetTokenService()->AddObserver(this); |
| return true; |
| } else { |
| error_ = kUserNotSignedIn; |
| @@ -125,18 +126,16 @@ void PushMessagingGetChannelIdFunction::StartAccessTokenFetch() { |
| std::vector<std::string> scope_vector = |
| extensions::ObfuscatedGaiaIdFetcher::GetScopes(); |
| OAuth2TokenService::ScopeSet scopes(scope_vector.begin(), scope_vector.end()); |
| - ProfileOAuth2TokenService* token_service = |
| - ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
| - SigninManagerBase* signin_manager = |
| - SigninManagerFactory::GetForProfile(GetProfile()); |
| - fetcher_access_token_request_ = token_service->StartRequest( |
| - signin_manager->GetAuthenticatedAccountId(), scopes, this); |
| + invalidation::InvalidationAuthProvider* auth_provider = |
| + GetInvalidationAuthProvider(); |
| + fetcher_access_token_request_ = |
| + auth_provider->GetTokenService()->StartRequest( |
| + auth_provider->GetAccountId(), scopes, this); |
| } |
| void PushMessagingGetChannelIdFunction::OnRefreshTokenAvailable( |
| const std::string& account_id) { |
| - ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()) |
| - ->RemoveObserver(this); |
| + GetInvalidationAuthProvider()->GetTokenService()->RemoveObserver(this); |
| DVLOG(2) << "Newly logged in: " << GetProfile()->GetProfileName(); |
| StartAccessTokenFetch(); |
| } |
| @@ -190,13 +189,11 @@ void PushMessagingGetChannelIdFunction::StartGaiaIdFetch( |
| } |
| // Check if the user is logged in. |
| -bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() const { |
| - ProfileOAuth2TokenService* token_service = |
| - ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
| - SigninManagerBase* signin_manager = |
| - SigninManagerFactory::GetForProfile(GetProfile()); |
| - return token_service->RefreshTokenIsAvailable( |
| - signin_manager->GetAuthenticatedAccountId()); |
| +bool PushMessagingGetChannelIdFunction::IsUserLoggedIn() { |
| + invalidation::InvalidationAuthProvider* auth_provider = |
| + GetInvalidationAuthProvider(); |
| + return auth_provider->GetTokenService()->RefreshTokenIsAvailable( |
| + auth_provider->GetAccountId()); |
| } |
| void PushMessagingGetChannelIdFunction::ReportResult( |
| @@ -264,12 +261,7 @@ void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure( |
| case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
| case GoogleServiceAuthError::ACCOUNT_DELETED: |
| case GoogleServiceAuthError::ACCOUNT_DISABLED: { |
| - if (interactive_) { |
| - LoginUIService* login_ui_service = |
| - LoginUIServiceFactory::GetForProfile(GetProfile()); |
| - // content::NotificationObserver will be called if token is issued. |
| - login_ui_service->ShowLoginPopup(); |
| - } else { |
| + if (!interactive_ || !GetInvalidationAuthProvider()->ShowLoginUI()) { |
| ReportResult(std::string(), error_text); |
| } |
| return; |
| @@ -281,6 +273,12 @@ void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure( |
| } |
| } |
| +invalidation::InvalidationAuthProvider* |
| +PushMessagingGetChannelIdFunction::GetInvalidationAuthProvider() { |
| + return invalidation::InvalidationServiceFactory::GetForProfile(GetProfile()) |
| + ->GetInvalidationAuthProvider(); |
| +} |
| + |
| PushMessagingAPI::PushMessagingAPI(content::BrowserContext* context) |
| : profile_(Profile::FromBrowserContext(context)) { |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |