Skip to content

Commit

Permalink
[Safe Browsing] Rename CSDService::Delegate implementations
Browse files Browse the repository at this point in the history
The //chrome and //weblayer implementations of this interface are both
named ClientSideDetectionServiceDelegate. This CL renames them to the
canonical {Chrome, WebLayer}ClientSideDetectionServiceDelegate for
consistency and clarity.

Bug: 1226567
Change-Id: I3c0026567b55cfde2a5327e1aee17e23527dc337
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3135473
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Xinghui Lu <xinghuilu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#917642}
  • Loading branch information
colinblundell authored and Chromium LUCI CQ committed Sep 2, 2021
1 parent 98de678 commit eb1d021
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 50 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/safe_browsing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ static_library("safe_browsing") {
"certificate_reporting_service_factory.h",
"chrome_client_side_detection_host_delegate.cc",
"chrome_client_side_detection_host_delegate.h",
"chrome_client_side_detection_service_delegate.cc",
"chrome_client_side_detection_service_delegate.h",
"chrome_password_protection_service.cc",
"chrome_password_protection_service.h",
"chrome_password_protection_service_factory.cc",
Expand All @@ -108,8 +110,6 @@ static_library("safe_browsing") {
"chrome_safe_browsing_blocking_page_factory.h",
"chrome_ui_manager_delegate.cc",
"chrome_ui_manager_delegate.h",
"client_side_detection_service_delegate.cc",
"client_side_detection_service_delegate.h",
"client_side_detection_service_factory.cc",
"client_side_detection_service_factory.h",
"delayed_warning_navigation_throttle.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/safe_browsing/client_side_detection_service_delegate.h"
#include "chrome/browser/safe_browsing/chrome_client_side_detection_service_delegate.h"

#include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
Expand All @@ -14,37 +14,38 @@

namespace safe_browsing {

ClientSideDetectionServiceDelegate::ClientSideDetectionServiceDelegate(
Profile* profile)
ChromeClientSideDetectionServiceDelegate::
ChromeClientSideDetectionServiceDelegate(Profile* profile)
: profile_(profile) {}

ClientSideDetectionServiceDelegate::~ClientSideDetectionServiceDelegate() =
default;
ChromeClientSideDetectionServiceDelegate::
~ChromeClientSideDetectionServiceDelegate() = default;

PrefService* ClientSideDetectionServiceDelegate::GetPrefs() {
PrefService* ChromeClientSideDetectionServiceDelegate::GetPrefs() {
if (profile_) {
return profile_->GetPrefs();
}
return nullptr;
}
scoped_refptr<network::SharedURLLoaderFactory>
ClientSideDetectionServiceDelegate::GetURLLoaderFactory() {
ChromeClientSideDetectionServiceDelegate::GetURLLoaderFactory() {
if (profile_) {
return profile_->GetURLLoaderFactory();
}
return nullptr;
}

scoped_refptr<network::SharedURLLoaderFactory>
ClientSideDetectionServiceDelegate::GetSafeBrowsingURLLoaderFactory() {
ChromeClientSideDetectionServiceDelegate::GetSafeBrowsingURLLoaderFactory() {
if (g_browser_process->safe_browsing_service()) {
return g_browser_process->safe_browsing_service()->GetURLLoaderFactory(
profile_);
}
return nullptr;
}

ChromeUserPopulation ClientSideDetectionServiceDelegate::GetUserPopulation() {
ChromeUserPopulation
ChromeClientSideDetectionServiceDelegate::GetUserPopulation() {
return ::safe_browsing::GetUserPopulation(profile_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#define CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#define CHROME_BROWSER_SAFE_BROWSING_CHROME_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_

#include "components/safe_browsing/content/browser/client_side_detection_service.h"

Expand All @@ -13,11 +13,11 @@ namespace safe_browsing {

// Delegate class which implements chrome specific bits for configuring
// the ClientSideDetectionService class.
class ClientSideDetectionServiceDelegate
class ChromeClientSideDetectionServiceDelegate
: public ClientSideDetectionService::Delegate {
public:
explicit ClientSideDetectionServiceDelegate(Profile* profile);
~ClientSideDetectionServiceDelegate() override;
explicit ChromeClientSideDetectionServiceDelegate(Profile* profile);
~ChromeClientSideDetectionServiceDelegate() override;

// ClientSideDetectionService::Delegate implementation.
PrefService* GetPrefs() override;
Expand All @@ -29,9 +29,9 @@ class ClientSideDetectionServiceDelegate
private:
Profile* profile_;

DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionServiceDelegate);
DISALLOW_COPY_AND_ASSIGN(ChromeClientSideDetectionServiceDelegate);
};

} // namespace safe_browsing

#endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/safe_browsing/client_side_detection_service_delegate.h"
#include "chrome/browser/safe_browsing/chrome_client_side_detection_service_delegate.h"

#include "base/test/bind.h"
#include "chrome/browser/profiles/profile.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "base/command_line.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/client_side_detection_service_delegate.h"
#include "chrome/browser/safe_browsing/chrome_client_side_detection_service_delegate.h"
#include "chrome/common/chrome_switches.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/safe_browsing/buildflags.h"
Expand Down Expand Up @@ -55,7 +55,7 @@ KeyedService* ClientSideDetectionServiceFactory::BuildServiceInstanceFor(

Profile* profile = Profile::FromBrowserContext(context);
return new ClientSideDetectionService(
std::make_unique<ClientSideDetectionServiceDelegate>(profile));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile));
}

content::BrowserContext*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/safe_browsing/client_side_detection_service_delegate.h"
#include "chrome/browser/safe_browsing/chrome_client_side_detection_service_delegate.h"

#include <stdint.h>

Expand Down Expand Up @@ -211,7 +211,7 @@ class ClientSideDetectionServiceTest : public testing::Test {
TEST_F(ClientSideDetectionServiceTest, ServiceObjectDeletedBeforeCallbackDone) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));
profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, true);
EXPECT_NE(csd_service_.get(), nullptr);
// We delete the client-side detection service class even though the callbacks
Expand All @@ -225,7 +225,7 @@ TEST_F(ClientSideDetectionServiceTest, ServiceObjectDeletedBeforeCallbackDone) {
TEST_F(ClientSideDetectionServiceTest, SendClientReportPhishingRequest) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));
csd_service_->SetURLLoaderFactoryForTesting(test_shared_loader_factory_);

GURL url("http://a.com/");
Expand Down Expand Up @@ -284,7 +284,7 @@ TEST_F(ClientSideDetectionServiceTest,
SendClientReportPhishingRequestWithToken) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));
csd_service_->SetURLLoaderFactoryForTesting(test_shared_loader_factory_);

profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, true);
Expand All @@ -309,7 +309,7 @@ TEST_F(ClientSideDetectionServiceTest,
SendClientReportPhishingRequestWithoutToken) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));
csd_service_->SetURLLoaderFactoryForTesting(test_shared_loader_factory_);

profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, true);
Expand All @@ -332,7 +332,7 @@ TEST_F(ClientSideDetectionServiceTest,
TEST_F(ClientSideDetectionServiceTest, GetNumReportTest) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));

base::Time now = base::Time::Now();
base::TimeDelta twenty_five_hours = base::TimeDelta::FromHours(25);
Expand All @@ -348,15 +348,15 @@ TEST_F(ClientSideDetectionServiceTest, GetNumReportTest) {
TEST_F(ClientSideDetectionServiceTest, CacheTest) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));

TestCache();
}

TEST_F(ClientSideDetectionServiceTest, IsPrivateIPAddress) {
SetModelFetchResponses();
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));

EXPECT_TRUE(csd_service_->IsPrivateIPAddress("10.1.2.3"));
EXPECT_TRUE(csd_service_->IsPrivateIPAddress("127.0.0.1"));
Expand All @@ -383,7 +383,7 @@ TEST_F(ClientSideDetectionServiceTest, TestModelFollowsPrefs) {
false);
profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnhanced, false);
csd_service_ = std::make_unique<ClientSideDetectionService>(
std::make_unique<ClientSideDetectionServiceDelegate>(profile_));
std::make_unique<ChromeClientSideDetectionServiceDelegate>(profile_));

// Safe Browsing is not enabled.
EXPECT_FALSE(csd_service_->enabled());
Expand Down
4 changes: 2 additions & 2 deletions weblayer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@ source_set("weblayer_lib_base") {
"browser/new_tab_callback_proxy.h",
"browser/proxying_url_loader_factory_impl.cc",
"browser/proxying_url_loader_factory_impl.h",
"browser/safe_browsing/client_side_detection_service_delegate.cc",
"browser/safe_browsing/client_side_detection_service_delegate.h",
"browser/safe_browsing/client_side_detection_service_factory.cc",
"browser/safe_browsing/client_side_detection_service_factory.h",
"browser/safe_browsing/real_time_url_lookup_service_factory.cc",
Expand All @@ -653,6 +651,8 @@ source_set("weblayer_lib_base") {
"browser/safe_browsing/url_checker_delegate_impl.h",
"browser/safe_browsing/weblayer_client_side_detection_host_delegate.cc",
"browser/safe_browsing/weblayer_client_side_detection_host_delegate.h",
"browser/safe_browsing/weblayer_client_side_detection_service_delegate.cc",
"browser/safe_browsing/weblayer_client_side_detection_service_delegate.h",
"browser/safe_browsing/weblayer_safe_browsing_blocking_page_factory.cc",
"browser/safe_browsing/weblayer_safe_browsing_blocking_page_factory.h",
"browser/safe_browsing/weblayer_safe_browsing_tab_observer_delegate.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "weblayer/browser/browser_context_impl.h"
#include "weblayer/browser/browser_process.h"
#include "weblayer/browser/feature_list_creator.h"
#include "weblayer/browser/safe_browsing/client_side_detection_service_delegate.h"
#include "weblayer/browser/safe_browsing/weblayer_client_side_detection_service_delegate.h"
#include "weblayer/common/features.h"

namespace weblayer {
Expand Down Expand Up @@ -46,7 +46,7 @@ ClientSideDetectionServiceFactory::~ClientSideDetectionServiceFactory() =
KeyedService* ClientSideDetectionServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new safe_browsing::ClientSideDetectionService(
std::make_unique<ClientSideDetectionServiceDelegate>(
std::make_unique<WebLayerClientSideDetectionServiceDelegate>(
static_cast<BrowserContextImpl*>(context)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "weblayer/browser/safe_browsing/client_side_detection_service_delegate.h"
#include "weblayer/browser/safe_browsing/weblayer_client_side_detection_service_delegate.h"

#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
Expand All @@ -15,33 +15,34 @@

namespace weblayer {

ClientSideDetectionServiceDelegate::ClientSideDetectionServiceDelegate(
BrowserContextImpl* browser_context)
WebLayerClientSideDetectionServiceDelegate::
WebLayerClientSideDetectionServiceDelegate(
BrowserContextImpl* browser_context)
: browser_context_(browser_context) {}

ClientSideDetectionServiceDelegate::~ClientSideDetectionServiceDelegate() =
default;
WebLayerClientSideDetectionServiceDelegate::
~WebLayerClientSideDetectionServiceDelegate() = default;

PrefService* ClientSideDetectionServiceDelegate::GetPrefs() {
PrefService* WebLayerClientSideDetectionServiceDelegate::GetPrefs() {
DCHECK(browser_context_);
return browser_context_->pref_service();
}

scoped_refptr<network::SharedURLLoaderFactory>
ClientSideDetectionServiceDelegate::GetURLLoaderFactory() {
WebLayerClientSideDetectionServiceDelegate::GetURLLoaderFactory() {
return browser_context_->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess();
}

scoped_refptr<network::SharedURLLoaderFactory>
ClientSideDetectionServiceDelegate::GetSafeBrowsingURLLoaderFactory() {
WebLayerClientSideDetectionServiceDelegate::GetSafeBrowsingURLLoaderFactory() {
SafeBrowsingService* sb_service =
BrowserProcess::GetInstance()->GetSafeBrowsingService();
return sb_service->GetURLLoaderFactory();
}

safe_browsing::ChromeUserPopulation
ClientSideDetectionServiceDelegate::GetUserPopulation() {
WebLayerClientSideDetectionServiceDelegate::GetUserPopulation() {
safe_browsing::ChromeUserPopulation population;
if (safe_browsing::IsEnhancedProtectionEnabled(*GetPrefs())) {
population.set_user_population(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBLAYER_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#define WEBLAYER_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#ifndef WEBLAYER_BROWSER_SAFE_BROWSING_WEBLAYER_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#define WEBLAYER_BROWSER_SAFE_BROWSING_WEBLAYER_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_

#include "components/safe_browsing/content/browser/client_side_detection_service.h"
#include "weblayer/browser/browser_context_impl.h"

namespace weblayer {

class ClientSideDetectionServiceDelegate
class WebLayerClientSideDetectionServiceDelegate
: public safe_browsing::ClientSideDetectionService::Delegate {
public:
explicit ClientSideDetectionServiceDelegate(
explicit WebLayerClientSideDetectionServiceDelegate(
BrowserContextImpl* browser_context);
~ClientSideDetectionServiceDelegate() override;
~WebLayerClientSideDetectionServiceDelegate() override;

// ClientSideDetectionService::Delegate implementation.
PrefService* GetPrefs() override;
Expand All @@ -27,9 +27,9 @@ class ClientSideDetectionServiceDelegate
private:
BrowserContextImpl* browser_context_;

DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionServiceDelegate);
DISALLOW_COPY_AND_ASSIGN(WebLayerClientSideDetectionServiceDelegate);
};

} // namespace weblayer

#endif // WEBLAYER_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_
#endif // WEBLAYER_BROWSER_SAFE_BROWSING_WEBLAYER_CLIENT_SIDE_DETECTION_SERVICE_DELEGATE_H_

0 comments on commit eb1d021

Please sign in to comment.