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

Prepare V4 database for per-profile Safe Browsing NetworkContexts

This CL finishes preparing the V4 database code for the upcoming split
of Safe Browsing NetworkContexts by profile. It starts using the
browser-wide network contexts for all requests, and removes cookies from
the V4UpdateProtocolManager.

Bug: 1049833
Change-Id: I3f1c9819846ed35497a8c0d3ec32a8254c92fa0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365296
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800323}
parent e9afac10
......@@ -12,6 +12,7 @@
#include "chrome/browser/safe_browsing/telemetry/telemetry_service.h"
#include "components/safe_browsing/android/remote_database_manager.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/features.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
......@@ -84,9 +85,14 @@ void ServicesDelegateAndroid::AddDownloadManager(
content::DownloadManager* download_manager) {}
void ServicesDelegateAndroid::StartOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> sb_url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> browser_url_loader_factory,
const V4ProtocolConfig& v4_config) {
database_manager_->StartOnIOThread(url_loader_factory, v4_config);
if (base::FeatureList::IsEnabled(kSafeBrowsingRemoveCookies)) {
database_manager_->StartOnIOThread(browser_url_loader_factory, v4_config);
} else {
database_manager_->StartOnIOThread(sb_url_loader_factory, v4_config);
}
}
void ServicesDelegateAndroid::StopOnIOThread(bool shutdown) {
......
......@@ -37,7 +37,8 @@ class ServicesDelegateAndroid : public ServicesDelegate {
void AddDownloadManager(content::DownloadManager* download_manager) override;
void StartOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> sb_url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> browser_url_loader_factory,
const V4ProtocolConfig& v4_config) override;
void StopOnIOThread(bool shutdown) override;
......
......@@ -297,7 +297,9 @@ void SafeBrowsingService::SetDatabaseManagerForTest(
void SafeBrowsingService::StartOnIOThread(
std::unique_ptr<network::PendingSharedURLLoaderFactory>
url_loader_factory) {
sb_url_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
browser_url_loader_factory) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (enabled_)
return;
......@@ -307,7 +309,9 @@ void SafeBrowsingService::StartOnIOThread(
V4ProtocolConfig v4_config = GetV4ProtocolConfig();
services_delegate_->StartOnIOThread(
network::SharedURLLoaderFactory::Create(std::move(url_loader_factory)),
network::SharedURLLoaderFactory::Create(std::move(sb_url_loader_factory)),
network::SharedURLLoaderFactory::Create(
std::move(browser_url_loader_factory)),
v4_config);
}
......@@ -331,7 +335,9 @@ void SafeBrowsingService::Start() {
base::BindOnce(
&SafeBrowsingService::StartOnIOThread, this,
std::make_unique<network::CrossThreadPendingSharedURLLoaderFactory>(
GetURLLoaderFactory())));
GetURLLoaderFactory()),
std::make_unique<network::CrossThreadPendingSharedURLLoaderFactory>(
g_browser_process->shared_url_loader_factory())));
}
void SafeBrowsingService::Stop(bool shutdown) {
......
......@@ -223,10 +223,16 @@ class SafeBrowsingService : public SafeBrowsingServiceInterface,
void SetDatabaseManagerForTest(SafeBrowsingDatabaseManager* database_manager);
// Called to initialize objects that are used on the io_thread. This may be
// Called to initialize objects that are used on the io_thread. This may be
// called multiple times during the life of the SafeBrowsingService.
// |sb_url_loader_factory| is a SharedURLLoaderFactory attached to the Safe
// Browsing NetworkContexts, and |browser_url_loader_factory| is attached to
// the global browser process.
// TODO(crbug.com/1049833): Remove the sb_url_loader_factory here.
void StartOnIOThread(std::unique_ptr<network::PendingSharedURLLoaderFactory>
url_loader_factory);
sb_url_loader_factory,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
browser_url_loader_factory);
// Called to stop or shutdown operations on the io_thread. This may be called
// multiple times to stop during the life of the SafeBrowsingService. If
......
......@@ -118,8 +118,12 @@ class ServicesDelegate {
#if !defined(OS_ANDROID)
virtual DownloadProtectionService* GetDownloadService() = 0;
#endif
// Takes a SharedURLLoaderFactory with the Safe Browsing NetworkContext and
// one from the BrowserProcess.
virtual void StartOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> sb_url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> browser_url_loader_factory,
const V4ProtocolConfig& v4_config) = 0;
virtual void StopOnIOThread(bool shutdown) = 0;
......
......@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
......@@ -18,6 +19,7 @@
#include "components/keyed_service/core/service_access_type.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/db/v4_local_database_manager.h"
#include "components/safe_browsing/core/features.h"
#include "components/safe_browsing/core/verdict_cache_manager.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......@@ -168,9 +170,14 @@ ServicesDelegateDesktop::CreateResourceRequestDetector() {
}
void ServicesDelegateDesktop::StartOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> sb_url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> browser_url_loader_factory,
const V4ProtocolConfig& v4_config) {
database_manager_->StartOnIOThread(url_loader_factory, v4_config);
if (base::FeatureList::IsEnabled(kSafeBrowsingRemoveCookies)) {
database_manager_->StartOnIOThread(browser_url_loader_factory, v4_config);
} else {
database_manager_->StartOnIOThread(sb_url_loader_factory, v4_config);
}
}
void ServicesDelegateDesktop::StopOnIOThread(bool shutdown) {
......
......@@ -45,7 +45,8 @@ class ServicesDelegateDesktop : public ServicesDelegate {
DownloadProtectionService* GetDownloadService() override;
void StartOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> sb_url_loader_factory,
scoped_refptr<network::SharedURLLoaderFactory> browser_url_loader_factory,
const V4ProtocolConfig& v4_config) override;
void StopOnIOThread(bool shutdown) override;
......
......@@ -261,6 +261,7 @@ static_library("v4_update_protocol_manager") {
":v4_protocol_manager_util",
"//base",
"//components/safe_browsing:buildflags",
"//components/safe_browsing/core:features",
"//components/safe_browsing/core/:webui_proto",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//net",
......
......@@ -340,10 +340,8 @@ void V4GetHashProtocolManager::GetFullHashes(
&resource_request->headers);
resource_request->load_flags = net::LOAD_DISABLE_CACHE;
if (base::FeatureList::IsEnabled(kSafeBrowsingRemoveCookies)) {
resource_request->load_flags |=
net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES;
}
if (base::FeatureList::IsEnabled(kSafeBrowsingRemoveCookies))
resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit;
std::unique_ptr<network::SimpleURLLoader> owned_loader =
network::SimpleURLLoader::Create(std::move(resource_request),
traffic_annotation);
......
......@@ -15,6 +15,7 @@
#include "base/timer/timer.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/db/safebrowsing.pb.h"
#include "components/safe_browsing/core/features.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
......@@ -343,6 +344,8 @@ void V4UpdateProtocolManager::IssueUpdateRequest() {
GetUpdateUrlAndHeaders(req_base64, &resource_request->url,
&resource_request->headers);
resource_request->load_flags = net::LOAD_DISABLE_CACHE;
if (base::FeatureList::IsEnabled(kSafeBrowsingRemoveCookies))
resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit;
std::unique_ptr<network::SimpleURLLoader> loader =
network::SimpleURLLoader::Create(std::move(resource_request),
traffic_annotation);
......
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