identity_signin_flow.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/extensions/api/identity/identity_signin_flow.h" 6 7#include "chrome/browser/app_mode/app_mode_utils.h" 8#include "chrome/browser/signin/token_service.h" 9#include "chrome/browser/signin/token_service_factory.h" 10#include "chrome/browser/ui/webui/signin/login_ui_service.h" 11#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 12#include "chrome/common/chrome_notification_types.h" 13#include "content/public/browser/notification_details.h" 14#include "google_apis/gaia/gaia_constants.h" 15 16namespace extensions { 17 18IdentitySigninFlow::IdentitySigninFlow(Delegate* delegate, Profile* profile) 19 : delegate_(delegate), 20 profile_(profile) { 21} 22 23IdentitySigninFlow::~IdentitySigninFlow() { 24} 25 26void IdentitySigninFlow::Start() { 27 DCHECK(delegate_); 28 29#if defined(OS_CHROMEOS) 30 // In normal mode (i.e. non-forced app mode), the user has to log out to 31 // re-establish credentials. Let the global error popup handle everything. 32 if (!chrome::IsRunningInForcedAppMode()) { 33 delegate_->SigninFailed(); 34 return; 35 } 36#endif 37 38 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 39 registrar_.Add(this, 40 chrome::NOTIFICATION_TOKEN_AVAILABLE, 41 content::Source<TokenService>(token_service)); 42 43 LoginUIService* login_ui_service = 44 LoginUIServiceFactory::GetForProfile(profile_); 45 login_ui_service->ShowLoginPopup(); 46} 47 48void IdentitySigninFlow::Observe(int type, 49 const content::NotificationSource& source, 50 const content::NotificationDetails& details) { 51 CHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE); 52 TokenService::TokenAvailableDetails* token_details = 53 content::Details<TokenService::TokenAvailableDetails>(details).ptr(); 54 if (token_details->service() == GaiaConstants::kGaiaOAuth2LoginRefreshToken) 55 delegate_->SigninSuccess(token_details->token()); 56} 57 58} // namespace extensions 59