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

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

Issue 2469673002: Invalidate WeakPtrs of ResourceMessageFilter on channel shutdown (Closed)
Patch Set: remove test Created 4 years, 1 month 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 7fd049eb4034192ded7c7a8ff033e9b92617fe9f..2ee8ff5c7a7b7916dff0d16b123d05fb36f36d6a 100644
--- a/content/browser/loader/resource_message_filter.cc
+++ b/content/browser/loader/resource_message_filter.cc
@@ -27,6 +27,7 @@ ResourceMessageFilter::ResourceMessageFilter(
BrowserAssociatedInterface<mojom::URLLoaderFactory>(this, this),
child_id_(child_id),
process_type_(process_type),
+ is_channel_closed_(false),
appcache_service_(appcache_service),
blob_storage_context_(blob_storage_context),
file_system_context_(file_system_context),
@@ -34,12 +35,21 @@ ResourceMessageFilter::ResourceMessageFilter(
get_contexts_callback_(get_contexts_callback),
weak_ptr_factory_(this) {}
-ResourceMessageFilter::~ResourceMessageFilter() {}
+ResourceMessageFilter::~ResourceMessageFilter() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(is_channel_closed_);
+ DCHECK(!weak_ptr_factory_.HasWeakPtrs());
+}
void ResourceMessageFilter::OnChannelClosing() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
// Unhook us from all pending network requests so they don't get sent to a
// deleted object.
ResourceDispatcherHostImpl::Get()->CancelRequestsForProcess(child_id_);
+
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ is_channel_closed_ = true;
}
bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
@@ -62,7 +72,7 @@ void ResourceMessageFilter::GetContexts(
base::WeakPtr<ResourceMessageFilter> ResourceMessageFilter::GetWeakPtr() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- return weak_ptr_factory_.GetWeakPtr();
+ return is_channel_closed_ ? nullptr : weak_ptr_factory_.GetWeakPtr();
}
void ResourceMessageFilter::CreateLoaderAndStart(
« no previous file with comments | « content/browser/loader/resource_message_filter.h ('k') | content/browser/loader/url_loader_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698