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