OLD | NEW |
---|---|
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_message_filter.h" |
yhirano
2016/11/10 06:42:29
Not needed.
horo
2016/11/10 14:46:33
Done.
| |
9 #include "content/browser/loader/resource_requester_info.h" | |
9 #include "content/common/resource_request.h" | 10 #include "content/common/resource_request.h" |
10 #include "content/common/url_loader.mojom.h" | 11 #include "content/common/url_loader.mojom.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 #include "mojo/public/cpp/bindings/strong_binding.h" | 13 #include "mojo/public/cpp/bindings/strong_binding.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 void DispatchSyncLoadResult( | 19 void DispatchSyncLoadResult( |
19 const URLLoaderFactoryImpl::SyncLoadCallback& callback, | 20 const URLLoaderFactoryImpl::SyncLoadCallback& callback, |
20 const SyncLoadResult* result) { | 21 const SyncLoadResult* result) { |
21 // |result| can be null when a loading task is aborted unexpectedly. Reply | 22 // |result| can be null when a loading task is aborted unexpectedly. Reply |
22 // with a failure result on that case. | 23 // with a failure result on that case. |
23 // TODO(tzik): Test null-result case. | 24 // TODO(tzik): Test null-result case. |
24 if (!result) { | 25 if (!result) { |
25 SyncLoadResult failure; | 26 SyncLoadResult failure; |
26 failure.error_code = net::ERR_FAILED; | 27 failure.error_code = net::ERR_FAILED; |
27 callback.Run(failure); | 28 callback.Run(failure); |
28 return; | 29 return; |
29 } | 30 } |
30 | 31 |
31 callback.Run(*result); | 32 callback.Run(*result); |
32 } | 33 } |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 URLLoaderFactoryImpl::URLLoaderFactoryImpl( | 37 URLLoaderFactoryImpl::URLLoaderFactoryImpl( |
37 scoped_refptr<ResourceMessageFilter> resource_message_filter) | 38 std::unique_ptr<ResourceRequesterInfo> requester_info) |
38 : resource_message_filter_(std::move(resource_message_filter)) { | 39 : requester_info_(std::move(requester_info)) { |
39 DCHECK(resource_message_filter_); | 40 DCHECK(requester_info_->IsRenderer()); |
41 DCHECK(requester_info_->filter()); | |
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 42 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
41 } | 43 } |
42 | 44 |
43 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { | 45 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { |
44 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 46 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
45 } | 47 } |
46 | 48 |
47 void URLLoaderFactoryImpl::CreateLoaderAndStart( | 49 void URLLoaderFactoryImpl::CreateLoaderAndStart( |
48 mojom::URLLoaderAssociatedRequest request, | 50 mojom::URLLoaderAssociatedRequest request, |
49 int32_t routing_id, | 51 int32_t routing_id, |
50 int32_t request_id, | 52 int32_t request_id, |
51 const ResourceRequest& url_request, | 53 const ResourceRequest& url_request, |
52 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) { | 54 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) { |
53 CreateLoaderAndStart(std::move(request), routing_id, request_id, url_request, | 55 CreateLoaderAndStart(std::move(request), routing_id, request_id, url_request, |
54 std::move(client_ptr_info), | 56 std::move(client_ptr_info), requester_info_->clone()); |
55 resource_message_filter_.get()); | |
56 } | 57 } |
57 | 58 |
58 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, | 59 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, |
59 int32_t request_id, | 60 int32_t request_id, |
60 const ResourceRequest& url_request, | 61 const ResourceRequest& url_request, |
61 const SyncLoadCallback& callback) { | 62 const SyncLoadCallback& callback) { |
62 SyncLoad(routing_id, request_id, url_request, callback, | 63 SyncLoad(routing_id, request_id, url_request, callback, |
63 resource_message_filter_.get()); | 64 requester_info_->clone()); |
64 } | 65 } |
65 | 66 |
66 // static | 67 // static |
67 void URLLoaderFactoryImpl::CreateLoaderAndStart( | 68 void URLLoaderFactoryImpl::CreateLoaderAndStart( |
68 mojom::URLLoaderAssociatedRequest request, | 69 mojom::URLLoaderAssociatedRequest request, |
69 int32_t routing_id, | 70 int32_t routing_id, |
70 int32_t request_id, | 71 int32_t request_id, |
71 const ResourceRequest& url_request, | 72 const ResourceRequest& url_request, |
72 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info, | 73 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info, |
73 ResourceMessageFilter* filter) { | 74 std::unique_ptr<ResourceRequesterInfo> requester_info) { |
74 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
75 | 76 |
76 mojom::URLLoaderClientAssociatedPtr client; | 77 mojom::URLLoaderClientAssociatedPtr client; |
77 client.Bind(std::move(client_ptr_info)); | 78 client.Bind(std::move(client_ptr_info)); |
78 | 79 |
79 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 80 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
80 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, | 81 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, |
81 std::move(request), std::move(client), filter); | 82 std::move(request), std::move(client), |
83 std::move(requester_info)); | |
82 } | 84 } |
83 | 85 |
84 // static | 86 // static |
85 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, | 87 void URLLoaderFactoryImpl::SyncLoad( |
86 int32_t request_id, | 88 int32_t routing_id, |
87 const ResourceRequest& url_request, | 89 int32_t request_id, |
88 const SyncLoadCallback& callback, | 90 const ResourceRequest& url_request, |
89 ResourceMessageFilter* filter) { | 91 const SyncLoadCallback& callback, |
92 std::unique_ptr<ResourceRequesterInfo> requester_info) { | |
90 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
91 | 94 |
92 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 95 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
93 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request, filter, | 96 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request, |
97 std::move(requester_info), | |
94 base::Bind(&DispatchSyncLoadResult, callback)); | 98 base::Bind(&DispatchSyncLoadResult, callback)); |
95 } | 99 } |
96 | 100 |
97 void URLLoaderFactoryImpl::Create( | 101 void URLLoaderFactoryImpl::Create( |
98 scoped_refptr<ResourceMessageFilter> filter, | 102 std::unique_ptr<ResourceRequesterInfo> requester_info, |
99 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { | 103 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
100 mojo::MakeStrongBinding( | 104 mojo::MakeStrongBinding( |
101 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), | 105 base::WrapUnique(new URLLoaderFactoryImpl(std::move(requester_info))), |
102 std::move(request)); | 106 std::move(request)); |
103 } | 107 } |
104 | 108 |
105 } // namespace content | 109 } // namespace content |
OLD | NEW |