identity_signin_flow.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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/profile_oauth2_token_service.h"
9#include "chrome/browser/signin/profile_oauth2_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
13namespace extensions {
14
15IdentitySigninFlow::IdentitySigninFlow(Delegate* delegate, Profile* profile)
16    : delegate_(delegate),
17      profile_(profile) {
18}
19
20IdentitySigninFlow::~IdentitySigninFlow() {
21  ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
22      RemoveObserver(this);
23}
24
25void IdentitySigninFlow::Start() {
26  DCHECK(delegate_);
27
28#if defined(OS_CHROMEOS)
29  // In normal mode (i.e. non-forced app mode), the user has to log out to
30  // re-establish credentials. Let the global error popup handle everything.
31  if (!chrome::IsRunningInForcedAppMode()) {
32    delegate_->SigninFailed();
33    return;
34  }
35#endif
36
37  ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->AddObserver(this);
38
39  LoginUIService* login_ui_service =
40      LoginUIServiceFactory::GetForProfile(profile_);
41  login_ui_service->ShowLoginPopup();
42}
43
44void IdentitySigninFlow::OnRefreshTokenAvailable(
45    const std::string& account_id) {
46  delegate_->SigninSuccess();
47}
48
49}  // namespace extensions
50