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

Unified Diff: content/child/resource_dispatcher.cc

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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/child/resource_dispatcher.cc
diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc
index 9c5a47a09e49c5836a699a94a3a62f435e93fb08..500e25bb502d1953d0891790750a46d94ccc9a2c 100644
--- a/content/child/resource_dispatcher.cc
+++ b/content/child/resource_dispatcher.cc
@@ -28,6 +28,7 @@
#include "content/child/shared_memory_received_data_factory.h"
#include "content/child/site_isolation_stats_gatherer.h"
#include "content/child/sync_load_response.h"
+#include "content/child/url_response_body_consumer.h"
#include "content/common/inter_process_time_ticks_converter.h"
#include "content/common/navigation_params.h"
#include "content/common/resource_messages.h"
@@ -39,6 +40,7 @@
#include "content/public/common/content_features.h"
#include "content/public/common/resource_response.h"
#include "content/public/common/resource_type.h"
+#include "mojo/public/cpp/bindings/binding.h"
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/http/http_response_headers.h"
@@ -73,6 +75,44 @@ int MakeRequestID() {
return next_request_id++;
}
+class URLLoaderClientImpl final : public mojom::URLLoaderClient {
+ public:
+ URLLoaderClientImpl(int request_id, ResourceDispatcher* resource_dispatcher)
+ : binding_(this),
+ request_id_(request_id),
+ resource_dispatcher_(resource_dispatcher) {}
+ ~URLLoaderClientImpl() override {
+ if (body_consumer_)
+ body_consumer_->Cancel();
+ }
+
+ void OnReceiveResponse(const ResourceResponseHead& response_head) override {
+ resource_dispatcher_->OnMessageReceived(
+ ResourceMsg_ReceivedResponse(request_id_, response_head));
+ }
+
+ void OnStartLoadingResponseBody(
+ mojo::ScopedDataPipeConsumerHandle body) override {
+ DCHECK(!body_consumer_);
+ body_consumer_ = new URLResponseBodyConsumer(
+ request_id_, resource_dispatcher_, std::move(body));
+ }
+
+ void OnComplete(const ResourceRequestCompletionStatus& status) override {
+ body_consumer_->OnComplete(status);
+ }
+
+ mojom::URLLoaderClientPtr CreateInterfacePtrAndBind() {
+ return binding_.CreateInterfacePtrAndBind();
+ }
+
+ private:
+ mojo::Binding<mojom::URLLoaderClient> binding_;
+ scoped_refptr<URLResponseBodyConsumer> body_consumer_;
+ const int request_id_;
+ ResourceDispatcher* const resource_dispatcher_;
+};
+
} // namespace
ResourceDispatcher::ResourceDispatcher(
@@ -545,11 +585,16 @@ void ResourceDispatcher::FlushDeferredMessages(int request_id) {
}
}
-void ResourceDispatcher::StartSync(const RequestInfo& request_info,
- ResourceRequestBodyImpl* request_body,
- SyncLoadResponse* response) {
+void ResourceDispatcher::StartSync(
+ const RequestInfo& request_info,
+ ResourceRequestBodyImpl* request_body,
+ SyncLoadResponse* response,
+ blink::WebURLRequest::LoadingIPCType ipc_type,
+ mojom::URLLoaderFactory* url_loader_factory) {
std::unique_ptr<ResourceRequest> request =
CreateRequest(request_info, request_body, NULL);
+ // TODO(yhirano): Use url_loader_factory otherwise.
+ DCHECK_EQ(blink::WebURLRequest::LoadingIPCType::ChromeIPC, ipc_type);
SyncLoadResult result;
IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad(
@@ -578,9 +623,12 @@ void ResourceDispatcher::StartSync(const RequestInfo& request_info,
response->encoded_body_length = result.encoded_body_length;
}
-int ResourceDispatcher::StartAsync(const RequestInfo& request_info,
- ResourceRequestBodyImpl* request_body,
- std::unique_ptr<RequestPeer> peer) {
+int ResourceDispatcher::StartAsync(
+ const RequestInfo& request_info,
+ ResourceRequestBodyImpl* request_body,
+ std::unique_ptr<RequestPeer> peer,
+ blink::WebURLRequest::LoadingIPCType ipc_type,
+ mojom::URLLoaderFactory* url_loader_factory) {
GURL frame_origin;
std::unique_ptr<ResourceRequest> request =
CreateRequest(request_info, request_body, &frame_origin);
@@ -598,8 +646,19 @@ int ResourceDispatcher::StartAsync(const RequestInfo& request_info,
request_info.loading_web_task_runner->clone());
}
- message_sender_->Send(new ResourceHostMsg_RequestResource(
- request_info.routing_id, request_id, *request));
+ if (ipc_type == blink::WebURLRequest::LoadingIPCType::Mojo) {
+ std::unique_ptr<URLLoaderClientImpl> client(
+ new URLLoaderClientImpl(request_id, this));
+ mojom::URLLoaderPtr url_loader;
+ url_loader_factory->CreateLoaderAndStart(
+ GetProxy(&url_loader), request_id, *request,
+ client->CreateInterfacePtrAndBind());
+ pending_requests_[request_id]->url_loader = std::move(url_loader);
+ pending_requests_[request_id]->url_loader_client = std::move(client);
+ } else {
+ message_sender_->Send(new ResourceHostMsg_RequestResource(
+ request_info.routing_id, request_id, *request));
+ }
return request_id;
}

Powered by Google App Engine
This is Rietveld 408576698