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

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

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix unittests 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..530e4d8e977496e5bf507e43c6a2cbc4b8428977 100644
--- a/content/browser/loader/resource_message_filter.cc
+++ b/content/browser/loader/resource_message_filter.cc
@@ -7,6 +7,7 @@
#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"
@@ -17,7 +18,6 @@ namespace content {
ResourceMessageFilter::ResourceMessageFilter(
int child_id,
- int process_type,
ChromeAppCacheService* appcache_service,
ChromeBlobStorageContext* blob_storage_context,
storage::FileSystemContext* file_system_context,
@@ -25,14 +25,14 @@ 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),
+ requester_info_(
+ ResourceRequesterInfo::CreateForRenderer(child_id,
+ appcache_service,
+ blob_storage_context,
+ file_system_context,
+ service_worker_context,
+ get_contexts_callback)),
weak_ptr_factory_(this) {}
ResourceMessageFilter::~ResourceMessageFilter() {
@@ -41,19 +41,26 @@ ResourceMessageFilter::~ResourceMessageFilter() {
DCHECK(!weak_ptr_factory_.HasWeakPtrs());
}
+void ResourceMessageFilter::OnFilterAdded(IPC::Channel*) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ requester_info_->set_filter(GetWeakPtr());
mmenke 2016/11/17 16:27:20 Comment that this can't be done on construction be
horo 2016/11/17 17:50:27 Done. Added comment.
+}
+
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);
+ return ResourceDispatcherHostImpl::Get()->OnMessageReceived(
+ message, requester_info_.get());
}
void ResourceMessageFilter::OnDestruct() const {
@@ -62,14 +69,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 +80,21 @@ 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();
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698