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.
5 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h"
7 #include "chrome/browser/app_mode/app_mode_utils.h"
8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
9 #include "chrome/browser/signin/signin_manager_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 "components/signin/core/browser/profile_oauth2_token_service.h"
13 #include "components/signin/core/browser/signin_manager.h"
15 namespace extensions
{
17 IdentitySigninFlow::IdentitySigninFlow(Delegate
* delegate
, Profile
* profile
)
18 : delegate_(delegate
),
22 IdentitySigninFlow::~IdentitySigninFlow() {
23 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_
)->
27 void IdentitySigninFlow::Start() {
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();
39 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_
)->AddObserver(this);
41 LoginUIService
* login_ui_service
=
42 LoginUIServiceFactory::GetForProfile(profile_
);
43 login_ui_service
->ShowLoginPopup();
46 void IdentitySigninFlow::OnRefreshTokenAvailable(
47 const std::string
& account_id
) {
48 if (SigninManagerFactory::GetForProfile(profile_
)->
49 GetAuthenticatedAccountId() == account_id
) {
50 delegate_
->SigninSuccess();
54 } // namespace extensions