Commit c1b6aa1f authored by David Roger's avatar David Roger Committed by Chromium LUCI CQ

[signin] Add helper function AccountInfo::IsManaged

The logic to check whether an account is managed was duplicated many
times in the code. This CL factors it in a helper function.

This should be a pure refactoring, and should not change the behavior.

Fixed: 1122496
Change-Id: I32e09af11ecc1169b2d704a5c4552e7f17f8ec7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570569Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836079}
parent 45de9387
......@@ -320,9 +320,7 @@ bool ArePublicSessionRestrictionsEnabled() {
base::string16 GetDefaultNameForNewSignedInProfile(
const AccountInfo& account_info) {
DCHECK(account_info.IsValid());
bool is_consumer = account_info.hosted_domain.empty() ||
account_info.hosted_domain == kNoHostedDomainFound;
if (is_consumer)
if (!account_info.IsManaged())
return base::UTF8ToUTF16(account_info.given_name);
return l10n_util::GetStringUTF16(
IDS_SIGNIN_DICE_WEB_INTERCEPT_ENTERPRISE_PROFILE_NAME);
......
......@@ -329,16 +329,14 @@ bool DiceWebSigninInterceptor::ShouldShowEnterpriseBubble(
return false;
}
if (intercepted_account_info.hosted_domain != kNoHostedDomainFound)
if (intercepted_account_info.IsManaged())
return true;
base::Optional<AccountInfo> primary_account_info =
identity_manager_->FindExtendedAccountInfoForAccountWithRefreshToken(
primary_core_account_info);
if (!primary_account_info || !primary_account_info->IsValid())
return false;
return primary_account_info->hosted_domain != kNoHostedDomainFound;
return primary_account_info && primary_account_info->IsManaged();
}
bool DiceWebSigninInterceptor::ShouldShowMultiUserBubble(
......
......@@ -35,12 +35,6 @@ namespace {
constexpr int kInterceptionBubbleHeight = 342;
constexpr int kInterceptionBubbleWidth = 290;
// Returns true if the account is managed.
bool IsManaged(const AccountInfo& account_info) {
return !account_info.hosted_domain.empty() &&
account_info.hosted_domain != kNoHostedDomainFound;
}
} // namespace
DiceWebSigninInterceptionBubbleView::ScopedBrowserListObserver::
......@@ -111,11 +105,11 @@ void DiceWebSigninInterceptionBubbleView::RecordInterceptionResult(
// For Enterprise, slice per enterprise status for each account.
if (bubble_parameters.interception_type ==
DiceWebSigninInterceptor::SigninInterceptionType::kEnterprise) {
if (IsManaged(bubble_parameters.intercepted_account)) {
if (bubble_parameters.intercepted_account.IsManaged()) {
std::string histogram_name = histogram_base_name + ".NewIsEnterprise";
base::UmaHistogramEnumeration(histogram_name, result);
}
if (IsManaged(bubble_parameters.primary_account)) {
if (bubble_parameters.primary_account.IsManaged()) {
std::string histogram_name = histogram_base_name + ".PrimaryIsEnterprise";
base::UmaHistogramEnumeration(histogram_name, result);
}
......
......@@ -108,9 +108,6 @@ base::Value ProfileCustomizationHandler::GetProfileInfoValue() {
ProfileAttributesEntry* entry = GetProfileEntry();
SkColor profile_color =
entry->GetProfileThemeColors().profile_highlight_color;
std::string hosted_domain = entry->GetHostedDomain();
bool is_managed =
!hosted_domain.empty() && hosted_domain != kNoHostedDomainFound;
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetStringKey("textColor",
......@@ -124,7 +121,8 @@ base::Value ProfileCustomizationHandler::GetProfileInfoValue() {
profiles::GetSizedAvatarIcon(entry->GetAvatarIcon(avatar_icon_size), true,
avatar_icon_size, avatar_icon_size);
dict.SetStringKey("pictureUrl", webui::GetBitmapDataUrl(icon.AsBitmap()));
dict.SetBoolKey("isManaged", is_managed);
dict.SetBoolKey("isManaged",
AccountInfo::IsManaged(entry->GetHostedDomain()));
return dict;
}
......
......@@ -58,10 +58,6 @@ enum class ProfilePickerAction {
kMaxValue = kDeleteProfile,
};
bool IsManaged(const std::string& hosted_domain) {
return !hosted_domain.empty() && hosted_domain != kNoHostedDomainFound;
}
base::Optional<SkColor> GetChromeColorColorById(int color_id) {
for (chrome_colors::ColorInfo color_info :
chrome_colors::kGeneratedColorsInfo) {
......@@ -565,8 +561,8 @@ base::Value ProfilePickerHandler::GetProfilesList() {
// chrome.
profile_entry->SetString("gaiaName", entry->GetGAIANameToDisplay());
profile_entry->SetString("userName", entry->GetUserName());
profile_entry->SetBoolPath("isManaged",
IsManaged(entry->GetHostedDomain()));
profile_entry->SetBoolPath(
"isManaged", AccountInfo::IsManaged(entry->GetHostedDomain()));
gfx::Image icon =
profiles::GetSizedAvatarIcon(entry->GetAvatarIcon(avatar_icon_size),
true, avatar_icon_size, avatar_icon_size);
......
......@@ -56,14 +56,6 @@ bool WaitingForExtendedInfo(signin::IdentityManager* identity_manager) {
return !GetExtendedAccountInfo(identity_manager).has_value();
}
// Returns true if the account is managed.
// TODO(crbug.com/1122496): Move this helper into AccountInfo to reduce code
// duplication (replaces other instances of such a helper function as well).
bool IsManaged(const AccountInfo& account_info) {
return !account_info.hosted_domain.empty() &&
account_info.hosted_domain != kNoHostedDomainFound;
}
} // namespace
const TimeDelta AccountInvestigator::kPeriodicReportingInterval =
......@@ -254,7 +246,7 @@ void AccountInvestigator::DoPeriodicReport(
base::Optional<AccountInfo> info =
GetExtendedAccountInfo(identity_manager_);
signin_metrics::LogSignedInCookiesCountsPerPrimaryAccountType(
signed_in_accounts.size(), is_syncing, IsManaged(*info));
signed_in_accounts.size(), is_syncing, info->IsManaged());
}
periodic_pending_ = false;
......
......@@ -113,6 +113,16 @@ bool AccountInfo::UpdateWith(const AccountInfo& other) {
return modified;
}
// static
bool AccountInfo::IsManaged(const std::string& hosted_domain) {
return !hosted_domain.empty() && hosted_domain != kNoHostedDomainFound;
}
bool AccountInfo::IsManaged() const {
return IsManaged(hosted_domain);
}
bool operator==(const CoreAccountInfo& l, const CoreAccountInfo& r) {
return l.account_id == r.account_id && l.gaia == r.gaia &&
gaia::AreEmailsSame(l.email, r.email) &&
......
......@@ -7,6 +7,7 @@
#include <string>
#include "base/optional.h"
#include "build/build_config.h"
#include "google_apis/gaia/core_account_id.h"
#include "ui/gfx/image/image.h"
......@@ -74,6 +75,14 @@ struct AccountInfo : public CoreAccountInfo {
// Updates the empty fields of |this| with |other|. Returns whether at least
// one field was updated.
bool UpdateWith(const AccountInfo& other);
// Helper functions returning whether the account is managed (hosted_domain
// is different from kNoHostedDomainFound). Returns false for gmail.com
// accounts and other non-managed accounts like yahoo.com. Returns false if
// hosted_domain is still unknown (empty), this information will become
// available asynchronously.
static bool IsManaged(const std::string& hosted_domain);
bool IsManaged() const;
};
bool operator==(const CoreAccountInfo& l, const CoreAccountInfo& r);
......
......@@ -586,6 +586,5 @@ bool AuthenticationService::IsAuthenticatedIdentityManaged() const {
if (!primary_account_info)
return false;
const std::string& hosted_domain = primary_account_info->hosted_domain;
return hosted_domain != kNoHostedDomainFound && !hosted_domain.empty();
return primary_account_info->IsManaged();
}
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