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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix URLLoaderFactoryImplTest/URLLoaderFactoryImplTest.GetFailedResponse2 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 2ee8ff5c7a7b7916dff0d16b123d05fb36f36d6a..b70e281bc733ee2dd1cdaea4ee03222639873e38 100644
--- a/content/browser/loader/resource_message_filter.cc
+++ b/content/browser/loader/resource_message_filter.cc
@@ -4,12 +4,15 @@
#include "content/browser/loader/resource_message_filter.h"
+#include "base/logging.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
+#include "content/browser/loader/resource_requester_info.h"
#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"
@@ -17,7 +20,6 @@ namespace content {
ResourceMessageFilter::ResourceMessageFilter(
int child_id,
- int process_type,
ChromeAppCacheService* appcache_service,
ChromeBlobStorageContext* blob_storage_context,
storage::FileSystemContext* file_system_context,
@@ -25,15 +27,17 @@ ResourceMessageFilter::ResourceMessageFilter(
const GetContextsCallback& get_contexts_callback)
: BrowserMessageFilter(ResourceMsgStart),
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),
- service_worker_context_(service_worker_context),
- get_contexts_callback_(get_contexts_callback),
- weak_ptr_factory_(this) {}
+ requester_info_(
+ ResourceRequesterInfo::CreateForRenderer(child_id,
+ appcache_service,
+ blob_storage_context,
+ file_system_context,
+ service_worker_context,
+ get_contexts_callback)),
+ weak_ptr_factory_(this) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+}
ResourceMessageFilter::~ResourceMessageFilter() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -41,19 +45,29 @@ ResourceMessageFilter::~ResourceMessageFilter() {
DCHECK(!weak_ptr_factory_.HasWeakPtrs());
}
+void ResourceMessageFilter::OnFilterAdded(IPC::Channel*) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ InitializeOnIOThread();
+}
+
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_);
+ ResourceDispatcherHostImpl::Get()->CancelRequestsForProcess(
+ requester_info_->child_id());
weak_ptr_factory_.InvalidateWeakPtrs();
is_channel_closed_ = true;
}
bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
- return ResourceDispatcherHostImpl::Get()->OnMessageReceived(message, this);
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ // Check if InitializeOnIOThread() has been called.
+ DCHECK_EQ(this, requester_info_->filter());
+ return ResourceDispatcherHostImpl::Get()->OnMessageReceived(
+ message, requester_info_.get());
}
void ResourceMessageFilter::OnDestruct() const {
@@ -62,14 +76,6 @@ void ResourceMessageFilter::OnDestruct() const {
BrowserThread::DeleteOnIOThread::Destruct(this);
}
-void ResourceMessageFilter::GetContexts(
- ResourceType resource_type,
- ResourceContext** resource_context,
- net::URLRequestContext** request_context) {
- return get_contexts_callback_.Run(resource_type, resource_context,
- request_context);
-}
-
base::WeakPtr<ResourceMessageFilter> ResourceMessageFilter::GetWeakPtr() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
return is_channel_closed_ ? nullptr : weak_ptr_factory_.GetWeakPtr();
@@ -81,17 +87,32 @@ void ResourceMessageFilter::CreateLoaderAndStart(
int32_t request_id,
const ResourceRequest& url_request,
mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) {
- URLLoaderFactoryImpl::CreateLoaderAndStart(std::move(request), routing_id,
- request_id, url_request,
- std::move(client_ptr_info), this);
+ URLLoaderFactoryImpl::CreateLoaderAndStart(
+ requester_info_.get(), std::move(request), routing_id, request_id,
+ url_request, std::move(client_ptr_info));
}
void ResourceMessageFilter::SyncLoad(int32_t routing_id,
int32_t request_id,
const ResourceRequest& url_request,
const SyncLoadCallback& callback) {
- URLLoaderFactoryImpl::SyncLoad(routing_id, request_id, url_request, callback,
- this);
+ URLLoaderFactoryImpl::SyncLoad(requester_info_.get(), routing_id, request_id,
+ url_request, callback);
+}
+
+int ResourceMessageFilter::child_id() const {
+ return requester_info_->child_id();
+}
+
+void ResourceMessageFilter::InitializeForTest() {
+ InitializeOnIOThread();
+}
+
+void ResourceMessageFilter::InitializeOnIOThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ // 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());
}
} // namespace content
« no previous file with comments | « content/browser/loader/resource_message_filter.h ('k') | content/browser/loader/resource_request_info_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698