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