Commit 85753b0f authored by Colin Blundell's avatar Colin Blundell Committed by Chromium LUCI CQ

[Safe Browsing] Abstract signin dep from RealTimeUrlLookupService

This CL continues with the abstraction of dependencies on signin and
sync from //components/safe_browsing's access token fetching flow in
order to enable reuse by WebLayer. The concrete step taken here is to
abstract the dependencies on
//components/safe_browsing/core/browser/sync from
RealTimeUrlLookupService, passing these dependencies in via the
constructor. There are no behavioral changes in this CL:
- //chrome and //ios/chrome's factories glue the relevant parameters
  from //components/safe_browsing/core/browser/sync
- //weblayer's factory passes in values for the parameters such that
  access token fetching for URL lookups continues to be disabled in
  WebLayer

Followup work will bring up support for access token fetching in
WebLayer.

Bug: 1080748
Change-Id: I69fca4b2d04118088bb48596eb192beab7bafb4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621301Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarXinghui Lu <xinghuilu@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842942}
parent 4b932f7f
...@@ -2187,6 +2187,7 @@ static_library("browser") { ...@@ -2187,6 +2187,7 @@ static_library("browser") {
"//components/safe_browsing/core:file_type_policies", "//components/safe_browsing/core:file_type_policies",
"//components/safe_browsing/core:public", "//components/safe_browsing/core:public",
"//components/safe_browsing/core/browser", "//components/safe_browsing/core/browser",
"//components/safe_browsing/core/browser/sync",
"//components/safe_browsing/core/common", "//components/safe_browsing/core/common",
"//components/safe_browsing/core/common:safe_browsing_policy_handler", "//components/safe_browsing/core/common:safe_browsing_policy_handler",
"//components/safe_browsing/core/db:database_manager", "//components/safe_browsing/core/db:database_manager",
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/safe_browsing/url_lookup_service_factory.h" #include "chrome/browser/safe_browsing/url_lookup_service_factory.h"
#include "base/bind.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h" #include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -15,6 +16,8 @@ ...@@ -15,6 +16,8 @@
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/safe_browsing/buildflags.h" #include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/browser/sync/safe_browsing_primary_account_token_fetcher.h"
#include "components/safe_browsing/core/browser/sync/sync_utils.h"
#include "components/safe_browsing/core/common/utils.h" #include "components/safe_browsing/core/common/utils.h"
#include "components/safe_browsing/core/realtime/url_lookup_service.h" #include "components/safe_browsing/core/realtime/url_lookup_service.h"
#include "components/safe_browsing/core/verdict_cache_manager.h" #include "components/safe_browsing/core/verdict_cache_manager.h"
...@@ -69,8 +72,13 @@ KeyedService* RealTimeUrlLookupServiceFactory::BuildServiceInstanceFor( ...@@ -69,8 +72,13 @@ KeyedService* RealTimeUrlLookupServiceFactory::BuildServiceInstanceFor(
return new RealTimeUrlLookupService( return new RealTimeUrlLookupService(
network::SharedURLLoaderFactory::Create(std::move(url_loader_factory)), network::SharedURLLoaderFactory::Create(std::move(url_loader_factory)),
VerdictCacheManagerFactory::GetForProfile(profile), VerdictCacheManagerFactory::GetForProfile(profile),
IdentityManagerFactory::GetForProfile(profile),
ProfileSyncServiceFactory::GetForProfile(profile), profile->GetPrefs(), ProfileSyncServiceFactory::GetForProfile(profile), profile->GetPrefs(),
std::make_unique<SafeBrowsingPrimaryAccountTokenFetcher>(
IdentityManagerFactory::GetForProfile(profile)),
base::BindRepeating(&safe_browsing::SyncUtils::
AreSigninAndSyncSetUpForSafeBrowsingTokenFetches,
ProfileSyncServiceFactory::GetForProfile(profile),
IdentityManagerFactory::GetForProfile(profile)),
GetProfileManagementStatus(browser_policy_connector), GetProfileManagementStatus(browser_policy_connector),
is_under_advanced_protection, profile->IsOffTheRecord(), is_under_advanced_protection, profile->IsOffTheRecord(),
g_browser_process->variations_service()); g_browser_process->variations_service());
......
...@@ -58,6 +58,7 @@ source_set("safe_browsing_url_checker_unittest") { ...@@ -58,6 +58,7 @@ source_set("safe_browsing_url_checker_unittest") {
":browser", ":browser",
"//base/test:test_support", "//base/test:test_support",
"//components/safe_browsing/core:csd_proto", "//components/safe_browsing/core:csd_proto",
"//components/safe_browsing/core/browser:token_fetcher",
"//components/safe_browsing/core/common:test_support", "//components/safe_browsing/core/common:test_support",
"//components/safe_browsing/core/common:thread_utils", "//components/safe_browsing/core/common:thread_utils",
"//components/safe_browsing/core/db:test_database_manager", "//components/safe_browsing/core/db:test_database_manager",
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
#include "components/safe_browsing/core/browser/safe_browsing_url_checker_impl.h" #include "components/safe_browsing/core/browser/safe_browsing_url_checker_impl.h"
#include <memory> #include <memory>
#include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "components/safe_browsing/core/browser/safe_browsing_token_fetcher.h"
#include "components/safe_browsing/core/browser/url_checker_delegate.h" #include "components/safe_browsing/core/browser/url_checker_delegate.h"
#include "components/safe_browsing/core/common/test_task_environment.h" #include "components/safe_browsing/core/common/test_task_environment.h"
#include "components/safe_browsing/core/common/thread_utils.h" #include "components/safe_browsing/core/common/thread_utils.h"
...@@ -166,11 +168,15 @@ class MockUrlCheckerDelegate : public UrlCheckerDelegate { ...@@ -166,11 +168,15 @@ class MockUrlCheckerDelegate : public UrlCheckerDelegate {
class MockRealTimeUrlLookupService : public RealTimeUrlLookupService { class MockRealTimeUrlLookupService : public RealTimeUrlLookupService {
public: public:
MockRealTimeUrlLookupService() MockRealTimeUrlLookupService()
: RealTimeUrlLookupService(/*url_loader_factory=*/nullptr, : RealTimeUrlLookupService(
/*url_loader_factory=*/nullptr,
/*cache_manager=*/nullptr, /*cache_manager=*/nullptr,
/*identity_manager=*/nullptr,
/*sync_service=*/nullptr, /*sync_service=*/nullptr,
/*pref_service=*/nullptr, /*pref_service=*/nullptr,
/*token_fetcher=*/nullptr,
/*client_token_config_callback=*/base::BindRepeating([](bool) {
return false;
}),
ChromeUserPopulation::NOT_MANAGED, ChromeUserPopulation::NOT_MANAGED,
/*is_under_advanced_protection=*/false, /*is_under_advanced_protection=*/false,
/*is_off_the_record=*/false, /*is_off_the_record=*/false,
......
...@@ -36,11 +36,10 @@ static_library("url_lookup_service") { ...@@ -36,11 +36,10 @@ static_library("url_lookup_service") {
"//components/safe_browsing/core:csd_proto", "//components/safe_browsing/core:csd_proto",
"//components/safe_browsing/core:realtimeapi_proto", "//components/safe_browsing/core:realtimeapi_proto",
"//components/safe_browsing/core:verdict_cache_manager", "//components/safe_browsing/core:verdict_cache_manager",
"//components/safe_browsing/core/browser/sync", "//components/safe_browsing/core/browser:token_fetcher",
"//components/safe_browsing/core/common:safe_browsing_prefs", "//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/safe_browsing/core/common:thread_utils", "//components/safe_browsing/core/common:thread_utils",
"//components/safe_browsing/core/db:v4_protocol_manager_util", "//components/safe_browsing/core/db:v4_protocol_manager_util",
"//components/signin/public/identity_manager",
"//components/sync", "//components/sync",
"//components/variations/service:service", "//components/variations/service:service",
"//services/network/public/cpp:cpp", "//services/network/public/cpp:cpp",
...@@ -57,6 +56,7 @@ static_library("url_lookup_service_base") { ...@@ -57,6 +56,7 @@ static_library("url_lookup_service_base") {
deps = [ deps = [
"//base:base", "//base:base",
"//build:chromeos_buildflags", "//build:chromeos_buildflags",
"//components/keyed_service/core",
"//components/prefs", "//components/prefs",
"//components/safe_browsing:buildflags", "//components/safe_browsing:buildflags",
"//components/safe_browsing/core:csd_proto", "//components/safe_browsing/core:csd_proto",
...@@ -67,7 +67,6 @@ static_library("url_lookup_service_base") { ...@@ -67,7 +67,6 @@ static_library("url_lookup_service_base") {
"//components/safe_browsing/core/common:safe_browsing_prefs", "//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/safe_browsing/core/common:thread_utils", "//components/safe_browsing/core/common:thread_utils",
"//components/safe_browsing/core/db:v4_protocol_manager_util", "//components/safe_browsing/core/db:v4_protocol_manager_util",
"//components/signin/public/identity_manager",
"//components/sync", "//components/sync",
"//services/network/public/cpp:cpp", "//services/network/public/cpp:cpp",
"//url:url", "//url:url",
...@@ -88,10 +87,10 @@ source_set("unit_tests") { ...@@ -88,10 +87,10 @@ source_set("unit_tests") {
"//components/safe_browsing:buildflags", "//components/safe_browsing:buildflags",
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core:verdict_cache_manager", "//components/safe_browsing/core:verdict_cache_manager",
"//components/safe_browsing/core/browser:token_fetcher",
"//components/safe_browsing/core/common", "//components/safe_browsing/core/common",
"//components/safe_browsing/core/common:safe_browsing_prefs", "//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/safe_browsing/core/common:test_support", "//components/safe_browsing/core/common:test_support",
"//components/signin/public/identity_manager:test_support",
"//components/sync:test_support", "//components/sync:test_support",
"//components/sync_preferences:test_support", "//components/sync_preferences:test_support",
"//components/unified_consent", "//components/unified_consent",
......
...@@ -30,7 +30,7 @@ class RealTimePolicyEngine { ...@@ -30,7 +30,7 @@ class RealTimePolicyEngine {
RealTimePolicyEngine() = delete; RealTimePolicyEngine() = delete;
~RealTimePolicyEngine() = delete; ~RealTimePolicyEngine() = delete;
// A callback via which the client of this component indicates whether they // A callback via which the client of this class indicates whether they
// are configured to support token fetches. Used as part of // are configured to support token fetches. Used as part of
// CanPerformFullURLLookupWithToken(). // CanPerformFullURLLookupWithToken().
using ClientConfiguredForTokenFetchesCallback = using ClientConfiguredForTokenFetchesCallback =
......
...@@ -13,14 +13,11 @@ ...@@ -13,14 +13,11 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/buildflags.h" #include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/browser/sync/safe_browsing_primary_account_token_fetcher.h" #include "components/safe_browsing/core/browser/safe_browsing_token_fetcher.h"
#include "components/safe_browsing/core/browser/sync/sync_utils.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h" #include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/thread_utils.h" #include "components/safe_browsing/core/common/thread_utils.h"
#include "components/safe_browsing/core/db/v4_protocol_manager_util.h" #include "components/safe_browsing/core/db/v4_protocol_manager_util.h"
#include "components/safe_browsing/core/realtime/policy_engine.h" #include "components/safe_browsing/core/realtime/policy_engine.h"
#include "components/signin/public/identity_manager/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#include "net/base/ip_address.h" #include "net/base/ip_address.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -35,9 +32,10 @@ namespace safe_browsing { ...@@ -35,9 +32,10 @@ namespace safe_browsing {
RealTimeUrlLookupService::RealTimeUrlLookupService( RealTimeUrlLookupService::RealTimeUrlLookupService(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
VerdictCacheManager* cache_manager, VerdictCacheManager* cache_manager,
signin::IdentityManager* identity_manager,
syncer::SyncService* sync_service, syncer::SyncService* sync_service,
PrefService* pref_service, PrefService* pref_service,
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher,
const ClientConfiguredForTokenFetchesCallback& client_token_config_callback,
const ChromeUserPopulation::ProfileManagementStatus& const ChromeUserPopulation::ProfileManagementStatus&
profile_management_status, profile_management_status,
bool is_under_advanced_protection, bool is_under_advanced_protection,
...@@ -50,14 +48,12 @@ RealTimeUrlLookupService::RealTimeUrlLookupService( ...@@ -50,14 +48,12 @@ RealTimeUrlLookupService::RealTimeUrlLookupService(
profile_management_status, profile_management_status,
is_under_advanced_protection, is_under_advanced_protection,
is_off_the_record), is_off_the_record),
identity_manager_(identity_manager),
sync_service_(sync_service), sync_service_(sync_service),
pref_service_(pref_service), pref_service_(pref_service),
token_fetcher_(std::move(token_fetcher)),
client_token_config_callback_(client_token_config_callback),
is_off_the_record_(is_off_the_record), is_off_the_record_(is_off_the_record),
variations_(variations_service) { variations_(variations_service) {}
token_fetcher_ = std::make_unique<SafeBrowsingPrimaryAccountTokenFetcher>(
identity_manager_);
}
void RealTimeUrlLookupService::GetAccessToken( void RealTimeUrlLookupService::GetAccessToken(
const GURL& url, const GURL& url,
...@@ -93,10 +89,7 @@ bool RealTimeUrlLookupService::CanPerformFullURLLookup() const { ...@@ -93,10 +89,7 @@ bool RealTimeUrlLookupService::CanPerformFullURLLookup() const {
bool RealTimeUrlLookupService::CanPerformFullURLLookupWithToken() const { bool RealTimeUrlLookupService::CanPerformFullURLLookupWithToken() const {
return RealTimePolicyEngine::CanPerformFullURLLookupWithToken( return RealTimePolicyEngine::CanPerformFullURLLookupWithToken(
pref_service_, is_off_the_record_, pref_service_, is_off_the_record_, client_token_config_callback_,
base::BindOnce(
&SyncUtils::AreSigninAndSyncSetUpForSafeBrowsingTokenFetches,
sync_service_, identity_manager_),
variations_); variations_);
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "components/safe_browsing/core/proto/csd.pb.h" #include "components/safe_browsing/core/proto/csd.pb.h"
#include "components/safe_browsing/core/proto/realtimeapi.pb.h" #include "components/safe_browsing/core/proto/realtimeapi.pb.h"
#include "components/safe_browsing/core/realtime/url_lookup_service_base.h" #include "components/safe_browsing/core/realtime/url_lookup_service_base.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace net { namespace net {
...@@ -29,10 +28,6 @@ namespace network { ...@@ -29,10 +28,6 @@ namespace network {
class SharedURLLoaderFactory; class SharedURLLoaderFactory;
} // namespace network } // namespace network
namespace signin {
class IdentityManager;
}
namespace syncer { namespace syncer {
class SyncService; class SyncService;
} }
...@@ -52,14 +47,23 @@ class SafeBrowsingTokenFetcher; ...@@ -52,14 +47,23 @@ class SafeBrowsingTokenFetcher;
// users.(See: go/chrome-protego-enterprise-dd) // users.(See: go/chrome-protego-enterprise-dd)
class RealTimeUrlLookupService : public RealTimeUrlLookupServiceBase { class RealTimeUrlLookupService : public RealTimeUrlLookupServiceBase {
public: public:
// |cache_manager|, |identity_manager|, |sync_service| and |pref_service| may // A callback via which the client of this component indicates whether they
// be null in tests. // are configured to support token fetches.
using ClientConfiguredForTokenFetchesCallback =
base::RepeatingCallback<bool(bool user_has_enabled_enhanced_protection)>;
// |cache_manager|, |sync_service|, and |pref_service| may be null in tests.
// |token_fetcher| may also be null, but in that case the passed-in
// |client_token_config_callback| should return false to ensure that access
// token fetches are not actually invoked.
RealTimeUrlLookupService( RealTimeUrlLookupService(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
VerdictCacheManager* cache_manager, VerdictCacheManager* cache_manager,
signin::IdentityManager* identity_manager,
syncer::SyncService* sync_service, syncer::SyncService* sync_service,
PrefService* pref_service, PrefService* pref_service,
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher,
const ClientConfiguredForTokenFetchesCallback&
client_token_config_callback,
const ChromeUserPopulation::ProfileManagementStatus& const ChromeUserPopulation::ProfileManagementStatus&
profile_management_status, profile_management_status,
bool is_under_advanced_protection, bool is_under_advanced_protection,
...@@ -91,10 +95,6 @@ class RealTimeUrlLookupService : public RealTimeUrlLookupServiceBase { ...@@ -91,10 +95,6 @@ class RealTimeUrlLookupService : public RealTimeUrlLookupServiceBase {
base::TimeTicks get_token_start_time, base::TimeTicks get_token_start_time,
const std::string& access_token); const std::string& access_token);
// Unowned object used for getting access token when real time url check with
// token is enabled.
signin::IdentityManager* identity_manager_;
// Unowned object used for checking sync status of the profile. // Unowned object used for checking sync status of the profile.
syncer::SyncService* sync_service_; syncer::SyncService* sync_service_;
...@@ -104,6 +104,10 @@ class RealTimeUrlLookupService : public RealTimeUrlLookupServiceBase { ...@@ -104,6 +104,10 @@ class RealTimeUrlLookupService : public RealTimeUrlLookupServiceBase {
// The token fetcher used for getting access token. // The token fetcher used for getting access token.
std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher_; std::unique_ptr<SafeBrowsingTokenFetcher> token_fetcher_;
// The callback via which the client of this component indicates whether they
// are configured to support token fetches.
ClientConfiguredForTokenFetchesCallback client_token_config_callback_;
// A boolean indicates whether the profile associated with this // A boolean indicates whether the profile associated with this
// |url_lookup_service| is an off the record profile. // |url_lookup_service| is an off the record profile.
bool is_off_the_record_; bool is_off_the_record_;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/safe_browsing/core/realtime/url_lookup_service.h" #include "components/safe_browsing/core/realtime/url_lookup_service.h"
#include "base/bind.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
...@@ -11,10 +12,10 @@ ...@@ -11,10 +12,10 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/safe_browsing/buildflags.h" #include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/browser/safe_browsing_token_fetcher.h"
#include "components/safe_browsing/core/common/test_task_environment.h" #include "components/safe_browsing/core/common/test_task_environment.h"
#include "components/safe_browsing/core/features.h" #include "components/safe_browsing/core/features.h"
#include "components/safe_browsing/core/verdict_cache_manager.h" #include "components/safe_browsing/core/verdict_cache_manager.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/sync/driver/test_sync_service.h" #include "components/sync/driver/test_sync_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/unified_consent/pref_names.h" #include "components/unified_consent/pref_names.h"
...@@ -29,9 +30,25 @@ using ::testing::_; ...@@ -29,9 +30,25 @@ using ::testing::_;
namespace safe_browsing { namespace safe_browsing {
namespace { namespace {
constexpr char kTestEmail[] = "test@example.com";
constexpr char kRealTimeLookupUrlPrefix[] = constexpr char kRealTimeLookupUrlPrefix[] =
"https://safebrowsing.google.com/safebrowsing/clientreport/realtime"; "https://safebrowsing.google.com/safebrowsing/clientreport/realtime";
class TestSafeBrowsingTokenFetcher : public SafeBrowsingTokenFetcher {
public:
TestSafeBrowsingTokenFetcher() = default;
~TestSafeBrowsingTokenFetcher() override = default;
// SafeBrowsingTokenFetcher:
void Start(Callback callback) override { callback_ = std::move(callback); }
void RunAccessTokenCallback(std::string token) {
std::move(callback_).Run(token);
}
private:
Callback callback_;
};
} // namespace } // namespace
class RealTimeUrlLookupServiceTest : public PlatformTest { class RealTimeUrlLookupServiceTest : public PlatformTest {
...@@ -54,11 +71,15 @@ class RealTimeUrlLookupServiceTest : public PlatformTest { ...@@ -54,11 +71,15 @@ class RealTimeUrlLookupServiceTest : public PlatformTest {
cache_manager_ = std::make_unique<VerdictCacheManager>( cache_manager_ = std::make_unique<VerdictCacheManager>(
nullptr, content_setting_map_.get()); nullptr, content_setting_map_.get());
identity_test_env_ = std::make_unique<signin::IdentityTestEnvironment>(); auto token_fetcher = std::make_unique<TestSafeBrowsingTokenFetcher>();
raw_token_fetcher_ = token_fetcher.get();
rt_service_ = std::make_unique<RealTimeUrlLookupService>( rt_service_ = std::make_unique<RealTimeUrlLookupService>(
test_shared_loader_factory_, cache_manager_.get(), test_shared_loader_factory_, cache_manager_.get(), &test_sync_service_,
identity_test_env_->identity_manager(), &test_sync_service_, &test_pref_service_, std::move(token_fetcher),
&test_pref_service_, ChromeUserPopulation::NOT_MANAGED, base::BindRepeating(
&RealTimeUrlLookupServiceTest::AreTokenFetchesConfiguredInClient,
base::Unretained(this)),
ChromeUserPopulation::NOT_MANAGED,
/*is_under_advanced_protection=*/true, /*is_under_advanced_protection=*/true,
/*is_off_the_record=*/false, /*variations_service=*/nullptr); /*is_off_the_record=*/false, /*variations_service=*/nullptr);
} }
...@@ -140,14 +161,17 @@ class RealTimeUrlLookupServiceTest : public PlatformTest { ...@@ -140,14 +161,17 @@ class RealTimeUrlLookupServiceTest : public PlatformTest {
} }
} }
void SetupPrimaryAccount() { void EnableTokenFetchesInClient() {
identity_test_env_->MakeUnconsentedPrimaryAccountAvailable(kTestEmail); token_fetches_configured_in_client_ = true;
}
void FulfillAccessTokenRequest(std::string token) {
raw_token_fetcher_->RunAccessTokenCallback(token);
} }
void WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( bool AreTokenFetchesConfiguredInClient(
std::string token) { bool user_has_enabled_extended_protection) {
identity_test_env_->WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( return token_fetches_configured_in_client_;
token, base::Time::Max());
} }
network::TestURLLoaderFactory test_url_loader_factory_; network::TestURLLoaderFactory test_url_loader_factory_;
...@@ -155,8 +179,9 @@ class RealTimeUrlLookupServiceTest : public PlatformTest { ...@@ -155,8 +179,9 @@ class RealTimeUrlLookupServiceTest : public PlatformTest {
std::unique_ptr<RealTimeUrlLookupService> rt_service_; std::unique_ptr<RealTimeUrlLookupService> rt_service_;
std::unique_ptr<VerdictCacheManager> cache_manager_; std::unique_ptr<VerdictCacheManager> cache_manager_;
scoped_refptr<HostContentSettingsMap> content_setting_map_; scoped_refptr<HostContentSettingsMap> content_setting_map_;
bool token_fetches_configured_in_client_ = false;
TestSafeBrowsingTokenFetcher* raw_token_fetcher_ = nullptr;
std::unique_ptr<base::test::TaskEnvironment> task_environment_; std::unique_ptr<base::test::TaskEnvironment> task_environment_;
std::unique_ptr<signin::IdentityTestEnvironment> identity_test_env_;
sync_preferences::TestingPrefServiceSyncable test_pref_service_; sync_preferences::TestingPrefServiceSyncable test_pref_service_;
syncer::TestSyncService test_sync_service_; syncer::TestSyncService test_sync_service_;
base::test::ScopedFeatureList feature_list_; base::test::ScopedFeatureList feature_list_;
...@@ -558,7 +583,7 @@ TEST_F(RealTimeUrlLookupServiceTest, ...@@ -558,7 +583,7 @@ TEST_F(RealTimeUrlLookupServiceTest,
TestStartLookup_AttachTokenWhenWithTokenIsEnabled) { TestStartLookup_AttachTokenWhenWithTokenIsEnabled) {
base::HistogramTester histograms; base::HistogramTester histograms;
EnableRealTimeUrlLookup(/* is_with_token_enabled */ true); EnableRealTimeUrlLookup(/* is_with_token_enabled */ true);
SetupPrimaryAccount(); EnableTokenFetchesInClient();
GURL url("http://example.test/"); GURL url("http://example.test/");
SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS, SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60, RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60,
...@@ -579,8 +604,7 @@ TEST_F(RealTimeUrlLookupServiceTest, ...@@ -579,8 +604,7 @@ TEST_F(RealTimeUrlLookupServiceTest,
EXPECT_CALL(response_callback, Run(/* is_rt_lookup_successful */ true, EXPECT_CALL(response_callback, Run(/* is_rt_lookup_successful */ true,
/* is_cached_response */ false, _)); /* is_cached_response */ false, _));
WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( FulfillAccessTokenRequest("access_token_string");
"access_token_string");
task_environment_->RunUntilIdle(); task_environment_->RunUntilIdle();
// Check the response is cached. // Check the response is cached.
...@@ -593,7 +617,8 @@ TEST_F(RealTimeUrlLookupServiceTest, ...@@ -593,7 +617,8 @@ TEST_F(RealTimeUrlLookupServiceTest,
/* expected_count */ 1); /* expected_count */ 1);
} }
TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_NoTokenWhenNotSignedIn) { TEST_F(RealTimeUrlLookupServiceTest,
TestStartLookup_NoTokenWhenNotConfiguredInClient) {
EnableRealTimeUrlLookup(/* is_with_token_enabled */ true); EnableRealTimeUrlLookup(/* is_with_token_enabled */ true);
GURL url("http://example.test/"); GURL url("http://example.test/");
SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS, SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS,
...@@ -606,7 +631,8 @@ TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_NoTokenWhenNotSignedIn) { ...@@ -606,7 +631,8 @@ TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_NoTokenWhenNotSignedIn) {
url, url,
base::BindOnce( base::BindOnce(
[](std::unique_ptr<RTLookupRequest> request, std::string token) { [](std::unique_ptr<RTLookupRequest> request, std::string token) {
// Check the token field is empty. // Check the token field is empty as the passed-in client callback
// indicates that token fetches are not configured in the client.
EXPECT_EQ("", token); EXPECT_EQ("", token);
}), }),
response_callback.Get()); response_callback.Get());
...@@ -625,7 +651,7 @@ TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_NoTokenWhenNotSignedIn) { ...@@ -625,7 +651,7 @@ TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_NoTokenWhenNotSignedIn) {
TEST_F(RealTimeUrlLookupServiceTest, TEST_F(RealTimeUrlLookupServiceTest,
TestStartLookup_NoTokenWhenWithTokenIsDisabled) { TestStartLookup_NoTokenWhenWithTokenIsDisabled) {
EnableRealTimeUrlLookup(/* is_with_token_enabled */ false); EnableRealTimeUrlLookup(/* is_with_token_enabled */ false);
SetupPrimaryAccount(); EnableTokenFetchesInClient();
GURL url("http://example.test/"); GURL url("http://example.test/");
SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS, SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60, RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60,
......
...@@ -40,6 +40,7 @@ source_set("safe_browsing") { ...@@ -40,6 +40,7 @@ source_set("safe_browsing") {
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core:verdict_cache_manager", "//components/safe_browsing/core:verdict_cache_manager",
"//components/safe_browsing/core/browser", "//components/safe_browsing/core/browser",
"//components/safe_browsing/core/browser/sync",
"//components/safe_browsing/core/common", "//components/safe_browsing/core/common",
"//components/safe_browsing/core/common:safe_browsing_prefs", "//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/safe_browsing/core/db", "//components/safe_browsing/core/db",
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
#include "ios/chrome/browser/safe_browsing/real_time_url_lookup_service_factory.h" #include "ios/chrome/browser/safe_browsing/real_time_url_lookup_service_factory.h"
#include "base/bind.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/safe_browsing/core/browser/sync/safe_browsing_primary_account_token_fetcher.h"
#include "components/safe_browsing/core/browser/sync/sync_utils.h"
#include "components/safe_browsing/core/common/utils.h" #include "components/safe_browsing/core/common/utils.h"
#include "components/safe_browsing/core/realtime/url_lookup_service.h" #include "components/safe_browsing/core/realtime/url_lookup_service.h"
#include "components/safe_browsing/core/verdict_cache_manager.h" #include "components/safe_browsing/core/verdict_cache_manager.h"
...@@ -57,9 +60,15 @@ RealTimeUrlLookupServiceFactory::BuildServiceInstanceFor( ...@@ -57,9 +60,15 @@ RealTimeUrlLookupServiceFactory::BuildServiceInstanceFor(
return std::make_unique<safe_browsing::RealTimeUrlLookupService>( return std::make_unique<safe_browsing::RealTimeUrlLookupService>(
safe_browsing_service->GetURLLoaderFactory(), safe_browsing_service->GetURLLoaderFactory(),
VerdictCacheManagerFactory::GetForBrowserState(chrome_browser_state), VerdictCacheManagerFactory::GetForBrowserState(chrome_browser_state),
IdentityManagerFactory::GetForBrowserState(chrome_browser_state),
ProfileSyncServiceFactory::GetForBrowserState(chrome_browser_state), ProfileSyncServiceFactory::GetForBrowserState(chrome_browser_state),
chrome_browser_state->GetPrefs(), chrome_browser_state->GetPrefs(),
std::make_unique<safe_browsing::SafeBrowsingPrimaryAccountTokenFetcher>(
IdentityManagerFactory::GetForBrowserState(chrome_browser_state)),
base::BindRepeating(
&safe_browsing::SyncUtils::
AreSigninAndSyncSetUpForSafeBrowsingTokenFetches,
ProfileSyncServiceFactory::GetForBrowserState(chrome_browser_state),
IdentityManagerFactory::GetForBrowserState(chrome_browser_state)),
safe_browsing::ChromeUserPopulation::NOT_MANAGED, safe_browsing::ChromeUserPopulation::NOT_MANAGED,
/*is_under_advanced_protection=*/false, /*is_under_advanced_protection=*/false,
chrome_browser_state->IsOffTheRecord(), chrome_browser_state->IsOffTheRecord(),
......
...@@ -659,6 +659,7 @@ source_set("weblayer_lib_base") { ...@@ -659,6 +659,7 @@ source_set("weblayer_lib_base") {
"//components/safe_browsing/core:verdict_cache_manager", "//components/safe_browsing/core:verdict_cache_manager",
"//components/safe_browsing/core/browser", "//components/safe_browsing/core/browser",
"//components/safe_browsing/core/browser:network_context", "//components/safe_browsing/core/browser:network_context",
"//components/safe_browsing/core/browser:token_fetcher",
"//components/safe_browsing/core/common", "//components/safe_browsing/core/common",
"//components/safe_browsing/core/db:allowlist_checker_client", "//components/safe_browsing/core/db:allowlist_checker_client",
"//components/safe_browsing/core/db:database_manager", "//components/safe_browsing/core/db:database_manager",
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "weblayer/browser/safe_browsing/real_time_url_lookup_service_factory.h" #include "weblayer/browser/safe_browsing/real_time_url_lookup_service_factory.h"
#include "base/bind.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/safe_browsing/core/browser/safe_browsing_token_fetcher.h"
#include "components/safe_browsing/core/common/utils.h" #include "components/safe_browsing/core/common/utils.h"
#include "components/safe_browsing/core/realtime/url_lookup_service.h" #include "components/safe_browsing/core/realtime/url_lookup_service.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -48,8 +50,12 @@ KeyedService* RealTimeUrlLookupServiceFactory::BuildServiceInstanceFor( ...@@ -48,8 +50,12 @@ KeyedService* RealTimeUrlLookupServiceFactory::BuildServiceInstanceFor(
return new safe_browsing::RealTimeUrlLookupService( return new safe_browsing::RealTimeUrlLookupService(
network::SharedURLLoaderFactory::Create(std::move(url_loader_factory)), network::SharedURLLoaderFactory::Create(std::move(url_loader_factory)),
VerdictCacheManagerFactory::GetForBrowserContext(context), VerdictCacheManagerFactory::GetForBrowserContext(context),
nullptr /* identity manager */, nullptr /* profile sync service */, nullptr /* profile sync service */,
static_cast<BrowserContextImpl*>(context)->pref_service(), static_cast<BrowserContextImpl*>(context)->pref_service(),
// TODO(crbug.com/1080748): Bring up token fetching for URL lookups and
// configure the following two parameters accordingly.
nullptr /* token_fetcher */,
base::BindRepeating([](bool) { return false; }),
safe_browsing::GetProfileManagementStatus(nullptr), safe_browsing::GetProfileManagementStatus(nullptr),
false /* is_under_advanced_protection */, false /* is_under_advanced_protection */,
static_cast<BrowserContextImpl*>(context)->IsOffTheRecord(), static_cast<BrowserContextImpl*>(context)->IsOffTheRecord(),
......
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