identity_signin_flow.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 "content/public/browser/notification_source.h" 15#include "google_apis/gaia/gaia_constants.h" 16 17namespace extensions { 18 19IdentitySigninFlow::IdentitySigninFlow(Delegate* delegate, Profile* profile) 20 : delegate_(delegate), 21 profile_(profile) { 22} 23 24IdentitySigninFlow::~IdentitySigninFlow() { 25} 26 27void IdentitySigninFlow::Start() { 28 DCHECK(delegate_); 29 30#if defined(OS_CHROMEOS) 31 // In normal mode (i.e. non-forced app mode), the user has to log out to 32 // re-establish credentials. Let the global error popup handle everything. 33 if (!chrome::IsRunningInForcedAppMode()) { 34 delegate_->SigninFailed(); 35 return; 36 } 37#endif 38 39 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 40 registrar_.Add(this, 41 chrome::NOTIFICATION_TOKEN_AVAILABLE, 42 content::Source<TokenService>(token_service)); 43 44 LoginUIService* login_ui_service = 45 LoginUIServiceFactory::GetForProfile(profile_); 46 login_ui_service->ShowLoginPopup(); 47} 48 49void IdentitySigninFlow::Observe(int type, 50 const content::NotificationSource& source, 51 const content::NotificationDetails& details) { 52 CHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE); 53 TokenService::TokenAvailableDetails* token_details = 54 content::Details<TokenService::TokenAvailableDetails>(details).ptr(); 55 if (token_details->service() == GaiaConstants::kGaiaOAuth2LoginRefreshToken) 56 delegate_->SigninSuccess(token_details->token()); 57} 58 59} // namespace extensions 60