Home | History | Annotate | Download | only in identity
      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_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"
     14 
     15 namespace extensions {
     16 
     17 IdentitySigninFlow::IdentitySigninFlow(Delegate* delegate, Profile* profile)
     18     : delegate_(delegate),
     19       profile_(profile) {
     20 }
     21 
     22 IdentitySigninFlow::~IdentitySigninFlow() {
     23   ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
     24       RemoveObserver(this);
     25 }
     26 
     27 void 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   ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->AddObserver(this);
     40 
     41   LoginUIService* login_ui_service =
     42       LoginUIServiceFactory::GetForProfile(profile_);
     43   login_ui_service->ShowLoginPopup();
     44 }
     45 
     46 void IdentitySigninFlow::OnRefreshTokenAvailable(
     47     const std::string& account_id) {
     48   if (SigninManagerFactory::GetForProfile(profile_)->
     49       GetAuthenticatedAccountId() == account_id) {
     50     delegate_->SigninSuccess();
     51   }
     52 }
     53 
     54 }  // namespace extensions
     55