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_url_loader_factory.h" | |
12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 13 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
13 #include "content/browser/frame_host/frame_tree_node.h" | 14 #include "content/browser/frame_host/frame_tree_node.h" |
14 #include "content/browser/frame_host/navigation_request_info.h" | 15 #include "content/browser/frame_host/navigation_request_info.h" |
15 #include "content/browser/loader/navigation_resource_handler.h" | 16 #include "content/browser/loader/navigation_resource_handler.h" |
16 #include "content/browser/loader/navigation_resource_throttle.h" | 17 #include "content/browser/loader/navigation_resource_throttle.h" |
17 #include "content/browser/loader/navigation_url_loader_delegate.h" | 18 #include "content/browser/loader/navigation_url_loader_delegate.h" |
18 #include "content/browser/loader/url_loader_request_handler.h" | 19 #include "content/browser/loader/url_loader_request_handler.h" |
19 #include "content/browser/resource_context_impl.h" | 20 #include "content/browser/resource_context_impl.h" |
20 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 21 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
21 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " | 22 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 service_worker_navigation_handle_core, blob_storage_context, | 123 service_worker_navigation_handle_core, blob_storage_context, |
123 request_info->begin_params.skip_service_worker, resource_type, | 124 request_info->begin_params.skip_service_worker, resource_type, |
124 request_info->begin_params.request_context_type, frame_type, | 125 request_info->begin_params.request_context_type, frame_type, |
125 request_info->are_ancestors_secure, | 126 request_info->are_ancestors_secure, |
126 request_info->common_params.post_data, web_contents_getter); | 127 request_info->common_params.post_data, web_contents_getter); |
127 if (service_worker_handler) | 128 if (service_worker_handler) |
128 handlers_.push_back(std::move(service_worker_handler)); | 129 handlers_.push_back(std::move(service_worker_handler)); |
129 } | 130 } |
130 | 131 |
131 if (appcache_handle_core) { | 132 if (appcache_handle_core) { |
132 // TODO: add appcache code here. | 133 std::unique_ptr<URLLoaderRequestHandler> appcache_handler = |
134 AppCacheURLLoaderFactory::CreateRequestHandler( | |
michaeln
2017/06/02 01:17:59
I'd vote to maintain as much symmetry with S/W as
ananta
2017/06/03 01:55:55
Done.
| |
135 appcache_handle_core, url_loader_factory_getter.get()); | |
136 if (appcache_handler) | |
137 handlers_.push_back(std::move(appcache_handler)); | |
133 } | 138 } |
134 | 139 |
135 DCHECK(!network_factory_); | 140 DCHECK(!network_factory_); |
136 network_factory_ = url_loader_factory_getter->GetNetworkFactory()->get(); | 141 network_factory_ = url_loader_factory_getter->GetNetworkFactory()->get(); |
137 | 142 |
138 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr)); | 143 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr)); |
139 } | 144 } |
140 | 145 |
141 // This could be called multiple times. | 146 // This could be called multiple times. |
142 void Restart(mojom::URLLoaderRequest url_loader_request, | 147 void Restart(mojom::URLLoaderRequest url_loader_request, |
143 mojom::URLLoaderClientPtr url_loader_client_ptr) { | 148 mojom::URLLoaderClientPtr url_loader_client_ptr) { |
144 url_loader_request_ = std::move(url_loader_request); | 149 url_loader_request_ = std::move(url_loader_request); |
145 url_loader_client_ptr_ = std::move(url_loader_client_ptr); | 150 url_loader_client_ptr_ = std::move(url_loader_client_ptr); |
146 handler_index_ = 0; | 151 handler_index_ = 0; |
147 MaybeStartLoader(nullptr); | 152 MaybeStartLoader(nullptr); |
148 } | 153 } |
149 | 154 |
150 void MaybeStartLoader(mojom::URLLoaderFactory* factory) { | 155 void MaybeStartLoader(mojom::URLLoaderFactory* factory) { |
151 DCHECK(url_loader_client_ptr_.is_bound()); | 156 DCHECK(url_loader_client_ptr_.is_bound()); |
152 | 157 |
153 if (factory) { | 158 if (factory) { |
154 factory->CreateLoaderAndStart( | 159 factory->CreateLoaderAndStart( |
155 std::move(url_loader_request_), 0 /* routing_id? */, | 160 std::move(url_loader_request_), 0 /* routing_id? */, |
156 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, | 161 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, |
157 *resource_request_, std::move(url_loader_client_ptr_)); | 162 *resource_request_, std::move(url_loader_client_ptr_)); |
158 return; | 163 return; |
159 } | 164 } |
160 | 165 |
161 if (handler_index_ < handlers_.size()) { | 166 if (handler_index_ < handlers_.size()) { |
162 handlers_[handler_index_++]->MaybeCreateLoaderFactory( | 167 handlers_[handler_index_++]->MaybeCreateLoaderFactory( |
michaeln
2017/06/02 01:17:59
This method is a whole lot like AppCacheRequestHan
ananta
2017/06/03 01:55:55
Thanks done. It made the code a lot simpler.
| |
163 *resource_request_, resource_context_, | 168 *resource_request_, resource_context_, |
164 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader, | 169 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader, |
165 base::Unretained(this))); | 170 base::Unretained(this))); |
166 return; | 171 return; |
167 } | 172 } |
168 | 173 |
169 DCHECK_EQ(handlers_.size(), handler_index_); | 174 DCHECK_EQ(handlers_.size(), handler_index_); |
170 DCHECK(network_factory_ != nullptr); | 175 DCHECK(network_factory_ != nullptr); |
171 MaybeStartLoader(network_factory_); | 176 MaybeStartLoader(network_factory_); |
172 } | 177 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", | 355 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", |
351 this, "&NavigationURLLoaderNetworkService", this, | 356 this, "&NavigationURLLoaderNetworkService", this, |
352 "success", false); | 357 "success", false); |
353 | 358 |
354 delegate_->OnRequestFailed(completion_status.exists_in_cache, | 359 delegate_->OnRequestFailed(completion_status.exists_in_cache, |
355 completion_status.error_code); | 360 completion_status.error_code); |
356 } | 361 } |
357 } | 362 } |
358 | 363 |
359 } // namespace content | 364 } // namespace content |
OLD | NEW |