Commit 7a9db510 authored by yhirano's avatar yhirano Committed by Commit bot

Provide route ID via URLLoaderFactory

BUG=603396

Review-Url: https://codereview.chromium.org/2390983002
Cr-Commit-Position: refs/heads/master@{#423011}
parent 50face11
......@@ -326,6 +326,7 @@ specific_include_rules = {
"+content/browser/loader/test_url_loader_client.h",
"+content/browser/loader/resource_dispatcher_host_impl.h",
"+content/browser/loader/resource_message_filter.h",
"+content/browser/loader/resource_request_info_impl.h",
"+content/browser/loader/url_loader_factory_impl.h",
"+content/browser/loader_delegate_impl.h",
"+content/common/resource_request.h",
......
......@@ -26,13 +26,12 @@ URLLoaderFactoryImpl::~URLLoaderFactoryImpl() {
void URLLoaderFactoryImpl::CreateLoaderAndStart(
mojom::URLLoaderRequest request,
int32_t routing_id,
int32_t request_id,
const ResourceRequest& url_request,
mojom::URLLoaderClientPtr client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(yhirano): Provide the right routing ID.
const int routing_id = 0;
ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request,
std::move(request), std::move(client),
......
......@@ -22,6 +22,7 @@ class URLLoaderFactoryImpl final : public mojom::URLLoaderFactory {
~URLLoaderFactoryImpl() override;
void CreateLoaderAndStart(mojom::URLLoaderRequest request,
int32_t routing_id,
int32_t request_id,
const ResourceRequest& url_request,
mojom::URLLoaderClientPtr client) override;
......
......@@ -22,6 +22,7 @@
#include "content/browser/loader/navigation_resource_throttle.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#include "content/browser/loader/resource_message_filter.h"
#include "content/browser/loader/resource_request_info_impl.h"
#include "content/browser/loader/test_url_loader_client.h"
#include "content/browser/loader_delegate_impl.h"
#include "content/common/resource_request.h"
......@@ -53,6 +54,8 @@ namespace content {
namespace {
constexpr int kChildId = 99;
class RejectingResourceDispatcherHostDelegate final
: public ResourceDispatcherHostDelegate {
public:
......@@ -76,7 +79,7 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> {
: thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
browser_context_(new TestBrowserContext()),
resource_message_filter_(new ResourceMessageFilter(
0,
kChildId,
// If browser side navigation is enabled then
// ResourceDispatcherHostImpl prevents main frame URL requests from
// the renderer. Ensure that these checks don't trip us up by
......@@ -130,6 +133,8 @@ class URLLoaderFactoryImplTest : public ::testing::TestWithParam<size_t> {
};
TEST_P(URLLoaderFactoryImplTest, GetResponse) {
constexpr int32_t kRoutingId = 81;
constexpr int32_t kRequestId = 28;
NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
mojom::URLLoaderPtr loader;
base::FilePath root;
......@@ -142,7 +147,8 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) {
request.url = net::URLRequestMockHTTPJob::GetMockUrl("hello.html");
request.method = "GET";
request.is_main_frame = true;
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request,
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), kRoutingId,
kRequestId, request,
client.CreateInterfacePtrAndBind());
ASSERT_FALSE(client.has_received_response());
......@@ -150,6 +156,17 @@ TEST_P(URLLoaderFactoryImplTest, GetResponse) {
ASSERT_FALSE(client.has_received_completion());
client.RunUntilResponseReceived();
net::URLRequest* url_request =
rdh_.GetURLRequest(GlobalRequestID(kChildId, kRequestId));
ASSERT_TRUE(url_request);
ResourceRequestInfoImpl* request_info =
ResourceRequestInfoImpl::ForRequest(url_request);
ASSERT_TRUE(request_info);
EXPECT_EQ(kChildId, request_info->GetChildID());
EXPECT_EQ(kRoutingId, request_info->GetRouteID());
EXPECT_EQ(kRequestId, request_info->GetRequestID());
ASSERT_FALSE(client.has_received_completion());
ASSERT_FALSE(client.has_received_completion());
......@@ -194,7 +211,7 @@ TEST_P(URLLoaderFactoryImplTest, GetFailedResponse) {
request.url = net::URLRequestFailedJob::GetMockHttpUrlWithFailurePhase(
net::URLRequestFailedJob::START, net::ERR_TIMED_OUT);
request.method = "GET";
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request,
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request,
client.CreateInterfacePtrAndBind());
client.RunUntilComplete();
......@@ -212,7 +229,7 @@ TEST_P(URLLoaderFactoryImplTest, InvalidURL) {
request.url = GURL();
request.method = "GET";
ASSERT_FALSE(request.url.is_valid());
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request,
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request,
client.CreateInterfacePtrAndBind());
client.RunUntilComplete();
......@@ -231,7 +248,7 @@ TEST_P(URLLoaderFactoryImplTest, ShouldNotRequestURL) {
TestURLLoaderClient client;
request.url = GURL("http://localhost/");
request.method = "GET";
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 1, request,
factory_->CreateLoaderAndStart(mojo::GetProxy(&loader), 2, 1, request,
client.CreateInterfacePtrAndBind());
client.RunUntilComplete();
......
......@@ -664,7 +664,7 @@ int ResourceDispatcher::StartAsync(
new URLLoaderClientImpl(request_id, this, main_thread_task_runner_));
mojom::URLLoaderPtr url_loader;
url_loader_factory->CreateLoaderAndStart(
GetProxy(&url_loader), request_id, *request,
GetProxy(&url_loader), routing_id, 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);
......
......@@ -12,6 +12,7 @@ interface URLLoaderFactory {
// (e.g., response arrival) happen. |request_id| is for compatibility with
// the existing Chrome IPC.
CreateLoaderAndStart(URLLoader& loader,
int32 routing_id,
int32 request_id,
URLRequest request,
URLLoaderClient client);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment