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