blob: 58e60fde5fe7585c54aae25b810519b1615da542 [file] [log] [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/autofill/ui_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
namespace autofill {
absl::optional<AccountInfo> GetPrimaryAccountInfoFromBrowserContext(
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
if (!identity_manager) {
return absl::nullopt;
}
CoreAccountInfo core_account =
identity_manager->GetPrimaryAccountInfo(signin::ConsentLevel::kSignin);
return identity_manager->FindExtendedAccountInfo(core_account);
}
} // namespace autofill