Commit b74eabdc authored by Kush Sinha's avatar Kush Sinha Committed by Commit Bot

Dead code removal: AccountMapperUtil

Bug: 925827
Change-Id: Id4aa0202ba4c97339fd8b470d28e096b5791e130
Reviewed-on: https://chromium-review.googlesource.com/c/1483024
Commit-Queue: Kush Sinha <sinhak@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635977}
parent f21f7bb9
...@@ -295,8 +295,6 @@ source_set("chromeos") { ...@@ -295,8 +295,6 @@ source_set("chromeos") {
"account_manager/account_manager_migrator.h", "account_manager/account_manager_migrator.h",
"account_manager/account_migration_runner.cc", "account_manager/account_migration_runner.cc",
"account_manager/account_migration_runner.h", "account_manager/account_migration_runner.h",
"account_mapper_util.cc",
"account_mapper_util.h",
"android_sms/android_sms_app_manager.cc", "android_sms/android_sms_app_manager.cc",
"android_sms/android_sms_app_manager.h", "android_sms/android_sms_app_manager.h",
"android_sms/android_sms_app_manager_impl.cc", "android_sms/android_sms_app_manager_impl.cc",
......
// Copyright 2018 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/chromeos/account_mapper_util.h"
#include "components/account_id/account_id.h"
#include "components/signin/core/browser/account_info.h"
#include "components/signin/core/browser/account_tracker_service.h"
namespace chromeos {
AccountMapperUtil::AccountMapperUtil(
AccountTrackerService* account_tracker_service)
: account_tracker_service_(account_tracker_service) {}
AccountMapperUtil::~AccountMapperUtil() = default;
std::string AccountMapperUtil::AccountKeyToOAuthAccountId(
const AccountManager::AccountKey& account_key) const {
DCHECK(account_key.IsValid());
if (account_key.account_type !=
account_manager::AccountType::ACCOUNT_TYPE_GAIA) {
return std::string();
}
const AccountInfo& account_info = AccountKeyToGaiaAccountInfo(account_key);
DCHECK(!account_info.account_id.empty()) << "Can't find account id";
return account_info.account_id;
}
AccountManager::AccountKey AccountMapperUtil::OAuthAccountIdToAccountKey(
const std::string& account_id) const {
DCHECK(!account_id.empty());
const AccountInfo& account_info =
account_tracker_service_->GetAccountInfo(account_id);
DCHECK(!account_info.gaia.empty()) << "Can't find account info";
return AccountManager::AccountKey{
account_info.gaia, account_manager::AccountType::ACCOUNT_TYPE_GAIA};
}
AccountInfo AccountMapperUtil::AccountKeyToGaiaAccountInfo(
const AccountManager::AccountKey& account_key) const {
DCHECK(account_key.IsValid());
if (account_key.account_type !=
account_manager::AccountType::ACCOUNT_TYPE_GAIA) {
return AccountInfo();
}
AccountInfo account_info =
account_tracker_service_->FindAccountInfoByGaiaId(account_key.id);
DCHECK(!account_info.IsEmpty()) << "Can't find account info";
return account_info;
}
// static
bool AccountMapperUtil::IsEqual(const AccountManager::AccountKey& account_key,
const AccountId& account_id) {
switch (account_key.account_type) {
case chromeos::account_manager::AccountType::ACCOUNT_TYPE_GAIA:
return (account_id.GetAccountType() == AccountType::GOOGLE) &&
(account_id.GetGaiaId() == account_key.id);
case chromeos::account_manager::AccountType::ACCOUNT_TYPE_ACTIVE_DIRECTORY:
return (account_id.GetAccountType() == AccountType::ACTIVE_DIRECTORY) &&
(account_id.GetObjGuid() == account_key.id);
case chromeos::account_manager::AccountType::ACCOUNT_TYPE_UNSPECIFIED:
return false;
}
}
} // namespace chromeos
// Copyright 2018 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.
#ifndef CHROME_BROWSER_CHROMEOS_ACCOUNT_MAPPER_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_ACCOUNT_MAPPER_UTIL_H_
#include <string>
#include "base/macros.h"
#include "chromeos/account_manager/account_manager.h"
class AccountId;
struct AccountInfo;
class AccountTrackerService;
namespace chromeos {
class AccountMapperUtil {
public:
explicit AccountMapperUtil(AccountTrackerService* account_tracker_service);
~AccountMapperUtil();
// A utility method to map an |account_key| to the account id used by the
// OAuth2TokenService chain (see |AccountInfo|). Returns an empty string for
// non-Gaia accounts.
std::string AccountKeyToOAuthAccountId(
const AccountManager::AccountKey& account_key) const;
// A utility method to map the |account_id| used by the OAuth2TokenService
// chain (see |AccountInfo|) to an |AccountManager::AccountKey|.
AccountManager::AccountKey OAuthAccountIdToAccountKey(
const std::string& account_id) const;
// A utility method to map an |account_key| representing a GAIA account to
// |AccountInfo|. Returns an empty |AccountInfo| for non-GAIA accounts.
AccountInfo AccountKeyToGaiaAccountInfo(
const AccountManager::AccountKey& account_key) const;
// A utility method to check whether |account_key| and |account_id| represent
// the same account.
static bool IsEqual(const AccountManager::AccountKey& account_key,
const AccountId& account_id);
private:
// A non-owning pointer to |AccountTrackerService|, which itself is a
// |KeyedService|.
AccountTrackerService* const account_tracker_service_;
DISALLOW_COPY_AND_ASSIGN(AccountMapperUtil);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_ACCOUNT_MAPPER_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment