Index: chrome/browser/ui/ash/user_accounts_delegate_chromeos.cc |
diff --git a/chrome/browser/ui/ash/user_accounts_delegate_chromeos.cc b/chrome/browser/ui/ash/user_accounts_delegate_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b0afbddb9a223d13f422ac8434604dcc8ab0b7fc |
--- /dev/null |
+++ b/chrome/browser/ui/ash/user_accounts_delegate_chromeos.cc |
@@ -0,0 +1,84 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h" |
+ |
+#include <algorithm> |
+#include <iterator> |
+ |
+#include "base/logging.h" |
+#include "chrome/browser/chromeos/login/user_manager.h" |
+#include "chrome/browser/chromeos/ui/inline_login_dialog.h" |
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
+#include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" |
+#include "components/signin/core/browser/profile_oauth2_token_service.h" |
+#include "components/signin/core/browser/signin_manager.h" |
+ |
+namespace chromeos { |
+ |
+UserAccountsDelegateChromeOS::UserAccountsDelegateChromeOS( |
+ Profile* user_profile) |
+ : user_profile_(user_profile) { |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_) |
+ ->AddObserver(this); |
+} |
+ |
+UserAccountsDelegateChromeOS::~UserAccountsDelegateChromeOS() { |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_) |
+ ->RemoveObserver(this); |
+} |
+ |
+std::string UserAccountsDelegateChromeOS::GetPrimaryAccount() { |
+ return SigninManagerFactory::GetForProfile(user_profile_) |
+ ->GetAuthenticatedUsername(); |
xiyuan
2014/04/24 21:22:10
Should this be GetAuthenticatedAccountId? Right no
dzhioev (left Google)
2014/04/24 22:06:20
I'm little confused. Comment for GetAuthenticatedA
xiyuan
2014/04/24 22:31:51
The plan is to make GetAuthenticatedAccountId retu
|
+} |
+ |
+std::vector<std::string> |
+UserAccountsDelegateChromeOS::GetSecondaryAccountsList() { |
+ ProfileOAuth2TokenService* token_service = |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_); |
+ std::vector<std::string> accounts = token_service->GetAccounts(); |
+ // Filter primary account. |
+ std::vector<std::string>::iterator it = |
+ std::remove(accounts.begin(), accounts.end(), GetPrimaryAccount()); |
+ if (std::distance(it, accounts.end()) != 1) |
xiyuan
2014/04/24 21:22:10
nit: LOG_IF since this "if" only do logging.
dzhioev (left Google)
2014/04/24 22:06:20
Done.
|
+ LOG(WARNING) << "Found " << std::distance(it, accounts.end()) |
+ << " primary " |
+ "accounts in the account list."; |
+ accounts.erase(it, accounts.end()); |
+ return accounts; |
+} |
+ |
+std::string UserAccountsDelegateChromeOS::GetAccountDisplayName( |
+ const std::string& account_id) { |
+ User* user = UserManager::Get()->GetUserByProfile(user_profile_); |
+ if (user->email() == account_id && !user->display_email().empty()) |
+ return user->display_email(); |
+ return account_id; |
+} |
+ |
+void UserAccountsDelegateChromeOS::DeleteAccount( |
+ const std::string& account_id) { |
+ MutableProfileOAuth2TokenService* oauth2_token_service = |
+ ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( |
+ user_profile_); |
+ oauth2_token_service->RevokeCredentials(account_id); |
+} |
+ |
+void UserAccountsDelegateChromeOS::LaunchAddAccountDialog() { |
+ ui::InlineLoginDialog::Show(user_profile_); |
+} |
+ |
+void UserAccountsDelegateChromeOS::OnRefreshTokenAvailable( |
+ const std::string& account_id) { |
+ NotifyAccountListChanged(); |
+} |
+ |
+void UserAccountsDelegateChromeOS::OnRefreshTokenRevoked( |
+ const std::string& account_id) { |
+ NotifyAccountListChanged(); |
+} |
+ |
+} // namespace chromeos |