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

Side by Side Diff: content/browser/loader/url_loader_factory_impl.cc

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: incorporated mmemke's comment 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/loader/url_loader_factory_impl.h" 5 #include "content/browser/loader/url_loader_factory_impl.h"
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 #include "content/browser/loader/resource_message_filter.h" 8 #include "content/browser/loader/resource_requester_info.h"
9 #include "content/common/resource_request.h" 9 #include "content/common/resource_request.h"
10 #include "content/common/url_loader.mojom.h" 10 #include "content/common/url_loader.mojom.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h" 12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 void DispatchSyncLoadResult( 18 void DispatchSyncLoadResult(
19 const URLLoaderFactoryImpl::SyncLoadCallback& callback, 19 const URLLoaderFactoryImpl::SyncLoadCallback& callback,
20 const SyncLoadResult* result) { 20 const SyncLoadResult* result) {
21 // |result| can be null when a loading task is aborted unexpectedly. Reply 21 // |result| can be null when a loading task is aborted unexpectedly. Reply
22 // with a failure result on that case. 22 // with a failure result on that case.
23 // TODO(tzik): Test null-result case. 23 // TODO(tzik): Test null-result case.
24 if (!result) { 24 if (!result) {
25 SyncLoadResult failure; 25 SyncLoadResult failure;
26 failure.error_code = net::ERR_FAILED; 26 failure.error_code = net::ERR_FAILED;
27 callback.Run(failure); 27 callback.Run(failure);
28 return; 28 return;
29 } 29 }
30 30
31 callback.Run(*result); 31 callback.Run(*result);
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 URLLoaderFactoryImpl::URLLoaderFactoryImpl( 36 URLLoaderFactoryImpl::URLLoaderFactoryImpl(
37 scoped_refptr<ResourceMessageFilter> resource_message_filter) 37 std::unique_ptr<ResourceRequesterInfo> requester_info)
38 : resource_message_filter_(std::move(resource_message_filter)) { 38 : requester_info_(std::move(requester_info)) {
39 DCHECK(resource_message_filter_); 39 DCHECK(requester_info_->IsRenderer());
40 DCHECK(requester_info_->GetFilter());
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); 41 DCHECK_CURRENTLY_ON(BrowserThread::IO);
41 } 42 }
42 43
43 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { 44 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO); 45 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45 } 46 }
46 47
47 void URLLoaderFactoryImpl::CreateLoaderAndStart( 48 void URLLoaderFactoryImpl::CreateLoaderAndStart(
48 mojom::URLLoaderAssociatedRequest request, 49 mojom::URLLoaderAssociatedRequest request,
49 int32_t routing_id, 50 int32_t routing_id,
50 int32_t request_id, 51 int32_t request_id,
51 const ResourceRequest& url_request, 52 const ResourceRequest& url_request,
52 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) { 53 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) {
53 CreateLoaderAndStart(std::move(request), routing_id, request_id, url_request, 54 CreateLoaderAndStart(std::move(request), routing_id, request_id, url_request,
54 std::move(client_ptr_info), 55 std::move(client_ptr_info), requester_info_->clone());
55 resource_message_filter_.get());
56 } 56 }
57 57
58 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, 58 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id,
59 int32_t request_id, 59 int32_t request_id,
60 const ResourceRequest& url_request, 60 const ResourceRequest& url_request,
61 const SyncLoadCallback& callback) { 61 const SyncLoadCallback& callback) {
62 SyncLoad(routing_id, request_id, url_request, callback, 62 SyncLoad(routing_id, request_id, url_request, callback,
63 resource_message_filter_.get()); 63 requester_info_->clone());
64 } 64 }
65 65
66 // static 66 // static
67 void URLLoaderFactoryImpl::CreateLoaderAndStart( 67 void URLLoaderFactoryImpl::CreateLoaderAndStart(
68 mojom::URLLoaderAssociatedRequest request, 68 mojom::URLLoaderAssociatedRequest request,
69 int32_t routing_id, 69 int32_t routing_id,
70 int32_t request_id, 70 int32_t request_id,
71 const ResourceRequest& url_request, 71 const ResourceRequest& url_request,
72 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info, 72 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info,
73 ResourceMessageFilter* filter) { 73 std::unique_ptr<ResourceRequesterInfo> requester_info) {
74 DCHECK_CURRENTLY_ON(BrowserThread::IO); 74 DCHECK_CURRENTLY_ON(BrowserThread::IO);
75 75
76 mojom::URLLoaderClientAssociatedPtr client; 76 mojom::URLLoaderClientAssociatedPtr client;
77 client.Bind(std::move(client_ptr_info)); 77 client.Bind(std::move(client_ptr_info));
78 78
79 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); 79 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
80 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, 80 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request,
81 std::move(request), std::move(client), filter); 81 std::move(request), std::move(client),
82 std::move(requester_info));
82 } 83 }
83 84
84 // static 85 // static
85 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, 86 void URLLoaderFactoryImpl::SyncLoad(
86 int32_t request_id, 87 int32_t routing_id,
87 const ResourceRequest& url_request, 88 int32_t request_id,
88 const SyncLoadCallback& callback, 89 const ResourceRequest& url_request,
89 ResourceMessageFilter* filter) { 90 const SyncLoadCallback& callback,
91 std::unique_ptr<ResourceRequesterInfo> requester_info) {
90 DCHECK_CURRENTLY_ON(BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(BrowserThread::IO);
91 93
92 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); 94 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
93 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request, filter, 95 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request,
96 std::move(requester_info),
94 base::Bind(&DispatchSyncLoadResult, callback)); 97 base::Bind(&DispatchSyncLoadResult, callback));
95 } 98 }
96 99
97 void URLLoaderFactoryImpl::Create( 100 void URLLoaderFactoryImpl::Create(
98 scoped_refptr<ResourceMessageFilter> filter, 101 std::unique_ptr<ResourceRequesterInfo> requester_info,
99 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { 102 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
100 mojo::MakeStrongBinding( 103 mojo::MakeStrongBinding(
101 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), 104 base::WrapUnique(new URLLoaderFactoryImpl(std::move(requester_info))),
102 std::move(request)); 105 std::move(request));
103 } 106 }
104 107
105 } // namespace content 108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698