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" |
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 { |
| 17 |
| 18 void DispatchSyncLoadResult( |
| 19 const URLLoaderFactoryImpl::SyncLoadCallback& callback, |
| 20 const SyncLoadResult* result) { |
| 21 if (!result) { |
| 22 SyncLoadResult failure; |
| 23 failure.error_code = net::ERR_FAILED; |
| 24 callback.Run(failure); |
| 25 return; |
| 26 } |
| 27 |
| 28 callback.Run(*result); |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
16 URLLoaderFactoryImpl::URLLoaderFactoryImpl( | 33 URLLoaderFactoryImpl::URLLoaderFactoryImpl( |
17 scoped_refptr<ResourceMessageFilter> resource_message_filter) | 34 scoped_refptr<ResourceMessageFilter> resource_message_filter) |
18 : resource_message_filter_(std::move(resource_message_filter)) { | 35 : resource_message_filter_(std::move(resource_message_filter)) { |
19 DCHECK(resource_message_filter_); | 36 DCHECK(resource_message_filter_); |
20 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 37 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
21 } | 38 } |
22 | 39 |
23 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { | 40 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { |
24 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
25 } | 42 } |
26 | 43 |
27 void URLLoaderFactoryImpl::CreateLoaderAndStart( | 44 void URLLoaderFactoryImpl::CreateLoaderAndStart( |
28 mojom::URLLoaderRequest request, | 45 mojom::URLLoaderRequest request, |
29 int32_t routing_id, | 46 int32_t routing_id, |
30 int32_t request_id, | 47 int32_t request_id, |
31 const ResourceRequest& url_request, | 48 const ResourceRequest& url_request, |
32 mojom::URLLoaderClientPtr client) { | 49 mojom::URLLoaderClientPtr client) { |
33 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
34 | 51 |
35 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 52 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
36 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, | 53 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, |
37 std::move(request), std::move(client), | 54 std::move(request), std::move(client), |
38 resource_message_filter_.get()); | 55 resource_message_filter_.get()); |
39 } | 56 } |
40 | 57 |
| 58 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, |
| 59 int32_t request_id, |
| 60 const ResourceRequest& url_request, |
| 61 const SyncLoadCallback& callback) { |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 63 |
| 64 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 65 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request, |
| 66 resource_message_filter_.get(), |
| 67 base::Bind(&DispatchSyncLoadResult, callback)); |
| 68 } |
| 69 |
41 void URLLoaderFactoryImpl::Create( | 70 void URLLoaderFactoryImpl::Create( |
42 scoped_refptr<ResourceMessageFilter> filter, | 71 scoped_refptr<ResourceMessageFilter> filter, |
43 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { | 72 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
44 mojo::MakeStrongBinding( | 73 mojo::MakeStrongBinding( |
45 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), | 74 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), |
46 std::move(request)); | 75 std::move(request)); |
47 } | 76 } |
48 | 77 |
49 } // namespace content | 78 } // namespace content |
OLD | NEW |