Commit 10f6e211 authored by Ali Juma's avatar Ali Juma Committed by Commit Bot

Remove direct usage of BrowserThread from components/safe_browsing/core

This is a follow-up to http://crrev/c/1992353, using the utility functions
added in that CL to replace direct usage of BrowserThread everywhere in
components/safe_browsing/core.

This is a step towards removing dependencies on content/ from
components/safe_browsing/core.

Change-Id: Ieafd8c27c40b3c57374596f17d8c777d38b13247
Bug: 1028755
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1999334Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Ali Juma <ajuma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732406}
parent 26e5d986
...@@ -98,8 +98,8 @@ if (!is_ios) { ...@@ -98,8 +98,8 @@ if (!is_ios) {
"//components/content_settings/core/browser", "//components/content_settings/core/browser",
"//components/history/core/browser", "//components/history/core/browser",
"//components/password_manager/core/browser:browser", "//components/password_manager/core/browser:browser",
"//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",
"//content/public/browser",
"//url", "//url",
] ]
} }
......
...@@ -18,13 +18,14 @@ jumbo_source_set("browser") { ...@@ -18,13 +18,14 @@ jumbo_source_set("browser") {
"//components/safe_browsing/core:csd_proto", "//components/safe_browsing/core:csd_proto",
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core:realtimeapi_proto", "//components/safe_browsing/core:realtimeapi_proto",
"//components/safe_browsing/core:verdict_cache_manager",
"//components/safe_browsing/core/browser:network_context", "//components/safe_browsing/core/browser:network_context",
"//components/safe_browsing/core/browser:referrer_chain_provider", "//components/safe_browsing/core/browser:referrer_chain_provider",
"//components/safe_browsing/core/common:common", "//components/safe_browsing/core/common:common",
"//components/safe_browsing/core/common:thread_utils",
"//components/safe_browsing/core/db:database_manager", "//components/safe_browsing/core/db:database_manager",
"//components/safe_browsing/core/realtime:policy_engine", "//components/safe_browsing/core/realtime:policy_engine",
"//components/safe_browsing/core/realtime:url_lookup_service", "//components/safe_browsing/core/realtime:url_lookup_service",
"//components/safe_browsing/core:verdict_cache_manager",
"//components/safe_browsing/core/web_ui:constants", "//components/safe_browsing/core/web_ui:constants",
"//components/security_interstitials/content:security_interstitial_page", "//components/security_interstitials/content:security_interstitial_page",
"//content/public/browser:browser", "//content/public/browser:browser",
...@@ -40,15 +41,14 @@ source_set("network_context") { ...@@ -40,15 +41,14 @@ source_set("network_context") {
deps = [ deps = [
"//components/safe_browsing/core/common:common", "//components/safe_browsing/core/common:common",
"//components/safe_browsing/core/common:thread_utils",
"//content/public/browser:browser", "//content/public/browser:browser",
"//net:extras", "//net:extras",
] ]
} }
source_set("referrer_chain_provider") { source_set("referrer_chain_provider") {
sources = [ sources = [ "referrer_chain_provider.h" ]
"referrer_chain_provider.h",
]
deps = [ deps = [
"//components/safe_browsing/core:csd_proto", "//components/safe_browsing/core:csd_proto",
"//components/sessions", "//components/sessions",
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/safe_browsing/core/common/safebrowsing_constants.h" #include "components/safe_browsing/core/common/safebrowsing_constants.h"
#include "content/public/browser/browser_task_traits.h" #include "components/safe_browsing/core/common/thread_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_context_client_base.h" #include "content/public/browser/network_context_client_base.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
...@@ -36,13 +35,13 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory ...@@ -36,13 +35,13 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory
std::move(network_context_params_factory)) {} std::move(network_context_params_factory)) {}
void Reset() { void Reset() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
url_loader_factory_.reset(); url_loader_factory_.reset();
network_context_.reset(); network_context_.reset();
} }
network::mojom::NetworkContext* GetNetworkContext() { network::mojom::NetworkContext* GetNetworkContext() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
if (!network_context_ || !network_context_.is_connected()) { if (!network_context_ || !network_context_.is_connected()) {
network_context_.reset(); network_context_.reset();
content::GetNetworkService()->CreateNetworkContext( content::GetNetworkService()->CreateNetworkContext(
...@@ -76,7 +75,7 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory ...@@ -76,7 +75,7 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory
mojo::PendingRemote<network::mojom::URLLoaderClient> client, mojo::PendingRemote<network::mojom::URLLoaderClient> client,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
override { override {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
GetURLLoaderFactory()->CreateLoaderAndStart( GetURLLoaderFactory()->CreateLoaderAndStart(
std::move(loader), routing_id, request_id, options, request, std::move(loader), routing_id, request_id, options, request,
std::move(client), traffic_annotation); std::move(client), traffic_annotation);
...@@ -94,7 +93,7 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory ...@@ -94,7 +93,7 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory
} }
network::mojom::URLLoaderFactory* GetURLLoaderFactory() { network::mojom::URLLoaderFactory* GetURLLoaderFactory() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
if (!url_loader_factory_ || !url_loader_factory_.is_connected()) { if (!url_loader_factory_ || !url_loader_factory_.is_connected()) {
url_loader_factory_.reset(); url_loader_factory_.reset();
network::mojom::URLLoaderFactoryParamsPtr params = network::mojom::URLLoaderFactoryParamsPtr params =
...@@ -113,7 +112,7 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory ...@@ -113,7 +112,7 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory
~SharedURLLoaderFactory() override = default; ~SharedURLLoaderFactory() override = default;
network::mojom::NetworkContextParamsPtr CreateNetworkContextParams() { network::mojom::NetworkContextParamsPtr CreateNetworkContextParams() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
network::mojom::NetworkContextParamsPtr network_context_params = network::mojom::NetworkContextParamsPtr network_context_params =
network_context_params_factory_.Run(); network_context_params_factory_.Run();
...@@ -145,29 +144,29 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory ...@@ -145,29 +144,29 @@ class SafeBrowsingNetworkContext::SharedURLLoaderFactory
SafeBrowsingNetworkContext::SafeBrowsingNetworkContext( SafeBrowsingNetworkContext::SafeBrowsingNetworkContext(
const base::FilePath& user_data_dir, const base::FilePath& user_data_dir,
NetworkContextParamsFactory network_context_params_factory) { NetworkContextParamsFactory network_context_params_factory) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
url_loader_factory_ = base::MakeRefCounted<SharedURLLoaderFactory>( url_loader_factory_ = base::MakeRefCounted<SharedURLLoaderFactory>(
user_data_dir, std::move(network_context_params_factory)); user_data_dir, std::move(network_context_params_factory));
} }
SafeBrowsingNetworkContext::~SafeBrowsingNetworkContext() { SafeBrowsingNetworkContext::~SafeBrowsingNetworkContext() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
} }
scoped_refptr<network::SharedURLLoaderFactory> scoped_refptr<network::SharedURLLoaderFactory>
SafeBrowsingNetworkContext::GetURLLoaderFactory() { SafeBrowsingNetworkContext::GetURLLoaderFactory() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
return url_loader_factory_; return url_loader_factory_;
} }
network::mojom::NetworkContext* network::mojom::NetworkContext*
SafeBrowsingNetworkContext::GetNetworkContext() { SafeBrowsingNetworkContext::GetNetworkContext() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
return url_loader_factory_->GetNetworkContext(); return url_loader_factory_->GetNetworkContext();
} }
void SafeBrowsingNetworkContext::FlushForTesting() { void SafeBrowsingNetworkContext::FlushForTesting() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
url_loader_factory_->FlushForTesting(); url_loader_factory_->FlushForTesting();
} }
......
...@@ -12,13 +12,12 @@ ...@@ -12,13 +12,12 @@
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "components/safe_browsing/content/web_ui/safe_browsing_ui.h" #include "components/safe_browsing/content/web_ui/safe_browsing_ui.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/thread_utils.h"
#include "components/safe_browsing/core/realtime/policy_engine.h" #include "components/safe_browsing/core/realtime/policy_engine.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"
#include "components/safe_browsing/core/web_ui/constants.h" #include "components/safe_browsing/core/web_ui/constants.h"
#include "components/security_interstitials/content/unsafe_resource.h" #include "components/security_interstitials/content/unsafe_resource.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -116,7 +115,7 @@ SafeBrowsingUrlCheckerImpl::SafeBrowsingUrlCheckerImpl( ...@@ -116,7 +115,7 @@ SafeBrowsingUrlCheckerImpl::SafeBrowsingUrlCheckerImpl(
cache_manager_on_ui_(cache_manager_on_ui) {} cache_manager_on_ui_(cache_manager_on_ui) {}
SafeBrowsingUrlCheckerImpl::~SafeBrowsingUrlCheckerImpl() { SafeBrowsingUrlCheckerImpl::~SafeBrowsingUrlCheckerImpl() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
if (state_ == STATE_CHECKING_URL) { if (state_ == STATE_CHECKING_URL) {
database_manager_->CancelCheck(this); database_manager_->CancelCheck(this);
...@@ -207,7 +206,7 @@ void SafeBrowsingUrlCheckerImpl::OnUrlResult(const GURL& url, ...@@ -207,7 +206,7 @@ void SafeBrowsingUrlCheckerImpl::OnUrlResult(const GURL& url,
base::BindRepeating(&SafeBrowsingUrlCheckerImpl::OnBlockingPageComplete, base::BindRepeating(&SafeBrowsingUrlCheckerImpl::OnBlockingPageComplete,
weak_factory_.GetWeakPtr()); weak_factory_.GetWeakPtr());
resource.callback_thread = resource.callback_thread =
base::CreateSingleThreadTaskRunner({content::BrowserThread::IO}); base::CreateSingleThreadTaskRunner(CreateTaskTraits(ThreadID::IO));
resource.web_contents_getter = web_contents_getter_; resource.web_contents_getter = web_contents_getter_;
resource.threat_source = database_manager_->GetThreatSource(); resource.threat_source = database_manager_->GetThreatSource();
...@@ -232,7 +231,7 @@ void SafeBrowsingUrlCheckerImpl::OnTimeout() { ...@@ -232,7 +231,7 @@ void SafeBrowsingUrlCheckerImpl::OnTimeout() {
void SafeBrowsingUrlCheckerImpl::CheckUrlImpl(const GURL& url, void SafeBrowsingUrlCheckerImpl::CheckUrlImpl(const GURL& url,
const std::string& method, const std::string& method,
Notifier notifier) { Notifier notifier) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DVLOG(1) << "SafeBrowsingUrlCheckerImpl checks URL: " << url; DVLOG(1) << "SafeBrowsingUrlCheckerImpl checks URL: " << url;
urls_.emplace_back(url, method, std::move(notifier)); urls_.emplace_back(url, method, std::move(notifier));
...@@ -241,7 +240,7 @@ void SafeBrowsingUrlCheckerImpl::CheckUrlImpl(const GURL& url, ...@@ -241,7 +240,7 @@ void SafeBrowsingUrlCheckerImpl::CheckUrlImpl(const GURL& url,
} }
void SafeBrowsingUrlCheckerImpl::ProcessUrls() { void SafeBrowsingUrlCheckerImpl::ProcessUrls() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK_NE(STATE_BLOCKED, state_); DCHECK_NE(STATE_BLOCKED, state_);
if (state_ == STATE_CHECKING_URL || if (state_ == STATE_CHECKING_URL ||
...@@ -286,7 +285,7 @@ void SafeBrowsingUrlCheckerImpl::ProcessUrls() { ...@@ -286,7 +285,7 @@ void SafeBrowsingUrlCheckerImpl::ProcessUrls() {
url.spec()); url.spec());
base::PostTask( base::PostTask(
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, CreateTaskTraits(ThreadID::IO),
base::BindOnce(&SafeBrowsingUrlCheckerImpl::OnCheckBrowseUrlResult, base::BindOnce(&SafeBrowsingUrlCheckerImpl::OnCheckBrowseUrlResult,
weak_factory_.GetWeakPtr(), url, threat_type, weak_factory_.GetWeakPtr(), url, threat_type,
ThreatMetadata())); ThreatMetadata()));
...@@ -319,7 +318,7 @@ void SafeBrowsingUrlCheckerImpl::ProcessUrls() { ...@@ -319,7 +318,7 @@ void SafeBrowsingUrlCheckerImpl::ProcessUrls() {
// |OnCheckUrlForHighConfidenceAllowlist| to trigger the hash-based // |OnCheckUrlForHighConfidenceAllowlist| to trigger the hash-based
// checking. // checking.
base::PostTask( base::PostTask(
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, CreateTaskTraits(ThreadID::IO),
base::BindOnce(&SafeBrowsingUrlCheckerImpl:: base::BindOnce(&SafeBrowsingUrlCheckerImpl::
OnCheckUrlForHighConfidenceAllowlist, OnCheckUrlForHighConfidenceAllowlist,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
...@@ -330,7 +329,7 @@ void SafeBrowsingUrlCheckerImpl::ProcessUrls() { ...@@ -330,7 +329,7 @@ void SafeBrowsingUrlCheckerImpl::ProcessUrls() {
// |OnCheckUrlForHighConfidenceAllowlist| to perform the full URL // |OnCheckUrlForHighConfidenceAllowlist| to perform the full URL
// lookup. // lookup.
base::PostTask( base::PostTask(
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, CreateTaskTraits(ThreadID::IO),
base::BindOnce(&SafeBrowsingUrlCheckerImpl:: base::BindOnce(&SafeBrowsingUrlCheckerImpl::
OnCheckUrlForHighConfidenceAllowlist, OnCheckUrlForHighConfidenceAllowlist,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
...@@ -433,7 +432,7 @@ bool SafeBrowsingUrlCheckerImpl::RunNextCallback(bool proceed, ...@@ -433,7 +432,7 @@ bool SafeBrowsingUrlCheckerImpl::RunNextCallback(bool proceed,
void SafeBrowsingUrlCheckerImpl::OnCheckUrlForHighConfidenceAllowlist( void SafeBrowsingUrlCheckerImpl::OnCheckUrlForHighConfidenceAllowlist(
bool did_match_allowlist) { bool did_match_allowlist) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK_EQ(content::ResourceType::kMainFrame, resource_type_); DCHECK_EQ(content::ResourceType::kMainFrame, resource_type_);
const GURL& url = urls_[next_index_].url; const GURL& url = urls_[next_index_].url;
...@@ -450,7 +449,7 @@ void SafeBrowsingUrlCheckerImpl::OnCheckUrlForHighConfidenceAllowlist( ...@@ -450,7 +449,7 @@ void SafeBrowsingUrlCheckerImpl::OnCheckUrlForHighConfidenceAllowlist(
} }
base::PostTask( base::PostTask(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce( base::BindOnce(
&SafeBrowsingUrlCheckerImpl::StartGetCachedRealTimeUrlVerdictOnUI, &SafeBrowsingUrlCheckerImpl::StartGetCachedRealTimeUrlVerdictOnUI,
weak_factory_.GetWeakPtr(), cache_manager_on_ui_, url, weak_factory_.GetWeakPtr(), cache_manager_on_ui_, url,
...@@ -463,7 +462,7 @@ void SafeBrowsingUrlCheckerImpl::StartGetCachedRealTimeUrlVerdictOnUI( ...@@ -463,7 +462,7 @@ void SafeBrowsingUrlCheckerImpl::StartGetCachedRealTimeUrlVerdictOnUI(
base::WeakPtr<VerdictCacheManager> cache_manager_on_ui, base::WeakPtr<VerdictCacheManager> cache_manager_on_ui,
const GURL& url, const GURL& url,
base::TimeTicks get_cache_start_time) { base::TimeTicks get_cache_start_time) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
std::unique_ptr<RTLookupResponse::ThreatInfo> cached_threat_info = std::unique_ptr<RTLookupResponse::ThreatInfo> cached_threat_info =
std::make_unique<RTLookupResponse::ThreatInfo>(); std::make_unique<RTLookupResponse::ThreatInfo>();
...@@ -477,7 +476,7 @@ void SafeBrowsingUrlCheckerImpl::StartGetCachedRealTimeUrlVerdictOnUI( ...@@ -477,7 +476,7 @@ void SafeBrowsingUrlCheckerImpl::StartGetCachedRealTimeUrlVerdictOnUI(
url, cached_threat_info.get()) url, cached_threat_info.get())
: RTLookupResponse::ThreatInfo::VERDICT_TYPE_UNSPECIFIED; : RTLookupResponse::ThreatInfo::VERDICT_TYPE_UNSPECIFIED;
base::PostTask( base::PostTask(
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, CreateTaskTraits(ThreadID::IO),
base::BindOnce( base::BindOnce(
&SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO, &SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO,
weak_checker_on_io, verdict_type, std::move(cached_threat_info), url, weak_checker_on_io, verdict_type, std::move(cached_threat_info), url,
...@@ -489,7 +488,7 @@ void SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO( ...@@ -489,7 +488,7 @@ void SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO(
std::unique_ptr<RTLookupResponse::ThreatInfo> cached_threat_info, std::unique_ptr<RTLookupResponse::ThreatInfo> cached_threat_info,
const GURL& url, const GURL& url,
base::TimeTicks get_cache_start_time) { base::TimeTicks get_cache_start_time) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
base::UmaHistogramSparse("SafeBrowsing.RT.GetCacheResult", verdict_type); base::UmaHistogramSparse("SafeBrowsing.RT.GetCacheResult", verdict_type);
UMA_HISTOGRAM_TIMES("SafeBrowsing.RT.GetCache.Time", UMA_HISTOGRAM_TIMES("SafeBrowsing.RT.GetCache.Time",
...@@ -521,12 +520,12 @@ void SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO( ...@@ -521,12 +520,12 @@ void SafeBrowsingUrlCheckerImpl::OnGetCachedRealTimeUrlVerdictDoneOnIO(
void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest( void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest(
std::unique_ptr<RTLookupRequest> request) { std::unique_ptr<RTLookupRequest> request) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// The following is to log this RTLookupRequest on any open // The following is to log this RTLookupRequest on any open
// chrome://safe-browsing pages. // chrome://safe-browsing pages.
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&WebUIInfoSingleton::AddToRTLookupPings, base::BindOnce(&WebUIInfoSingleton::AddToRTLookupPings,
base::Unretained(WebUIInfoSingleton::GetInstance()), base::Unretained(WebUIInfoSingleton::GetInstance()),
*request), *request),
...@@ -536,14 +535,14 @@ void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest( ...@@ -536,14 +535,14 @@ void SafeBrowsingUrlCheckerImpl::OnRTLookupRequest(
void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse( void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse(
std::unique_ptr<RTLookupResponse> response) { std::unique_ptr<RTLookupResponse> response) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK_EQ(content::ResourceType::kMainFrame, resource_type_); DCHECK_EQ(content::ResourceType::kMainFrame, resource_type_);
if (url_web_ui_token_ != -1) { if (url_web_ui_token_ != -1) {
// The following is to log this RTLookupResponse on any open // The following is to log this RTLookupResponse on any open
// chrome://safe-browsing pages. // chrome://safe-browsing pages.
base::PostTask( base::PostTask(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&WebUIInfoSingleton::AddToRTLookupResponses, base::BindOnce(&WebUIInfoSingleton::AddToRTLookupResponses,
base::Unretained(WebUIInfoSingleton::GetInstance()), base::Unretained(WebUIInfoSingleton::GetInstance()),
url_web_ui_token_, *response)); url_web_ui_token_, *response));
...@@ -553,7 +552,7 @@ void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse( ...@@ -553,7 +552,7 @@ void SafeBrowsingUrlCheckerImpl::OnRTLookupResponse(
SBThreatType sb_threat_type = SB_THREAT_TYPE_SAFE; SBThreatType sb_threat_type = SB_THREAT_TYPE_SAFE;
if (response && (response->threat_info_size() > 0)) { if (response && (response->threat_info_size() > 0)) {
base::PostTask(FROM_HERE, {content::BrowserThread::UI}, base::PostTask(FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindOnce(&VerdictCacheManager::CacheRealTimeUrlVerdict, base::BindOnce(&VerdictCacheManager::CacheRealTimeUrlVerdict,
cache_manager_on_ui_, url, *response, cache_manager_on_ui_, url, *response,
base::Time::Now())); base::Time::Now()));
......
...@@ -44,7 +44,7 @@ if (!is_ios) { ...@@ -44,7 +44,7 @@ if (!is_ios) {
"//components/pref_registry:pref_registry", "//components/pref_registry:pref_registry",
"//components/prefs", "//components/prefs",
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//content/public/browser:browser", "//components/safe_browsing/core/common:thread_utils",
"//net:net", "//net:net",
] ]
} }
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/thread_utils.h"
#include "components/safe_browsing/core/features.h" #include "components/safe_browsing/core/features.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/url_canon.h" #include "url/url_canon.h"
...@@ -328,7 +328,7 @@ void CanonicalizeDomainList( ...@@ -328,7 +328,7 @@ void CanonicalizeDomainList(
bool IsURLWhitelistedByPolicy(const GURL& url, bool IsURLWhitelistedByPolicy(const GURL& url,
StringListPrefMember* pref_member) { StringListPrefMember* pref_member) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
if (!pref_member) if (!pref_member)
return false; return false;
...@@ -340,7 +340,7 @@ bool IsURLWhitelistedByPolicy(const GURL& url, ...@@ -340,7 +340,7 @@ bool IsURLWhitelistedByPolicy(const GURL& url,
} }
bool IsURLWhitelistedByPolicy(const GURL& url, const PrefService& pref) { bool IsURLWhitelistedByPolicy(const GURL& url, const PrefService& pref) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
if (!pref.HasPrefPath(prefs::kSafeBrowsingWhitelistDomains)) if (!pref.HasPrefPath(prefs::kSafeBrowsingWhitelistDomains))
return false; return false;
const base::ListValue* whitelist = const base::ListValue* whitelist =
......
...@@ -48,8 +48,9 @@ static_library("database_manager") { ...@@ -48,8 +48,9 @@ static_library("database_manager") {
":v4_get_hash_protocol_manager", ":v4_get_hash_protocol_manager",
":v4_protocol_manager_util", ":v4_protocol_manager_util",
"//base", "//base",
"//content/public/browser", "//components/safe_browsing/core/common:thread_utils",
"//net", "//net",
"//services/network/public/cpp",
"//url", "//url",
] ]
...@@ -117,7 +118,7 @@ static_library("v4_database") { ...@@ -117,7 +118,7 @@ static_library("v4_database") {
":v4_store", ":v4_store",
"//base", "//base",
"//components/safe_browsing/core:webui_proto", "//components/safe_browsing/core:webui_proto",
"//content/public/browser", "//components/safe_browsing/core/common:thread_utils",
] ]
} }
...@@ -132,8 +133,9 @@ static_library("v4_get_hash_protocol_manager") { ...@@ -132,8 +133,9 @@ static_library("v4_get_hash_protocol_manager") {
":v4_protocol_manager_util", ":v4_protocol_manager_util",
"//base", "//base",
"//components/safe_browsing/core:webui_proto", "//components/safe_browsing/core:webui_proto",
"//content/public/browser", "//components/safe_browsing/core/common:thread_utils",
"//net", "//net",
"//services/network/public/cpp:cpp",
"//url", "//url",
] ]
} }
...@@ -285,7 +287,6 @@ source_set("unit_tests_shared") { ...@@ -285,7 +287,6 @@ source_set("unit_tests_shared") {
":v4_test_util", ":v4_test_util",
"//base", "//base",
"//components/safe_browsing/core/common:test_support", "//components/safe_browsing/core/common:test_support",
"//content/public/browser",
"//net", "//net",
"//net:test_support", "//net:test_support",
"//services/network:test_support", "//services/network:test_support",
...@@ -345,7 +346,7 @@ static_library("allowlist_checker_client") { ...@@ -345,7 +346,7 @@ static_library("allowlist_checker_client") {
deps = [ deps = [
":database_manager", ":database_manager",
"//base:base", "//base:base",
"//content/public/browser", "//components/safe_browsing/core/common:thread_utils",
"//url:url", "//url:url",
] ]
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include "base/bind.h" #include "base/bind.h"
#include "content/public/browser/browser_thread.h" #include "components/safe_browsing/core/common/thread_utils.h"
namespace safe_browsing { namespace safe_browsing {
...@@ -23,7 +23,7 @@ void AllowlistCheckerClient::StartCheckCsdWhitelist( ...@@ -23,7 +23,7 @@ void AllowlistCheckerClient::StartCheckCsdWhitelist(
scoped_refptr<SafeBrowsingDatabaseManager> database_manager, scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
const GURL& url, const GURL& url,
base::OnceCallback<void(bool)> callback_for_result) { base::OnceCallback<void(bool)> callback_for_result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// On timeout or if the list is unavailable, report match. // On timeout or if the list is unavailable, report match.
const bool kDefaultDoesMatchAllowlist = true; const bool kDefaultDoesMatchAllowlist = true;
...@@ -44,7 +44,7 @@ void AllowlistCheckerClient::StartCheckHighConfidenceAllowlist( ...@@ -44,7 +44,7 @@ void AllowlistCheckerClient::StartCheckHighConfidenceAllowlist(
scoped_refptr<SafeBrowsingDatabaseManager> database_manager, scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
const GURL& url, const GURL& url,
base::OnceCallback<void(bool)> callback_for_result) { base::OnceCallback<void(bool)> callback_for_result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// On timeout or if the list is unavailable, report no match. // On timeout or if the list is unavailable, report no match.
const bool kDefaultDoesMatchAllowlist = false; const bool kDefaultDoesMatchAllowlist = false;
...@@ -108,7 +108,7 @@ AllowlistCheckerClient::AllowlistCheckerClient( ...@@ -108,7 +108,7 @@ AllowlistCheckerClient::AllowlistCheckerClient(
: callback_for_result_(std::move(callback_for_result)), : callback_for_result_(std::move(callback_for_result)),
database_manager_(database_manager), database_manager_(database_manager),
default_does_match_allowlist_(default_does_match_allowlist) { default_does_match_allowlist_(default_does_match_allowlist) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// Set a timer to fail open, i.e. call it "whitelisted", if the full // Set a timer to fail open, i.e. call it "whitelisted", if the full
// check takes too long. // check takes too long.
...@@ -119,7 +119,7 @@ AllowlistCheckerClient::AllowlistCheckerClient( ...@@ -119,7 +119,7 @@ AllowlistCheckerClient::AllowlistCheckerClient(
} }
AllowlistCheckerClient::~AllowlistCheckerClient() { AllowlistCheckerClient::~AllowlistCheckerClient() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
} }
// SafeBrowsingDatabaseMananger::Client impl // SafeBrowsingDatabaseMananger::Client impl
...@@ -134,7 +134,7 @@ void AllowlistCheckerClient::OnCheckUrlForHighConfidenceAllowlist( ...@@ -134,7 +134,7 @@ void AllowlistCheckerClient::OnCheckUrlForHighConfidenceAllowlist(
} }
void AllowlistCheckerClient::OnCheckUrlResult(bool did_match_allowlist) { void AllowlistCheckerClient::OnCheckUrlResult(bool did_match_allowlist) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
timer_.Stop(); timer_.Stop();
// The callback can only be invoked by other code paths if this object is not // The callback can only be invoked by other code paths if this object is not
...@@ -147,7 +147,7 @@ void AllowlistCheckerClient::OnCheckUrlResult(bool did_match_allowlist) { ...@@ -147,7 +147,7 @@ void AllowlistCheckerClient::OnCheckUrlResult(bool did_match_allowlist) {
} }
void AllowlistCheckerClient::OnTimeout() { void AllowlistCheckerClient::OnTimeout() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
database_manager_->CancelCheck(this); database_manager_->CancelCheck(this);
OnCheckUrlResult(default_does_match_allowlist_); OnCheckUrlResult(default_does_match_allowlist_);
} }
......
...@@ -10,20 +10,17 @@ ...@@ -10,20 +10,17 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/safe_browsing/core/common/thread_utils.h"
#include "components/safe_browsing/core/db/v4_get_hash_protocol_manager.h" #include "components/safe_browsing/core/db/v4_get_hash_protocol_manager.h"
#include "components/safe_browsing/core/db/v4_protocol_manager_util.h" #include "components/safe_browsing/core/db/v4_protocol_manager_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "url/gurl.h" #include "url/gurl.h"
using content::BrowserThread;
namespace safe_browsing { namespace safe_browsing {
SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager() SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager()
: base::RefCountedDeleteOnSequence<SafeBrowsingDatabaseManager>( : base::RefCountedDeleteOnSequence<SafeBrowsingDatabaseManager>(
base::CreateSingleThreadTaskRunner({content::BrowserThread::IO})), base::CreateSingleThreadTaskRunner(CreateTaskTraits(ThreadID::IO))),
enabled_(false) {} enabled_(false) {}
SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
...@@ -31,7 +28,7 @@ SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { ...@@ -31,7 +28,7 @@ SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
} }
bool SafeBrowsingDatabaseManager::CancelApiCheck(Client* client) { bool SafeBrowsingDatabaseManager::CancelApiCheck(Client* client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
auto it = FindClientApiCheck(client); auto it = FindClientApiCheck(client);
if (it != api_checks_.end()) { if (it != api_checks_.end()) {
api_checks_.erase(it); api_checks_.erase(it);
...@@ -43,7 +40,7 @@ bool SafeBrowsingDatabaseManager::CancelApiCheck(Client* client) { ...@@ -43,7 +40,7 @@ bool SafeBrowsingDatabaseManager::CancelApiCheck(Client* client) {
bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url,
Client* client) { Client* client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK(v4_get_hash_protocol_manager_); DCHECK(v4_get_hash_protocol_manager_);
// Make sure we can check this url and that the service is enabled. // Make sure we can check this url and that the service is enabled.
...@@ -73,7 +70,7 @@ bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, ...@@ -73,7 +70,7 @@ bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url,
SafeBrowsingDatabaseManager::ApiCheckSet::iterator SafeBrowsingDatabaseManager::ApiCheckSet::iterator
SafeBrowsingDatabaseManager::FindClientApiCheck(Client* client) { SafeBrowsingDatabaseManager::FindClientApiCheck(Client* client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
for (auto it = api_checks_.begin(); it != api_checks_.end(); ++it) { for (auto it = api_checks_.begin(); it != api_checks_.end(); ++it) {
if ((*it)->client() == client) { if ((*it)->client() == client) {
return it; return it;
...@@ -101,7 +98,7 @@ std::unique_ptr<StoreStateMap> SafeBrowsingDatabaseManager::GetStoreStateMap() { ...@@ -101,7 +98,7 @@ std::unique_ptr<StoreStateMap> SafeBrowsingDatabaseManager::GetStoreStateMap() {
void SafeBrowsingDatabaseManager::OnThreatMetadataResponse( void SafeBrowsingDatabaseManager::OnThreatMetadataResponse(
std::unique_ptr<SafeBrowsingApiCheck> check, std::unique_ptr<SafeBrowsingApiCheck> check,
const ThreatMetadata& md) { const ThreatMetadata& md) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK(check); DCHECK(check);
// If the check is not in |api_checks_| then the request was cancelled by the // If the check is not in |api_checks_| then the request was cancelled by the
...@@ -117,7 +114,7 @@ void SafeBrowsingDatabaseManager::OnThreatMetadataResponse( ...@@ -117,7 +114,7 @@ void SafeBrowsingDatabaseManager::OnThreatMetadataResponse(
void SafeBrowsingDatabaseManager::StartOnIOThread( void SafeBrowsingDatabaseManager::StartOnIOThread(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const V4ProtocolConfig& config) { const V4ProtocolConfig& config) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create(
url_loader_factory, GetStoresForFullHashRequests(), config); url_loader_factory, GetStoresForFullHashRequests(), config);
...@@ -127,7 +124,7 @@ void SafeBrowsingDatabaseManager::StartOnIOThread( ...@@ -127,7 +124,7 @@ void SafeBrowsingDatabaseManager::StartOnIOThread(
// multiple times during the life of the DatabaseManager. // multiple times during the life of the DatabaseManager.
// Must be called on IO thread. // Must be called on IO thread.
void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// Delete pending checks, calling back any clients with empty metadata. // Delete pending checks, calling back any clients with empty metadata.
for (const SafeBrowsingApiCheck* check : api_checks_) { for (const SafeBrowsingApiCheck* check : api_checks_) {
...@@ -153,7 +150,7 @@ SafeBrowsingDatabaseManager::RegisterDatabaseUpdatedCallback( ...@@ -153,7 +150,7 @@ SafeBrowsingDatabaseManager::RegisterDatabaseUpdatedCallback(
} }
void SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished() { void SafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
update_complete_callback_list_.Notify(); update_complete_callback_list_.Notify();
} }
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/safe_browsing/core/common/thread_utils.h"
#include "components/safe_browsing/core/proto/webui.pb.h" #include "components/safe_browsing/core/proto/webui.pb.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
using base::TimeTicks; using base::TimeTicks;
namespace safe_browsing { namespace safe_browsing {
...@@ -137,7 +136,7 @@ V4Database::V4Database( ...@@ -137,7 +136,7 @@ V4Database::V4Database(
// static // static
void V4Database::Destroy(std::unique_ptr<V4Database> v4_database) { void V4Database::Destroy(std::unique_ptr<V4Database> v4_database) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
V4Database* v4_database_raw = v4_database.release(); V4Database* v4_database_raw = v4_database.release();
if (v4_database_raw) { if (v4_database_raw) {
v4_database_raw->weak_factory_on_io_.InvalidateWeakPtrs(); v4_database_raw->weak_factory_on_io_.InvalidateWeakPtrs();
...@@ -152,7 +151,7 @@ V4Database::~V4Database() { ...@@ -152,7 +151,7 @@ V4Database::~V4Database() {
void V4Database::ApplyUpdate( void V4Database::ApplyUpdate(
std::unique_ptr<ParsedServerResponse> parsed_server_response, std::unique_ptr<ParsedServerResponse> parsed_server_response,
DatabaseUpdatedCallback db_updated_callback) { DatabaseUpdatedCallback db_updated_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK(!pending_store_updates_); DCHECK(!pending_store_updates_);
DCHECK(db_updated_callback_.is_null()); DCHECK(db_updated_callback_.is_null());
...@@ -193,7 +192,7 @@ void V4Database::ApplyUpdate( ...@@ -193,7 +192,7 @@ void V4Database::ApplyUpdate(
void V4Database::UpdatedStoreReady(ListIdentifier identifier, void V4Database::UpdatedStoreReady(ListIdentifier identifier,
std::unique_ptr<V4Store> new_store) { std::unique_ptr<V4Store> new_store) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK(pending_store_updates_); DCHECK(pending_store_updates_);
if (new_store) { if (new_store) {
(*store_map_)[identifier].swap(new_store); (*store_map_)[identifier].swap(new_store);
...@@ -219,7 +218,7 @@ std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() { ...@@ -219,7 +218,7 @@ std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() {
bool V4Database::AreAnyStoresAvailable( bool V4Database::AreAnyStoresAvailable(
const StoresToCheck& stores_to_check) const { const StoresToCheck& stores_to_check) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
for (const ListIdentifier& identifier : stores_to_check) { for (const ListIdentifier& identifier : stores_to_check) {
if (IsStoreAvailable(identifier)) if (IsStoreAvailable(identifier))
return true; return true;
...@@ -229,7 +228,7 @@ bool V4Database::AreAnyStoresAvailable( ...@@ -229,7 +228,7 @@ bool V4Database::AreAnyStoresAvailable(
bool V4Database::AreAllStoresAvailable( bool V4Database::AreAllStoresAvailable(
const StoresToCheck& stores_to_check) const { const StoresToCheck& stores_to_check) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
for (const ListIdentifier& identifier : stores_to_check) { for (const ListIdentifier& identifier : stores_to_check) {
if (!IsStoreAvailable(identifier)) if (!IsStoreAvailable(identifier))
return false; return false;
...@@ -241,7 +240,7 @@ void V4Database::GetStoresMatchingFullHash( ...@@ -241,7 +240,7 @@ void V4Database::GetStoresMatchingFullHash(
const FullHash& full_hash, const FullHash& full_hash,
const StoresToCheck& stores_to_check, const StoresToCheck& stores_to_check,
StoreAndHashPrefixes* matched_store_and_hash_prefixes) { StoreAndHashPrefixes* matched_store_and_hash_prefixes) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
matched_store_and_hash_prefixes->clear(); matched_store_and_hash_prefixes->clear();
for (const ListIdentifier& identifier : stores_to_check) { for (const ListIdentifier& identifier : stores_to_check) {
if (!IsStoreAvailable(identifier)) if (!IsStoreAvailable(identifier))
...@@ -258,7 +257,7 @@ void V4Database::GetStoresMatchingFullHash( ...@@ -258,7 +257,7 @@ void V4Database::GetStoresMatchingFullHash(
void V4Database::ResetStores( void V4Database::ResetStores(
const std::vector<ListIdentifier>& stores_to_reset) { const std::vector<ListIdentifier>& stores_to_reset) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
for (const ListIdentifier& identifier : stores_to_reset) { for (const ListIdentifier& identifier : stores_to_reset) {
store_map_->at(identifier)->Reset(); store_map_->at(identifier)->Reset();
} }
...@@ -266,7 +265,7 @@ void V4Database::ResetStores( ...@@ -266,7 +265,7 @@ void V4Database::ResetStores(
void V4Database::VerifyChecksum( void V4Database::VerifyChecksum(
DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) { DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// Make a threadsafe copy of store_map_ w/raw pointers that we can hand to // Make a threadsafe copy of store_map_ w/raw pointers that we can hand to
// the DB thread. The V4Stores ptrs are guaranteed to be valid because their // the DB thread. The V4Stores ptrs are guaranteed to be valid because their
...@@ -288,7 +287,7 @@ void V4Database::VerifyChecksum( ...@@ -288,7 +287,7 @@ void V4Database::VerifyChecksum(
void V4Database::OnChecksumVerified( void V4Database::OnChecksumVerified(
DatabaseReadyForUpdatesCallback db_ready_for_updates_callback, DatabaseReadyForUpdatesCallback db_ready_for_updates_callback,
const std::vector<ListIdentifier>& stores_to_reset) { const std::vector<ListIdentifier>& stores_to_reset) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
std::move(db_ready_for_updates_callback).Run(stores_to_reset); std::move(db_ready_for_updates_callback).Run(stores_to_reset);
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h" #include "base/trace_event/traced_value.h"
#include "content/public/browser/browser_thread.h" #include "components/safe_browsing/core/common/thread_utils.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
using base::Time; using base::Time;
using base::TimeDelta; using base::TimeDelta;
using content::BrowserThread;
namespace { namespace {
...@@ -270,7 +269,7 @@ void V4GetHashProtocolManager::GetFullHashes( ...@@ -270,7 +269,7 @@ void V4GetHashProtocolManager::GetFullHashes(
full_hash_to_store_and_hash_prefixes, full_hash_to_store_and_hash_prefixes,
const std::vector<std::string>& list_client_states, const std::vector<std::string>& list_client_states,
FullHashCallback callback) { FullHashCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!full_hash_to_store_and_hash_prefixes.empty()); DCHECK(!full_hash_to_store_and_hash_prefixes.empty());
...@@ -361,7 +360,7 @@ void V4GetHashProtocolManager::GetFullHashesWithApis( ...@@ -361,7 +360,7 @@ void V4GetHashProtocolManager::GetFullHashesWithApis(
const GURL& url, const GURL& url,
const std::vector<std::string>& list_client_states, const std::vector<std::string>& list_client_states,
ThreatMetadataForApiCallback api_callback) { ThreatMetadataForApiCallback api_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme)); DCHECK(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme));
std::vector<FullHash> full_hashes; std::vector<FullHash> full_hashes;
...@@ -715,7 +714,7 @@ void V4GetHashProtocolManager::UpdateCache( ...@@ -715,7 +714,7 @@ void V4GetHashProtocolManager::UpdateCache(
const std::vector<HashPrefix>& prefixes_requested, const std::vector<HashPrefix>& prefixes_requested,
const std::vector<FullHashInfo>& full_hash_infos, const std::vector<FullHashInfo>& full_hash_infos,
const Time& negative_cache_expire) { const Time& negative_cache_expire) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
// If negative_cache_expire is null, don't cache the results since it's not // If negative_cache_expire is null, don't cache the results since it's not
// clear till what time they should be considered valid. // clear till what time they should be considered valid.
...@@ -771,7 +770,7 @@ void V4GetHashProtocolManager::OnURLLoaderComplete( ...@@ -771,7 +770,7 @@ void V4GetHashProtocolManager::OnURLLoaderComplete(
network::SimpleURLLoader* url_loader, network::SimpleURLLoader* url_loader,
std::unique_ptr<std::string> response_body) { std::unique_ptr<std::string> response_body) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
int response_code = 0; int response_code = 0;
if (url_loader->ResponseInfo() && url_loader->ResponseInfo()->headers) if (url_loader->ResponseInfo() && url_loader->ResponseInfo()->headers)
......
...@@ -31,8 +31,9 @@ static_library("url_lookup_service") { ...@@ -31,8 +31,9 @@ static_library("url_lookup_service") {
":policy_engine", ":policy_engine",
"//base:base", "//base:base",
"//components/safe_browsing/core:realtimeapi_proto", "//components/safe_browsing/core:realtimeapi_proto",
"//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",
"//content/public/browser", "//services/network/public/cpp:cpp",
"//url:url", "//url:url",
] ]
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/time/time.h" #include "base/time/time.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 "content/public/browser/browser_thread.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"
#include "net/base/url_util.h" #include "net/base/url_util.h"
...@@ -53,7 +53,7 @@ void RealTimeUrlLookupService::StartLookup( ...@@ -53,7 +53,7 @@ void RealTimeUrlLookupService::StartLookup(
const GURL& url, const GURL& url,
RTLookupRequestCallback request_callback, RTLookupRequestCallback request_callback,
RTLookupResponseCallback response_callback) { RTLookupResponseCallback response_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
DCHECK(url.is_valid()); DCHECK(url.is_valid());
std::unique_ptr<RTLookupRequest> request = FillRequestProto(url); std::unique_ptr<RTLookupRequest> request = FillRequestProto(url);
...@@ -129,7 +129,7 @@ void RealTimeUrlLookupService::OnURLLoaderComplete( ...@@ -129,7 +129,7 @@ void RealTimeUrlLookupService::OnURLLoaderComplete(
network::SimpleURLLoader* url_loader, network::SimpleURLLoader* url_loader,
base::TimeTicks request_start_time, base::TimeTicks request_start_time,
std::unique_ptr<std::string> response_body) { std::unique_ptr<std::string> response_body) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
auto it = pending_requests_.find(url_loader); auto it = pending_requests_.find(url_loader);
DCHECK(it != pending_requests_.end()) << "Request not found"; DCHECK(it != pending_requests_.end()) << "Request not found";
...@@ -184,7 +184,7 @@ std::unique_ptr<RTLookupRequest> RealTimeUrlLookupService::FillRequestProto( ...@@ -184,7 +184,7 @@ std::unique_ptr<RTLookupRequest> RealTimeUrlLookupService::FillRequestProto(
} }
size_t RealTimeUrlLookupService::GetBackoffDurationInSeconds() const { size_t RealTimeUrlLookupService::GetBackoffDurationInSeconds() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
return did_successful_lookup_since_last_backoff_ return did_successful_lookup_since_last_backoff_
? kMinBackOffResetDurationInSeconds ? kMinBackOffResetDurationInSeconds
: std::min(kMaxBackOffResetDurationInSeconds, : std::min(kMaxBackOffResetDurationInSeconds,
...@@ -192,7 +192,7 @@ size_t RealTimeUrlLookupService::GetBackoffDurationInSeconds() const { ...@@ -192,7 +192,7 @@ size_t RealTimeUrlLookupService::GetBackoffDurationInSeconds() const {
} }
void RealTimeUrlLookupService::HandleLookupError() { void RealTimeUrlLookupService::HandleLookupError() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
consecutive_failures_++; consecutive_failures_++;
// Any successful lookup clears both |consecutive_failures_| as well as // Any successful lookup clears both |consecutive_failures_| as well as
...@@ -226,7 +226,7 @@ void RealTimeUrlLookupService::HandleLookupError() { ...@@ -226,7 +226,7 @@ void RealTimeUrlLookupService::HandleLookupError() {
} }
void RealTimeUrlLookupService::HandleLookupSuccess() { void RealTimeUrlLookupService::HandleLookupSuccess() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
ResetFailures(); ResetFailures();
// |did_successful_lookup_since_last_backoff_| is set to true only when we // |did_successful_lookup_since_last_backoff_| is set to true only when we
...@@ -235,12 +235,12 @@ void RealTimeUrlLookupService::HandleLookupSuccess() { ...@@ -235,12 +235,12 @@ void RealTimeUrlLookupService::HandleLookupSuccess() {
} }
bool RealTimeUrlLookupService::IsInBackoffMode() const { bool RealTimeUrlLookupService::IsInBackoffMode() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
return backoff_timer_.IsRunning(); return backoff_timer_.IsRunning();
} }
void RealTimeUrlLookupService::ResetFailures() { void RealTimeUrlLookupService::ResetFailures() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK(CurrentlyOnThread(ThreadID::IO));
consecutive_failures_ = 0; consecutive_failures_ = 0;
backoff_timer_.Stop(); backoff_timer_.Stop();
} }
......
...@@ -23,6 +23,7 @@ source_set("triggers") { ...@@ -23,6 +23,7 @@ source_set("triggers") {
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core/browser:browser", "//components/safe_browsing/core/browser:browser",
"//components/safe_browsing/core/browser:referrer_chain_provider", "//components/safe_browsing/core/browser:referrer_chain_provider",
"//components/safe_browsing/core/common:thread_utils",
"//net:net", "//net:net",
] ]
} }
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#include "components/safe_browsing/content/base_ui_manager.h" #include "components/safe_browsing/content/base_ui_manager.h"
#include "components/safe_browsing/content/browser/threat_details.h" #include "components/safe_browsing/content/browser/threat_details.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/features.h" #include "components/safe_browsing/core/features.h"
#include "components/security_interstitials/content/unsafe_resource.h" #include "components/security_interstitials/content/unsafe_resource.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace safe_browsing { namespace safe_browsing {
...@@ -150,7 +150,7 @@ bool TriggerManager::StartCollectingThreatDetailsWithReason( ...@@ -150,7 +150,7 @@ bool TriggerManager::StartCollectingThreatDetailsWithReason(
history::HistoryService* history_service, history::HistoryService* history_service,
const SBErrorOptions& error_display_options, const SBErrorOptions& error_display_options,
TriggerManagerReason* reason) { TriggerManagerReason* reason) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
if (!CanStartDataCollectionWithReason(error_display_options, trigger_type, if (!CanStartDataCollectionWithReason(error_display_options, trigger_type,
reason)) reason))
return false; return false;
...@@ -179,7 +179,7 @@ bool TriggerManager::FinishCollectingThreatDetails( ...@@ -179,7 +179,7 @@ bool TriggerManager::FinishCollectingThreatDetails(
bool did_proceed, bool did_proceed,
int num_visits, int num_visits,
const SBErrorOptions& error_display_options) { const SBErrorOptions& error_display_options) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
// Make sure there's a ThreatDetails collector running on this tab. // Make sure there's a ThreatDetails collector running on this tab.
if (!base::Contains(data_collectors_map_, web_contents)) if (!base::Contains(data_collectors_map_, web_contents))
return false; return false;
...@@ -213,7 +213,7 @@ bool TriggerManager::FinishCollectingThreatDetails( ...@@ -213,7 +213,7 @@ bool TriggerManager::FinishCollectingThreatDetails(
} }
void TriggerManager::ThreatDetailsDone(content::WebContents* web_contents) { void TriggerManager::ThreatDetailsDone(content::WebContents* web_contents) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
// Clean up the ThreatDetailsdata collector on the specified tab. // Clean up the ThreatDetailsdata collector on the specified tab.
if (!base::Contains(data_collectors_map_, web_contents)) if (!base::Contains(data_collectors_map_, web_contents))
return; return;
...@@ -223,7 +223,7 @@ void TriggerManager::ThreatDetailsDone(content::WebContents* web_contents) { ...@@ -223,7 +223,7 @@ void TriggerManager::ThreatDetailsDone(content::WebContents* web_contents) {
} }
void TriggerManager::WebContentsDestroyed(content::WebContents* web_contents) { void TriggerManager::WebContentsDestroyed(content::WebContents* web_contents) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
if (!base::Contains(data_collectors_map_, web_contents)) if (!base::Contains(data_collectors_map_, web_contents))
return; return;
data_collectors_map_.erase(web_contents); data_collectors_map_.erase(web_contents);
......
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/history/core/browser/history_service_observer.h" #include "components/history/core/browser/history_service_observer.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/proto/csd.pb.h" #include "components/safe_browsing/core/proto/csd.pb.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
namespace safe_browsing { namespace safe_browsing {
...@@ -558,7 +557,7 @@ void VerdictCacheManager::CleanUpExpiredRealTimeUrlCheckVerdicts() { ...@@ -558,7 +557,7 @@ void VerdictCacheManager::CleanUpExpiredRealTimeUrlCheckVerdicts() {
void VerdictCacheManager::OnURLsDeleted( void VerdictCacheManager::OnURLsDeleted(
history::HistoryService* history_service, history::HistoryService* history_service,
const history::DeletionInfo& deletion_info) { const history::DeletionInfo& deletion_info) {
base::PostTask(FROM_HERE, {content::BrowserThread::UI}, base::PostTask(FROM_HERE, CreateTaskTraits(ThreadID::UI),
base::BindRepeating( base::BindRepeating(
&VerdictCacheManager::RemoveContentSettingsOnURLsDeleted, &VerdictCacheManager::RemoveContentSettingsOnURLsDeleted,
GetWeakPtr(), deletion_info.IsAllHistory(), GetWeakPtr(), deletion_info.IsAllHistory(),
...@@ -630,7 +629,7 @@ bool VerdictCacheManager::RemoveExpiredRealTimeUrlCheckVerdicts( ...@@ -630,7 +629,7 @@ bool VerdictCacheManager::RemoveExpiredRealTimeUrlCheckVerdicts(
void VerdictCacheManager::RemoveContentSettingsOnURLsDeleted( void VerdictCacheManager::RemoveContentSettingsOnURLsDeleted(
bool all_history, bool all_history,
const history::URLRows& deleted_rows) { const history::URLRows& deleted_rows) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(CurrentlyOnThread(ThreadID::UI));
DCHECK(content_settings_); DCHECK(content_settings_);
if (all_history) { if (all_history) {
......
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