Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: content/browser/loader/resource_message_filter.cc

Issue 2785523002: Reduce/remove usage of BrowserThread in content/browser/loader. (Closed)
Patch Set: Remove stray include Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_message_filter.cc
diff --git a/content/browser/loader/resource_message_filter.cc b/content/browser/loader/resource_message_filter.cc
index d437a15e1b1f04a3737835e0840f77ff7a621442..5262b2be418ffead24ff3500f4566e1a28ed12ba 100644
--- a/content/browser/loader/resource_message_filter.cc
+++ b/content/browser/loader/resource_message_filter.cc
@@ -12,7 +12,6 @@
#include "content/browser/loader/url_loader_factory_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/common/resource_messages.h"
-#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "storage/browser/fileapi/file_system_context.h"
@@ -24,7 +23,9 @@ ResourceMessageFilter::ResourceMessageFilter(
ChromeBlobStorageContext* blob_storage_context,
storage::FileSystemContext* file_system_context,
ServiceWorkerContextWrapper* service_worker_context,
- const GetContextsCallback& get_contexts_callback)
+ const GetContextsCallback& get_contexts_callback,
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_runner,
jam 2017/04/03 14:47:03 no need to pass this one in, we can remove the dch
ananta 2017/04/03 22:58:19 Done.
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner)
: BrowserMessageFilter(ResourceMsgStart),
BrowserAssociatedInterface<mojom::URLLoaderFactory>(this, this),
is_channel_closed_(false),
@@ -35,23 +36,25 @@ ResourceMessageFilter::ResourceMessageFilter(
file_system_context,
service_worker_context,
get_contexts_callback)),
+ main_thread_task_runner_(main_thread_runner),
+ io_thread_task_runner_(io_thread_runner),
weak_ptr_factory_(this) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
}
ResourceMessageFilter::~ResourceMessageFilter() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
DCHECK(is_channel_closed_);
DCHECK(!weak_ptr_factory_.HasWeakPtrs());
}
void ResourceMessageFilter::OnFilterAdded(IPC::Channel*) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
InitializeOnIOThread();
}
void ResourceMessageFilter::OnChannelClosing() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
// Unhook us from all pending network requests so they don't get sent to a
// deleted object.
@@ -63,7 +66,7 @@ void ResourceMessageFilter::OnChannelClosing() {
}
bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
// Check if InitializeOnIOThread() has been called.
DCHECK_EQ(this, requester_info_->filter());
return ResourceDispatcherHostImpl::Get()->OnMessageReceived(
@@ -73,11 +76,15 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
void ResourceMessageFilter::OnDestruct() const {
// Destroy the filter on the IO thread since that's where its weak pointers
// are being used.
- BrowserThread::DeleteOnIOThread::Destruct(this);
+ if (io_thread_task_runner_->BelongsToCurrentThread()) {
+ delete this;
+ } else {
+ io_thread_task_runner_->DeleteSoon(FROM_HERE, this);
+ }
}
base::WeakPtr<ResourceMessageFilter> ResourceMessageFilter::GetWeakPtr() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
return is_channel_closed_ ? nullptr : weak_ptr_factory_.GetWeakPtr();
}
@@ -109,7 +116,7 @@ void ResourceMessageFilter::InitializeForTest() {
}
void ResourceMessageFilter::InitializeOnIOThread() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
// The WeakPtr of the filter must be created on the IO thread. So sets the
// WeakPtr of |requester_info_| now.
requester_info_->set_filter(GetWeakPtr());

Powered by Google App Engine
This is Rietveld 408576698