Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / profile_identity_provider.cc
1 // Copyright 2014 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/signin/profile_identity_provider.h"
6
7 #include "components/signin/core/browser/profile_oauth2_token_service.h"
8
9 #if !defined(OS_ANDROID)
10 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
11 #endif
12
13 ProfileIdentityProvider::ProfileIdentityProvider(
14     SigninManagerBase* signin_manager,
15     ProfileOAuth2TokenService* token_service,
16     LoginUIService* login_ui_service)
17     : signin_manager_(signin_manager),
18       token_service_(token_service),
19       login_ui_service_(login_ui_service) {
20   signin_manager_->AddObserver(this);
21 }
22
23 ProfileIdentityProvider::~ProfileIdentityProvider() {
24   signin_manager_->RemoveObserver(this);
25 }
26
27 std::string ProfileIdentityProvider::GetActiveUsername() {
28   return signin_manager_->GetAuthenticatedUsername();
29 }
30
31 std::string ProfileIdentityProvider::GetActiveAccountId() {
32   return signin_manager_->GetAuthenticatedAccountId();
33 }
34
35 OAuth2TokenService* ProfileIdentityProvider::GetTokenService() {
36   return token_service_;
37 }
38
39 bool ProfileIdentityProvider::RequestLogin() {
40 #if defined(OS_ANDROID)
41   return false;
42 #else
43   login_ui_service_->ShowLoginPopup();
44   return true;
45 #endif
46 }
47
48 void ProfileIdentityProvider::GoogleSigninSucceeded(
49     const std::string& username,
50     const std::string& password) {
51   FireOnActiveAccountLogin();
52 }
53
54 void ProfileIdentityProvider::GoogleSignedOut(const std::string& username) {
55   FireOnActiveAccountLogout();
56 }