Commit b65b28af authored by Joon Ahn's avatar Joon Ahn Committed by Commit Bot

Standardize google internal account checks.

Utilize gaia::IsGoogleInternalAccountEmail() instead of one off string checks.

Bug: n/a
Change-Id: I772ae92dbe31ca0c1bccc3c0e2fb666fa50972e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899843
Commit-Queue: Joon Ahn <joonbug@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715874}
parent 5a2f5312
......@@ -19,6 +19,7 @@
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/user_manager/user_manager.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "third_party/icu/source/common/unicode/locid.h"
#include "ui/chromeos/events/keyboard_layout_util.h"
......@@ -106,12 +107,10 @@ ash::mojom::AssistantAllowedState IsAssistantAllowedForProfile(
if (identity_manager) {
const std::string email = identity_manager->GetPrimaryAccountInfo().email;
if (base::EndsWith(email, "@gmail.com",
base::CompareCase::INSENSITIVE_ASCII) ||
base::EndsWith(email, "@googlemail.com",
base::CompareCase::INSENSITIVE_ASCII) ||
base::EndsWith(email, "@google.com",
base::CompareCase::INSENSITIVE_ASCII)) {
if (!email.empty() &&
(gaia::ExtractDomainName(email) == "gmail.com" ||
gaia::ExtractDomainName(email) == "googlemail.com" ||
gaia::IsGoogleInternalAccountEmail(email))) {
account_supported = true;
}
}
......
......@@ -5,17 +5,16 @@
#include "chrome/browser/chromeos/bluetooth/debug_logs_manager.h"
#include "base/feature_list.h"
#include "base/strings/string_util.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "google_apis/gaia/gaia_auth_util.h"
namespace chromeos {
namespace bluetooth {
namespace {
const char kSupportedEmailSuffix[] = "@google.com";
const char kVerboseLoggingEnablePrefName[] = "bluetooth.verboseLogging.enable";
} // namespace
......@@ -60,8 +59,7 @@ bool DebugLogsManager::AreDebugLogsSupported() const {
return false;
}
return base::EndsWith(primary_user_email_, kSupportedEmailSuffix,
base::CompareCase::INSENSITIVE_ASCII);
return gaia::IsGoogleInternalAccountEmail(primary_user_email_);
}
} // namespace bluetooth
......
......@@ -26,6 +26,7 @@
#include "chromeos/network/network_state.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -72,10 +73,6 @@ bool IsNewDevice() {
kHatsNewDeviceThreshold;
}
bool IsGoogleUser(std::string username) {
return username.find("@google.com") != std::string::npos;
}
// Returns true if the |kForceHappinessTrackingSystem| flag is enabled.
bool IsTestingEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
......@@ -145,7 +142,8 @@ bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {
->IsEnterpriseManaged();
// Do not show survey if this is a non dogfood enterprise enrolled device.
if (is_enterprise_enrolled && !IsGoogleUser(profile->GetProfileUserName()))
if (is_enterprise_enrolled &&
!gaia::IsGoogleInternalAccountEmail(profile->GetProfileUserName()))
return false;
// In an enterprise enrolled device, the user can never be the owner, hence
......@@ -158,9 +156,10 @@ bool HatsNotificationController::ShouldShowSurveyToProfile(Profile* profile) {
if (!hats_finch_helper.IsDeviceSelectedForCurrentCycle())
return false;
base::TimeDelta threshold_time = IsGoogleUser(profile->GetProfileUserName())
? kHatsGooglerThreshold
: kHatsThreshold;
base::TimeDelta threshold_time =
gaia::IsGoogleInternalAccountEmail(profile->GetProfileUserName())
? kHatsGooglerThreshold
: kHatsThreshold;
// Do not show survey to user if user has interacted with HaTS within the past
// |threshold_time| time delta.
if (DidShowSurveyToProfileRecently(profile, threshold_time))
......@@ -177,7 +176,8 @@ void HatsNotificationController::Click(
UpdateLastInteractionTime();
// The dialog deletes itself on close.
HatsDialog::CreateAndShow(IsGoogleUser(profile_->GetProfileUserName()));
HatsDialog::CreateAndShow(
gaia::IsGoogleInternalAccountEmail(profile_->GetProfileUserName()));
// Remove the notification.
network_portal_detector::GetInstance()->RemoveObserver(this);
......
......@@ -131,8 +131,6 @@ const char kDeviceLocalAccountPendingDataRemoval[] =
// data.
const char kDeviceLocalAccountsWithSavedData[] = "PublicAccounts";
constexpr char kGoogleDotCom[] = "@google.com";
constexpr char kBluetoothLoggingUpstartJob[] = "bluetoothlog";
// If the service doesn't exist or the policy is not set, enable managed
......@@ -199,13 +197,11 @@ policy::MinimumVersionPolicyHandler* GetMinimumVersionPolicyHandler() {
->GetMinimumVersionPolicyHandler();
}
// Starts bluetooth logging service for accounts ending with |kGoogleDotCom|
// and certain devices.
// Starts bluetooth logging service for internal accounts and certain devices.
void MaybeStartBluetoothLogging(const AccountId& account_id) {
if (!base::EndsWith(account_id.GetUserEmail(), kGoogleDotCom,
base::CompareCase::INSENSITIVE_ASCII)) {
if (!gaia::IsGoogleInternalAccountEmail(account_id.GetUserEmail()))
return;
}
chromeos::UpstartClient::Get()->StartJob(kBluetoothLoggingUpstartJob, {},
EmptyVoidDBusMethodCallback());
}
......
......@@ -19,6 +19,7 @@
#include "components/user_manager/user_manager.h"
#include "components/version_info/version_info.h"
#include "content/public/common/content_switches.h"
#include "google_apis/gaia/gaia_auth_util.h"
namespace {
......@@ -60,8 +61,7 @@ bool ReleaseNotesStorage::ShouldNotify() {
}
std::string user_email = profile_->GetProfileUserName();
if (base::EndsWith(user_email, "@google.com",
base::CompareCase::INSENSITIVE_ASCII) ||
if (gaia::IsGoogleInternalAccountEmail(user_email) ||
(ProfileHelper::Get()->GetUserByProfile(profile_)->HasGaiaAccount() &&
!profile_->GetProfilePolicyConnector()->IsManaged())) {
const int last_milestone = profile_->GetPrefs()->GetInteger(
......
......@@ -51,6 +51,7 @@
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -112,8 +113,7 @@ const std::string BuildQueryString(Profile* profile) {
channel_name = "stable";
const std::string username = profile->GetProfileUserName();
std::string user_type;
if (base::EndsWith(username, "@google.com",
base::CompareCase::INSENSITIVE_ASCII)) {
if (gaia::IsGoogleInternalAccountEmail(username)) {
user_type = "googler";
} else if (profile->GetProfilePolicyConnector()->IsManaged()) {
user_type = "managed";
......
......@@ -107,7 +107,7 @@ std::string ExtractDomainName(const std::string& email_address) {
}
bool IsGoogleInternalAccountEmail(const std::string& email) {
return ExtractDomainName(email) == kGoogleDomain;
return ExtractDomainName(SanitizeEmail(email)) == kGoogleDomain;
}
bool IsGaiaSignonRealm(const GURL& url) {
......
......@@ -87,6 +87,7 @@ TEST(GaiaAuthUtilTest, ExtractDomainName) {
TEST(GaiaAuthUtilTest, IsGoogleInternalAccountEmail) {
EXPECT_TRUE(IsGoogleInternalAccountEmail("hello@google.com"));
EXPECT_FALSE(IsGoogleInternalAccountEmail("internal@gmail.com"));
EXPECT_FALSE(IsGoogleInternalAccountEmail(" "));
}
TEST(GaiaAuthUtilTest, SanitizeMissingDomain) {
......
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