Commit fa0ddb4c authored by Emily Stark's avatar Emily Stark Committed by Commit Bot

Remove lookalikes namespace

Namespaces are discouraged in chrome/, as previously discussed on
chromium-dev and recently codified at
https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++-dos-and-donts.md#named-namespaces. This
CL removes the lookalikes:: namespace.

Change-Id: I91cd483630881c4cb29fb5cf3f44ca91b5a767c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877127
Commit-Queue: Emily Stark <estark@chromium.org>
Reviewed-by: default avatarMustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709056}
parent 86721099
......@@ -3883,8 +3883,7 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation(
MaybeAddThrottle(
&throttles,
lookalikes::LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(
handle));
LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle));
MaybeAddThrottle(&throttles,
PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle));
......
......@@ -36,12 +36,8 @@ namespace {
const base::FeatureParam<bool> kEnableInterstitialForTopSites{
&features::kLookalikeUrlNavigationSuggestionsUI, "topsites", false};
using lookalikes::LookalikeUrlNavigationThrottle;
using MatchType = LookalikeUrlInterstitialPage::MatchType;
using UserAction = LookalikeUrlInterstitialPage::UserAction;
using NavigationSuggestionEvent =
lookalikes::LookalikeUrlNavigationThrottle::NavigationSuggestionEvent;
using lookalikes::DomainInfo;
using url_formatter::TopDomainEntry;
typedef content::NavigationThrottle::ThrottleCheckResult ThrottleCheckResult;
......@@ -91,8 +87,7 @@ std::string GetSimilarDomainFromTop500(const DomainInfo& navigated_domain) {
for (const std::string& navigated_skeleton : navigated_domain.skeletons) {
for (const char* const top_domain_skeleton :
top500_domains::kTop500EditDistanceSkeletons) {
if (lookalikes::IsEditDistanceAtMostOne(
base::UTF8ToUTF16(navigated_skeleton),
if (IsEditDistanceAtMostOne(base::UTF8ToUTF16(navigated_skeleton),
base::UTF8ToUTF16(top_domain_skeleton))) {
const std::string top_domain =
url_formatter::LookupSkeletonInTopDomains(top_domain_skeleton)
......@@ -129,8 +124,7 @@ std::string GetSimilarDomainFromEngagedSites(
continue;
}
for (const std::string& engaged_skeleton : engaged_site.skeletons) {
if (lookalikes::IsEditDistanceAtMostOne(
base::UTF8ToUTF16(navigated_skeleton),
if (IsEditDistanceAtMostOne(base::UTF8ToUTF16(navigated_skeleton),
base::UTF8ToUTF16(engaged_skeleton))) {
// If the only difference between the navigated and engaged
// domain is the registry part, this is unlikely to be a spoofing
......@@ -159,16 +153,20 @@ bool IsInterstitialReload(const GURL& current_url,
void RecordUMAFromMatchType(MatchType match_type) {
switch (match_type) {
case MatchType::kTopSite:
RecordEvent(NavigationSuggestionEvent::kMatchTopSite);
RecordEvent(LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchTopSite);
break;
case MatchType::kSiteEngagement:
RecordEvent(NavigationSuggestionEvent::kMatchSiteEngagement);
RecordEvent(LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
break;
case MatchType::kEditDistance:
RecordEvent(NavigationSuggestionEvent::kMatchEditDistance);
RecordEvent(LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchEditDistance);
break;
case MatchType::kEditDistanceSiteEngagement:
RecordEvent(NavigationSuggestionEvent::kMatchEditDistanceSiteEngagement);
RecordEvent(LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchEditDistanceSiteEngagement);
break;
case MatchType::kNone:
break;
......@@ -177,8 +175,6 @@ void RecordUMAFromMatchType(MatchType match_type) {
} // namespace
namespace lookalikes {
// static
const char LookalikeUrlNavigationThrottle::kHistogramName[] =
"NavigationSuggestion.Event";
......@@ -592,5 +588,3 @@ ThrottleCheckResult LookalikeUrlNavigationThrottle::PerformChecks(
return content::NavigationThrottle::PROCEED;
}
} // namespace lookalikes
......@@ -23,8 +23,6 @@ class NavigationHandle;
class Profile;
namespace lookalikes {
struct DomainInfo;
// Returns true if the domain given by |domain_info| is a top domain.
......@@ -127,6 +125,4 @@ class LookalikeUrlNavigationThrottle : public content::NavigationThrottle {
base::WeakPtrFactory<LookalikeUrlNavigationThrottle> weak_factory_{this};
};
} // namespace lookalikes
#endif // CHROME_BROWSER_LOOKALIKES_LOOKALIKE_URL_NAVIGATION_THROTTLE_H_
......@@ -34,13 +34,9 @@
namespace {
using lookalikes::LookalikeUrlNavigationThrottle;
using lookalikes::LookalikeUrlService;
using security_interstitials::MetricsHelper;
using security_interstitials::SecurityInterstitialCommand;
using UkmEntry = ukm::builders::LookalikeUrl_NavigationSuggestion;
using NavigationSuggestionEvent =
lookalikes::LookalikeUrlNavigationThrottle::NavigationSuggestionEvent;
using MatchType = LookalikeUrlInterstitialPage::MatchType;
using UserAction = LookalikeUrlInterstitialPage::UserAction;
......@@ -258,10 +254,12 @@ class LookalikeUrlNavigationThrottleBrowserTest
if (!ui_enabled()) {
return false;
}
if (expected_event == NavigationSuggestionEvent::kMatchSiteEngagement) {
if (expected_event == LookalikeUrlNavigationThrottle::
NavigationSuggestionEvent::kMatchSiteEngagement) {
return true;
}
if (expected_event == NavigationSuggestionEvent::kMatchTopSite &&
if (expected_event == LookalikeUrlNavigationThrottle::
NavigationSuggestionEvent::kMatchTopSite &&
ui_status() == UIStatus::kEnabledForSiteEngagementAndTopDomains) {
return true;
}
......@@ -443,7 +441,7 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestMetricsRecordedAndMaybeInterstitialShown(
browser(), kNavigatedUrl, kExpectedSuggestedUrl,
NavigationSuggestionEvent::kMatchTopSite);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::kMatchTopSite);
CheckUkm({kNavigatedUrl}, "MatchType", MatchType::kTopSite);
}
......@@ -461,8 +459,10 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestInterstitialNotShown(browser(), kNavigatedUrl);
histograms.ExpectTotalCount(LookalikeUrlNavigationThrottle::kHistogramName,
1);
histograms.ExpectBucketCount(LookalikeUrlNavigationThrottle::kHistogramName,
NavigationSuggestionEvent::kMatchTopSite, 1);
histograms.ExpectBucketCount(
LookalikeUrlNavigationThrottle::kHistogramName,
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::kMatchTopSite,
1);
CheckUkm({kNavigatedUrl}, "MatchType", MatchType::kTopSite);
}
......@@ -480,7 +480,7 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestMetricsRecordedAndMaybeInterstitialShown(
browser(), kNavigatedUrl, kExpectedSuggestedUrl,
NavigationSuggestionEvent::kMatchTopSite);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::kMatchTopSite);
CheckUkm({kNavigatedUrl}, "MatchType", MatchType::kTopSite);
}
......@@ -539,7 +539,9 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
1);
histograms.ExpectBucketCount(
LookalikeUrlNavigationThrottle::kHistogramName,
NavigationSuggestionEvent::kMatchEditDistanceSiteEngagement, 1);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchEditDistanceSiteEngagement,
1);
CheckUkm({kNavigatedUrl}, "MatchType",
MatchType::kEditDistanceSiteEngagement);
......@@ -562,8 +564,10 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestInterstitialNotShown(browser(), kNavigatedUrl);
histograms.ExpectTotalCount(LookalikeUrlNavigationThrottle::kHistogramName,
1);
histograms.ExpectBucketCount(LookalikeUrlNavigationThrottle::kHistogramName,
NavigationSuggestionEvent::kMatchEditDistance,
histograms.ExpectBucketCount(
LookalikeUrlNavigationThrottle::kHistogramName,
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchEditDistance,
1);
CheckUkm({kNavigatedUrl}, "MatchType", MatchType::kEditDistance);
......@@ -689,7 +693,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestMetricsRecordedAndMaybeInterstitialShown(
browser(), kNavigatedUrl, kExpectedSuggestedUrl,
NavigationSuggestionEvent::kMatchSiteEngagement);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
ukm_urls.push_back(kNavigatedUrl);
CheckUkm(ukm_urls, "MatchType", MatchType::kSiteEngagement);
......@@ -724,7 +729,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
SetEngagementScore(browser(), kExpectedSuggestedUrl, kHighEngagement);
TestMetricsRecordedAndMaybeInterstitialShown(
browser(), kNavigatedUrl, kExpectedSuggestedUrl,
NavigationSuggestionEvent::kMatchSiteEngagement);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
}
// Tests negative examples for all heuristics.
......@@ -766,7 +772,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestMetricsRecordedAndMaybeInterstitialShown(
browser(), kNavigatedUrl, kExpectedSuggestedUrl,
NavigationSuggestionEvent::kMatchSiteEngagement);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
CheckUkm({kNavigatedUrl}, "MatchType", MatchType::kSiteEngagement);
}
......@@ -795,7 +802,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
test_clock()->Advance(base::TimeDelta::FromHours(1));
TestMetricsRecordedAndMaybeInterstitialShown(
browser(), kNavigatedUrl, kEngagedUrl,
NavigationSuggestionEvent::kMatchSiteEngagement);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
ukm_urls.push_back(kNavigatedUrl);
CheckUkm(ukm_urls, "MatchType", MatchType::kSiteEngagement);
......@@ -821,7 +829,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestMetricsRecordedAndMaybeInterstitialShown(
incognito, kNavigatedUrl, kEngagedUrl,
NavigationSuggestionEvent::kMatchSiteEngagement);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
ukm_urls.push_back(kNavigatedUrl);
CheckUkm(ukm_urls, "MatchType", MatchType::kSiteEngagement);
}
......@@ -901,7 +910,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
TestHistogramEventsRecordedWhenInterstitialIgnored(
browser(), &histograms, kNavigatedUrl,
NavigationSuggestionEvent::kMatchSiteEngagement);
LookalikeUrlNavigationThrottle::NavigationSuggestionEvent::
kMatchSiteEngagement);
CheckUkm({kNavigatedUrl}, "MatchType", MatchType::kSiteEngagement);
}
......@@ -1069,4 +1079,3 @@ IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest,
TestInterstitialNotShown(browser(),
embedded_test_server()->GetURL("example.net", "/"));
}
......@@ -28,8 +28,6 @@
namespace {
using lookalikes::LookalikeUrlService;
constexpr uint32_t kEngagedSiteUpdateIntervalInSeconds = 5 * 60;
class LookalikeUrlServiceFactory : public BrowserContextKeyedServiceFactory {
......@@ -72,8 +70,6 @@ class LookalikeUrlServiceFactory : public BrowserContextKeyedServiceFactory {
} // namespace
namespace lookalikes {
std::string GetETLDPlusOne(const std::string& hostname) {
return net::registry_controlled_domains::GetDomainAndRegistry(
hostname, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
......@@ -191,5 +187,3 @@ void LookalikeUrlService::OnFetchEngagedSites(
last_engagement_fetch_time_ = clock_->Now();
std::move(callback).Run(engaged_sites_);
}
} // namespace lookalikes
......@@ -24,8 +24,6 @@ namespace base {
class Clock;
}
namespace lookalikes {
// Returns eTLD+1 of |hostname|. This excludes private registries, and returns
// "blogspot.com" for "test.blogspot.com" (blogspot.com is listed as a private
// registry). We do this to be consistent with url_formatter's top domain list
......@@ -99,6 +97,4 @@ class LookalikeUrlService : public KeyedService {
DISALLOW_COPY_AND_ASSIGN(LookalikeUrlService);
};
} // namespace lookalikes
#endif // CHROME_BROWSER_LOOKALIKES_LOOKALIKE_URL_SERVICE_H_
......@@ -29,19 +29,19 @@ namespace safety_tips {
bool ShouldTriggerSafetyTipFromLookalike(
const GURL& url,
const lookalikes::DomainInfo& navigated_domain,
const std::vector<lookalikes::DomainInfo>& engaged_sites,
const DomainInfo& navigated_domain,
const std::vector<DomainInfo>& engaged_sites,
GURL* safe_url) {
std::string matched_domain;
MatchType match_type;
if (!lookalikes::LookalikeUrlNavigationThrottle::GetMatchingDomain(
if (!LookalikeUrlNavigationThrottle::GetMatchingDomain(
navigated_domain, engaged_sites, &matched_domain, &match_type)) {
return false;
}
// If we're already displaying an interstitial, don't warn again.
if (lookalikes::LookalikeUrlNavigationThrottle::ShouldDisplayInterstitial(
if (LookalikeUrlNavigationThrottle::ShouldDisplayInterstitial(
match_type, navigated_domain)) {
return false;
}
......@@ -74,7 +74,7 @@ bool ShouldTriggerSafetyTipFromKeywordInURL(
// "eTLD + 1 - 1": "www.google.com" -> "google"
std::string eTLD_plusminus;
base::TrimString(url_formatter::top_domains::HostnameWithoutRegistry(
lookalikes::GetETLDPlusOne(url.host())),
GetETLDPlusOne(url.host())),
".", &eTLD_plusminus);
DCHECK(eTLD_plusminus.find('.') == std::string::npos);
......
......@@ -23,8 +23,8 @@ namespace safety_tips {
// navigated domain is a lookalike to, in the passed |safe_url|.
bool ShouldTriggerSafetyTipFromLookalike(
const GURL& url,
const lookalikes::DomainInfo& navigated_domain,
const std::vector<lookalikes::DomainInfo>& engaged_sites,
const DomainInfo& navigated_domain,
const std::vector<DomainInfo>& engaged_sites,
GURL* safe_url);
// Checks to see whether a given URL contains sensitive keywords in a way
......
......@@ -28,8 +28,6 @@ namespace {
using chrome_browser_safety_tips::FlaggedPage;
using chrome_browser_safety_tips::UrlPattern;
using lookalikes::DomainInfo;
using lookalikes::LookalikeUrlService;
using safe_browsing::V4ProtocolManagerUtil;
using safety_tips::ReputationService;
......@@ -208,7 +206,7 @@ void ReputationService::GetReputationStatusWithEngagedSites(
ReputationCheckCallback callback,
const GURL& url,
const std::vector<DomainInfo>& engaged_sites) {
const DomainInfo navigated_domain = lookalikes::GetDomainInfo(url);
const DomainInfo navigated_domain = GetDomainInfo(url);
// 0. Server-side warning suppression.
// If the URL is on the allowlist list, do nothing else. This is only used to
......@@ -245,7 +243,7 @@ void ReputationService::GetReputationStatusWithEngagedSites(
// 3. Protect against bad false positives by allowing top domains.
// Empty domain_and_registry happens on private domains.
if (navigated_domain.domain_and_registry.empty() ||
lookalikes::IsTopDomain(navigated_domain)) {
IsTopDomain(navigated_domain)) {
std::move(callback).Run(security_state::SafetyTipStatus::kNone,
IsIgnored(url), url, GURL());
return;
......
......@@ -17,10 +17,7 @@
#include "url/origin.h"
class Profile;
namespace lookalikes {
struct DomainInfo;
}
namespace safety_tips {
......@@ -67,7 +64,7 @@ class ReputationService : public KeyedService {
void GetReputationStatusWithEngagedSites(
ReputationCheckCallback callback,
const GURL& url,
const std::vector<lookalikes::DomainInfo>& engaged_sites);
const std::vector<DomainInfo>& engaged_sites);
// Set of origins that we've warned about, and the user has explicitly
// ignored. Used to avoid re-warning the user.
......
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