Commit b1635617 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Add field trial for SafeBrowsingNetworkContexts

SafeBrowsingNetworkContexts is ready to roll out to Beta (see
cl/337414650), so add a field trial for it. A few tests fail with
the feature enabled, so we add a little code to fix those tests as
well.

Change-Id: I5254a0b632f5319f50d29756a996e69dcd3acc43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477252Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarBettina Dea <bdea@chromium.org>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820901}
parent 15a2fdb0
...@@ -72,15 +72,17 @@ ClientSideDetectionService::ClientSideDetectionService(Profile* profile) ...@@ -72,15 +72,17 @@ ClientSideDetectionService::ClientSideDetectionService(Profile* profile)
: profile_(profile), : profile_(profile),
enabled_(false), enabled_(false),
extended_reporting_(false), extended_reporting_(false),
url_loader_factory_( url_loader_factory_(nullptr) {
g_browser_process->safe_browsing_service()
? g_browser_process->safe_browsing_service()->GetURLLoaderFactory(
profile)
: nullptr) {
// |profile_| can be null in unit tests // |profile_| can be null in unit tests
if (!profile_) if (!profile_)
return; return;
if (g_browser_process->safe_browsing_service()) {
url_loader_factory_ =
g_browser_process->safe_browsing_service()->GetURLLoaderFactory(
profile);
}
pref_change_registrar_.Init(profile_->GetPrefs()); pref_change_registrar_.Init(profile_->GetPrefs());
pref_change_registrar_.Add( pref_change_registrar_.Add(
prefs::kSafeBrowsingEnabled, prefs::kSafeBrowsingEnabled,
......
...@@ -192,8 +192,14 @@ SafeBrowsingService::GetURLLoaderFactory(Profile* profile) { ...@@ -192,8 +192,14 @@ SafeBrowsingService::GetURLLoaderFactory(Profile* profile) {
if (!base::FeatureList::IsEnabled(kSafeBrowsingSeparateNetworkContexts)) if (!base::FeatureList::IsEnabled(kSafeBrowsingSeparateNetworkContexts))
return GetURLLoaderFactory(); return GetURLLoaderFactory();
return services_delegate_->GetSafeBrowsingNetworkContext(profile) safe_browsing::SafeBrowsingNetworkContext* network_context =
->GetURLLoaderFactory(); services_delegate_->GetSafeBrowsingNetworkContext(profile);
// |network_context| may be null in tests
if (!network_context)
return nullptr;
return network_context->GetURLLoaderFactory();
} }
void SafeBrowsingService::FlushNetworkInterfaceForTesting() { void SafeBrowsingService::FlushNetworkInterfaceForTesting() {
......
...@@ -115,8 +115,10 @@ SafeBrowsingNetworkContext* ServicesDelegate::GetSafeBrowsingNetworkContext( ...@@ -115,8 +115,10 @@ SafeBrowsingNetworkContext* ServicesDelegate::GetSafeBrowsingNetworkContext(
Profile* profile) const { Profile* profile) const {
DCHECK(profile); DCHECK(profile);
DCHECK(base::FeatureList::IsEnabled(kSafeBrowsingSeparateNetworkContexts)); DCHECK(base::FeatureList::IsEnabled(kSafeBrowsingSeparateNetworkContexts));
// In tests, we may not have been notified of Profile creation.
auto it = network_context_map_.find(profile); auto it = network_context_map_.find(profile);
DCHECK(it != network_context_map_.end()); if (it == network_context_map_.end())
return nullptr;
return it->second.get(); return it->second.get();
} }
......
...@@ -154,6 +154,13 @@ TestSafeBrowsingService::GetURLLoaderFactory() { ...@@ -154,6 +154,13 @@ TestSafeBrowsingService::GetURLLoaderFactory() {
return SafeBrowsingService::GetURLLoaderFactory(); return SafeBrowsingService::GetURLLoaderFactory();
} }
scoped_refptr<network::SharedURLLoaderFactory>
TestSafeBrowsingService::GetURLLoaderFactory(Profile* profile) {
if (use_test_url_loader_factory_)
return test_shared_loader_factory_;
return SafeBrowsingService::GetURLLoaderFactory(profile);
}
// TestSafeBrowsingServiceFactory functions: // TestSafeBrowsingServiceFactory functions:
TestSafeBrowsingServiceFactory::TestSafeBrowsingServiceFactory() TestSafeBrowsingServiceFactory::TestSafeBrowsingServiceFactory()
: test_safe_browsing_service_(nullptr), use_v4_local_db_manager_(false) {} : test_safe_browsing_service_(nullptr), use_v4_local_db_manager_(false) {}
......
...@@ -95,6 +95,8 @@ class TestSafeBrowsingService : public SafeBrowsingService, ...@@ -95,6 +95,8 @@ class TestSafeBrowsingService : public SafeBrowsingService,
ResourceRequestDetector* CreateResourceRequestDetector() override; ResourceRequestDetector* CreateResourceRequestDetector() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override; scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory(
Profile* profile) override;
private: private:
std::unique_ptr<V4ProtocolConfig> v4_protocol_config_; std::unique_ptr<V4ProtocolConfig> v4_protocol_config_;
......
...@@ -6177,6 +6177,24 @@ ...@@ -6177,6 +6177,24 @@
] ]
} }
], ],
"SafeBrowsingNetworkContexts": [
{
"platforms": [
"windows",
"linux",
"mac"
],
"experiments": [
{
"name": "Enabled",
"enable_features": [
"SafeBrowsingRemoveCookies",
"SafeBrowsingSeparateNetworkContexts"
]
}
]
}
],
"SafeBrowsingPasswordProtectionForSavedPasswords": [ "SafeBrowsingPasswordProtectionForSavedPasswords": [
{ {
"platforms": [ "platforms": [
......
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