Chromium Code Reviews| 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) { | |
|
kinuko
2016/10/13 05:36:00
sorry, could you teach me when this could happen?
tzik
2016/10/13 06:31:26
This can be called from the dtor of SyncResourceHa
kinuko
2016/10/13 11:39:01
I see thanks. Maybe worth commenting that result
tzik
2016/10/14 08:02:31
Done.
| |
| 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 SyncLoadResult result; | |
|
kinuko
2016/10/13 05:36:00
Do we need this line?
tzik
2016/10/13 06:31:26
Oops. No, it's needed. Removed.
| |
| 65 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
| 66 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request, | |
| 67 resource_message_filter_.get(), | |
| 68 base::Bind(&DispatchSyncLoadResult, callback)); | |
| 69 } | |
| 70 | |
| 41 void URLLoaderFactoryImpl::Create( | 71 void URLLoaderFactoryImpl::Create( |
| 42 scoped_refptr<ResourceMessageFilter> filter, | 72 scoped_refptr<ResourceMessageFilter> filter, |
| 43 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { | 73 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 44 mojo::MakeStrongBinding( | 74 mojo::MakeStrongBinding( |
| 45 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), | 75 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), |
| 46 std::move(request)); | 76 std::move(request)); |
| 47 } | 77 } |
| 48 | 78 |
| 49 } // namespace content | 79 } // namespace content |
| OLD | NEW |