OLD | NEW |
(Empty) | |
| 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/ui/ash/user_accounts_delegate_chromeos.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <iterator> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "chrome/browser/chromeos/login/user_manager.h" |
| 12 #include "chrome/browser/chromeos/ui/inline_login_dialog.h" |
| 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" |
| 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 17 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "google_apis/gaia/gaia_auth_util.h" |
| 19 |
| 20 namespace chromeos { |
| 21 |
| 22 UserAccountsDelegateChromeOS::UserAccountsDelegateChromeOS( |
| 23 Profile* user_profile) |
| 24 : user_profile_(user_profile) { |
| 25 ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_) |
| 26 ->AddObserver(this); |
| 27 } |
| 28 |
| 29 UserAccountsDelegateChromeOS::~UserAccountsDelegateChromeOS() { |
| 30 ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_) |
| 31 ->RemoveObserver(this); |
| 32 } |
| 33 |
| 34 std::string UserAccountsDelegateChromeOS::GetPrimaryAccountId() { |
| 35 return SigninManagerFactory::GetForProfile(user_profile_) |
| 36 ->GetAuthenticatedAccountId(); |
| 37 } |
| 38 |
| 39 std::vector<std::string> |
| 40 UserAccountsDelegateChromeOS::GetSecondaryAccountIds() { |
| 41 ProfileOAuth2TokenService* token_service = |
| 42 ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); |
| 43 std::vector<std::string> accounts = token_service->GetAccounts(); |
| 44 // Filter primary account. |
| 45 std::vector<std::string>::iterator it = |
| 46 std::remove(accounts.begin(), accounts.end(), GetPrimaryAccountId()); |
| 47 LOG_IF(WARNING, std::distance(it, accounts.end()) != 1) |
| 48 << "Found " << std::distance(it, accounts.end()) |
| 49 << " primary accounts in the account list."; |
| 50 accounts.erase(it, accounts.end()); |
| 51 return accounts; |
| 52 } |
| 53 |
| 54 std::string UserAccountsDelegateChromeOS::GetAccountDisplayName( |
| 55 const std::string& account_id) { |
| 56 User* user = UserManager::Get()->GetUserByProfile(user_profile_); |
| 57 if (gaia::AreEmailsSame(user->email(), account_id) && |
| 58 !user->display_email().empty()) |
| 59 return user->display_email(); |
| 60 return account_id; |
| 61 } |
| 62 |
| 63 void UserAccountsDelegateChromeOS::DeleteAccount( |
| 64 const std::string& account_id) { |
| 65 MutableProfileOAuth2TokenService* oauth2_token_service = |
| 66 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( |
| 67 user_profile_); |
| 68 oauth2_token_service->RevokeCredentials(account_id); |
| 69 } |
| 70 |
| 71 void UserAccountsDelegateChromeOS::LaunchAddAccountDialog() { |
| 72 ui::InlineLoginDialog::Show(user_profile_); |
| 73 } |
| 74 |
| 75 void UserAccountsDelegateChromeOS::OnRefreshTokenAvailable( |
| 76 const std::string& account_id) { |
| 77 NotifyAccountListChanged(); |
| 78 } |
| 79 |
| 80 void UserAccountsDelegateChromeOS::OnRefreshTokenRevoked( |
| 81 const std::string& account_id) { |
| 82 NotifyAccountListChanged(); |
| 83 } |
| 84 |
| 85 } // namespace chromeos |
OLD | NEW |