Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/navigation_url_loader_network_service.h" | 5 #include "content/browser/loader/navigation_url_loader_network_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/browser/appcache/appcache_navigation_handle.h" | 11 #include "content/browser/appcache/appcache_navigation_handle.h" |
| 12 #include "content/browser/appcache/appcache_navigation_handle_core.h" | |
| 13 #include "content/browser/appcache/appcache_request_handler.h" | |
| 14 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 15 #include "content/browser/frame_host/frame_tree_node.h" | 13 #include "content/browser/frame_host/frame_tree_node.h" |
| 16 #include "content/browser/frame_host/navigation_request_info.h" | 14 #include "content/browser/frame_host/navigation_request_info.h" |
| 17 #include "content/browser/loader/navigation_resource_handler.h" | 15 #include "content/browser/loader/navigation_resource_handler.h" |
| 18 #include "content/browser/loader/navigation_resource_throttle.h" | 16 #include "content/browser/loader/navigation_resource_throttle.h" |
| 19 #include "content/browser/loader/navigation_url_loader_delegate.h" | 17 #include "content/browser/loader/navigation_url_loader_delegate.h" |
| 20 #include "content/browser/resource_context_impl.h" | 18 #include "content/browser/resource_context_impl.h" |
| 21 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 19 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
| 22 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " | 20 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " |
| 23 #include "content/browser/service_worker/service_worker_request_handler.h" | 21 #include "content/browser/service_worker/service_worker_request_handler.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 url_loader_factory_ptr = | 84 url_loader_factory_ptr = |
| 87 ServiceWorkerRequestHandler::InitializeForNavigationNetworkService( | 85 ServiceWorkerRequestHandler::InitializeForNavigationNetworkService( |
| 88 *resource_request, resource_context, | 86 *resource_request, resource_context, |
| 89 service_worker_navigation_handle_core, blob_storage_context, | 87 service_worker_navigation_handle_core, blob_storage_context, |
| 90 request_info->begin_params.skip_service_worker, resource_type, | 88 request_info->begin_params.skip_service_worker, resource_type, |
| 91 request_info->begin_params.request_context_type, frame_type, | 89 request_info->begin_params.request_context_type, frame_type, |
| 92 request_info->are_ancestors_secure, | 90 request_info->are_ancestors_secure, |
| 93 request_info->common_params.post_data, web_contents_getter); | 91 request_info->common_params.post_data, web_contents_getter); |
| 94 } | 92 } |
| 95 | 93 |
| 96 // TODO(scottmg): We need to rework AppCache to have it return a | |
| 97 // URLLoaderFactoryPtr[Info] here. We should also try to have it return | |
| 98 // synchronously in as many cases as possible (especially when there's no | |
| 99 // AppCache) to simplify and speed the common case. | |
| 100 if (false /*appcache_handle_core*/) { | |
| 101 AppCacheRequestHandler::InitializeForNavigationNetworkService( | |
| 102 std::move(resource_request), resource_context, appcache_handle_core, | |
| 103 resource_type, | |
| 104 base::Callback<void( | |
| 105 mojom::URLLoaderFactoryPtrInfo, | |
| 106 std::unique_ptr<ResourceRequest>)>() /* TODO(ananta) */); | |
| 107 return; | |
| 108 } | |
| 109 | |
| 110 // If we haven't gotten one from the above, then use the one the UI thread | 94 // If we haven't gotten one from the above, then use the one the UI thread |
| 111 // gave us, or otherwise fallback to the default. | 95 // gave us, or otherwise fallback to the default. |
| 112 mojom::URLLoaderFactory* factory; | 96 mojom::URLLoaderFactory* factory; |
| 113 if (url_loader_factory_ptr) { | 97 if (url_loader_factory_ptr) { |
| 114 factory = url_loader_factory_ptr.get(); | 98 factory = url_loader_factory_ptr.get(); |
| 115 } else { | 99 } else { |
| 116 if (factory_from_ui.is_valid()) { | 100 if (factory_from_ui.is_valid()) { |
| 117 url_loader_factory_ptr.Bind(std::move(factory_from_ui)); | 101 url_loader_factory_ptr.Bind(std::move(factory_from_ui)); |
| 118 factory = url_loader_factory_ptr.get(); | 102 factory = url_loader_factory_ptr.get(); |
| 119 } else { | 103 } else { |
| 120 factory = url_loader_factory_getter->GetNetworkFactory()->get(); | 104 if (appcache_handle_core) { |
| 105 factory = url_loader_factory_getter->GetAppCacheFactory()->get(); | |
| 106 } else { | |
| 107 factory = url_loader_factory_getter->GetNetworkFactory()->get(); | |
| 108 } | |
| 121 } | 109 } |
| 122 } | 110 } |
| 123 | 111 |
| 124 factory->CreateLoaderAndStart( | 112 factory->CreateLoaderAndStart( |
| 125 std::move(url_loader_request), 0 /* routing_id? */, 0 /* request_id? */, | 113 std::move(url_loader_request), 0 /* routing_id? */, 0 /* request_id? */, |
| 126 mojom::kURLLoadOptionSendSSLInfo, *resource_request, | 114 mojom::kURLLoadOptionSendSSLInfo, *resource_request, |
| 127 std::move(url_loader_client_to_pass)); | 115 std::move(url_loader_client_to_pass)); |
| 128 } | 116 } |
| 129 | 117 |
| 130 } // namespace | 118 } // namespace |
| 131 | 119 |
| 132 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( | 120 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( |
| 133 ResourceContext* resource_context, | 121 ResourceContext* resource_context, |
| 134 StoragePartition* storage_partition, | 122 StoragePartition* storage_partition, |
| 135 std::unique_ptr<NavigationRequestInfo> request_info, | 123 std::unique_ptr<NavigationRequestInfo> request_info, |
| 136 std::unique_ptr<NavigationUIData> navigation_ui_data, | 124 std::unique_ptr<NavigationUIData> navigation_ui_data, |
| 137 ServiceWorkerNavigationHandle* service_worker_navigation_handle, | 125 ServiceWorkerNavigationHandle* service_worker_navigation_handle, |
| 138 AppCacheNavigationHandle* appcache_handle, | 126 AppCacheNavigationHandle* appcache_handle, |
| 139 NavigationURLLoaderDelegate* delegate) | 127 NavigationURLLoaderDelegate* delegate) |
| 140 : delegate_(delegate), | 128 : delegate_(delegate), |
| 141 binding_(this), | 129 binding_(this), |
| 142 request_info_(std::move(request_info)) { | 130 request_info_(std::move(request_info)), |
| 131 request_id_(-1) { | |
| 143 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 144 | 133 |
| 145 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( | 134 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( |
| 146 "navigation", "Navigation timeToResponseStarted", this, | 135 "navigation", "Navigation timeToResponseStarted", this, |
| 147 request_info_->common_params.navigation_start, "FrameTreeNode id", | 136 request_info_->common_params.navigation_start, "FrameTreeNode id", |
| 148 request_info_->frame_tree_node_id); | 137 request_info_->frame_tree_node_id); |
| 149 | 138 |
| 150 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. | 139 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. |
| 151 auto new_request = base::MakeUnique<ResourceRequest>(); | 140 auto new_request = base::MakeUnique<ResourceRequest>(); |
| 152 | 141 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 mojom::URLLoaderFactoryPtrInfo factory_ptr_info; | 175 mojom::URLLoaderFactoryPtrInfo factory_ptr_info; |
| 187 | 176 |
| 188 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); | 177 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); |
| 189 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) != | 178 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) != |
| 190 schemes.end()) { | 179 schemes.end()) { |
| 191 FrameTreeNode* frame_tree_node = | 180 FrameTreeNode* frame_tree_node = |
| 192 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id); | 181 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id); |
| 193 factory_ptr_info = GetWebUIURLLoader(frame_tree_node).PassInterface(); | 182 factory_ptr_info = GetWebUIURLLoader(frame_tree_node).PassInterface(); |
| 194 } | 183 } |
| 195 | 184 |
| 185 request_id_--; | |
|
jam
2017/05/19 00:03:50
this class is created for each navigation request,
ananta
2017/05/19 00:23:13
Thanks. I made it a global
| |
| 186 | |
| 196 BrowserThread::PostTask( | 187 BrowserThread::PostTask( |
| 197 BrowserThread::IO, FROM_HERE, | 188 BrowserThread::IO, FROM_HERE, |
| 198 base::Bind(&PrepareNavigationStartOnIO, | 189 base::Bind(&PrepareNavigationStartOnIO, |
| 199 base::Passed(std::move(new_request)), resource_context, | 190 base::Passed(std::move(new_request)), resource_context, |
| 200 service_worker_navigation_handle | 191 service_worker_navigation_handle |
| 201 ? service_worker_navigation_handle->core() | 192 ? service_worker_navigation_handle->core() |
| 202 : nullptr, | 193 : nullptr, |
| 203 appcache_handle ? appcache_handle->core() : nullptr, | 194 appcache_handle ? appcache_handle->core() : nullptr, |
| 204 request_info_.get(), base::Passed(std::move(factory_ptr_info)), | 195 request_info_.get(), base::Passed(std::move(factory_ptr_info)), |
| 205 static_cast<StoragePartitionImpl*>(storage_partition) | 196 static_cast<StoragePartitionImpl*>(storage_partition) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 255 |
| 265 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, | 256 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, |
| 266 "&NavigationURLLoaderNetworkService", this, "success", | 257 "&NavigationURLLoaderNetworkService", this, "success", |
| 267 true); | 258 true); |
| 268 | 259 |
| 269 // Temporarily, we pass both a stream (null) and the data pipe to the | 260 // Temporarily, we pass both a stream (null) and the data pipe to the |
| 270 // delegate until PlzNavigate has shipped and we can be comfortable fully | 261 // delegate until PlzNavigate has shipped and we can be comfortable fully |
| 271 // switching to the data pipe. | 262 // switching to the data pipe. |
| 272 delegate_->OnResponseStarted(response_, nullptr, std::move(body), ssl_status_, | 263 delegate_->OnResponseStarted(response_, nullptr, std::move(body), ssl_status_, |
| 273 std::unique_ptr<NavigationData>(), | 264 std::unique_ptr<NavigationData>(), |
| 274 GlobalRequestID() /* request_id? */, | 265 GlobalRequestID(-1, request_id_), |
| 275 false /* is_download? */, false /* is_stream */); | 266 false /* is_download? */, false /* is_stream */); |
| 276 } | 267 } |
| 277 | 268 |
| 278 void NavigationURLLoaderNetworkService::OnComplete( | 269 void NavigationURLLoaderNetworkService::OnComplete( |
| 279 const ResourceRequestCompletionStatus& completion_status) { | 270 const ResourceRequestCompletionStatus& completion_status) { |
| 280 if (completion_status.error_code != net::OK) { | 271 if (completion_status.error_code != net::OK) { |
| 281 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", | 272 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", |
| 282 this, "&NavigationURLLoaderNetworkService", this, | 273 this, "&NavigationURLLoaderNetworkService", this, |
| 283 "success", false); | 274 "success", false); |
| 284 | 275 |
| 285 delegate_->OnRequestFailed(completion_status.exists_in_cache, | 276 delegate_->OnRequestFailed(completion_status.exists_in_cache, |
| 286 completion_status.error_code); | 277 completion_status.error_code); |
| 287 } | 278 } |
| 288 } | 279 } |
| 289 | 280 |
| 290 } // namespace content | 281 } // namespace content |
| OLD | NEW |