Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: content/browser/appcache/appcache_url_loader_job.cc

Issue 2982363002: Add support for fallback content for the frame. This includes main and subframes. (Closed)
Patch Set: Address review comments. Add the fallback function as a parameter to LoaderCallback Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/appcache/appcache_url_loader_job.h" 5 #include "content/browser/appcache/appcache_url_loader_job.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "content/browser/appcache/appcache_histograms.h" 8 #include "content/browser/appcache/appcache_histograms.h"
9 #include "content/browser/appcache/appcache_subresource_url_factory.h" 9 #include "content/browser/appcache/appcache_subresource_url_factory.h"
10 #include "content/browser/appcache/appcache_url_loader_request.h" 10 #include "content/browser/appcache/appcache_url_loader_request.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 delivery_type_ = NETWORK_DELIVERY; 68 delivery_type_ = NETWORK_DELIVERY;
69 69
70 AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() - 70 AppCacheHistograms::AddNetworkJobStartDelaySample(base::TimeTicks::Now() -
71 start_time_tick_); 71 start_time_tick_);
72 72
73 if (IsResourceTypeFrame(request_.resource_type)) { 73 if (IsResourceTypeFrame(request_.resource_type)) {
74 DCHECK(!main_resource_loader_callback_.is_null()); 74 DCHECK(!main_resource_loader_callback_.is_null());
75 // In network service land, if we are processing a navigation request, we 75 // In network service land, if we are processing a navigation request, we
76 // need to inform the loader callback that we are not going to handle this 76 // need to inform the loader callback that we are not going to handle this
77 // request. The loader callback is valid only for navigation requests. 77 // request. The loader callback is valid only for navigation requests.
78 std::move(main_resource_loader_callback_).Run(StartLoaderCallback()); 78 std::move(main_resource_loader_callback_)
79 .Run(StartLoaderCallback(), std::move(main_resource_fallback_handler_));
79 } else { 80 } else {
80 mojom::URLLoaderClientPtr client_ptr; 81 mojom::URLLoaderClientPtr client_ptr;
81 network_loader_client_binding_.Bind(mojo::MakeRequest(&client_ptr)); 82 network_loader_client_binding_.Bind(mojo::MakeRequest(&client_ptr));
82 83
83 default_url_loader_factory_getter_->GetNetworkFactory() 84 default_url_loader_factory_getter_->GetNetworkFactory()
84 ->get() 85 ->get()
85 ->CreateLoaderAndStart( 86 ->CreateLoaderAndStart(
86 mojo::MakeRequest(&network_loader_), 87 mojo::MakeRequest(&network_loader_),
87 subresource_load_info_->routing_id, 88 subresource_load_info_->routing_id,
88 subresource_load_info_->request_id, subresource_load_info_->options, 89 subresource_load_info_->request_id, subresource_load_info_->options,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 subresource_load_info_ = std::move(subresource_load_info); 217 subresource_load_info_ = std::move(subresource_load_info);
217 218
218 binding_.Bind(std::move(subresource_load_info_->url_loader_request)); 219 binding_.Bind(std::move(subresource_load_info_->url_loader_request));
219 binding_.set_connection_error_handler(base::Bind( 220 binding_.set_connection_error_handler(base::Bind(
220 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); 221 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this)));
221 222
222 client_ = std::move(subresource_load_info_->client); 223 client_ = std::move(subresource_load_info_->client);
223 default_url_loader_factory_getter_ = default_url_loader; 224 default_url_loader_factory_getter_ = default_url_loader;
224 } 225 }
225 226
227 void AppCacheURLLoaderJob::BindRequest(mojom::URLLoaderClientPtr client,
228 mojom::URLLoaderRequest request) {
229 DCHECK(!binding_.is_bound());
230 binding_.Bind(std::move(request));
231
232 client_ = std::move(client);
233
234 binding_.set_connection_error_handler(base::Bind(
235 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this)));
236 }
237
226 void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request, 238 void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request,
227 mojom::URLLoaderClientPtr client) { 239 mojom::URLLoaderClientPtr client) {
228 DCHECK(!binding_.is_bound()); 240 BindRequest(std::move(client), std::move(request));
229 binding_.Bind(std::move(request));
230
231 binding_.set_connection_error_handler(base::Bind(
232 &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this)));
233
234 client_ = std::move(client);
235
236 // Send the cached AppCacheResponse if any. 241 // Send the cached AppCacheResponse if any.
237 if (info_.get()) 242 if (info_.get())
238 SendResponseInfo(); 243 SendResponseInfo();
239 } 244 }
240 245
241 AppCacheURLLoaderJob::AppCacheURLLoaderJob( 246 AppCacheURLLoaderJob::AppCacheURLLoaderJob(
242 const ResourceRequest& request, 247 const ResourceRequest& request,
243 AppCacheURLLoaderRequest* appcache_request, 248 AppCacheURLLoaderRequest* appcache_request,
244 AppCacheStorage* storage) 249 AppCacheStorage* storage)
245 : request_(request), 250 : request_(request),
(...skipping 18 matching lines...) Expand all
264 } 269 }
265 270
266 if (response_info) { 271 if (response_info) {
267 info_ = response_info; 272 info_ = response_info;
268 reader_.reset( 273 reader_.reset(
269 storage_->CreateResponseReader(manifest_url_, entry_.response_id())); 274 storage_->CreateResponseReader(manifest_url_, entry_.response_id()));
270 275
271 if (is_range_request()) 276 if (is_range_request())
272 SetupRangeResponse(); 277 SetupRangeResponse();
273 278
274 if (IsResourceTypeFrame(request_.resource_type)) { 279 if (IsResourceTypeFrame(request_.resource_type) &&
280 main_resource_loader_callback_) {
275 DCHECK(!main_resource_loader_callback_.is_null()); 281 DCHECK(!main_resource_loader_callback_.is_null());
276 std::move(main_resource_loader_callback_) 282 std::move(main_resource_loader_callback_)
277 .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this))); 283 .Run(base::Bind(&AppCacheURLLoaderJob::Start, StaticAsWeakPtr(this)),
284 ResponseFallback());
278 } 285 }
279 286
280 response_body_stream_ = std::move(data_pipe_.producer_handle); 287 response_body_stream_ = std::move(data_pipe_.producer_handle);
281 288
282 // TODO(ananta) 289 // TODO(ananta)
283 // Move the asynchronous reading and mojo pipe handling code to a helper 290 // Move the asynchronous reading and mojo pipe handling code to a helper
284 // class. That would also need a change to BlobURLLoader. 291 // class. That would also need a change to BlobURLLoader.
285 292
286 // Wait for the data pipe to be ready to accept data. 293 // Wait for the data pipe to be ready to accept data.
287 writable_handle_watcher_.Watch( 294 writable_handle_watcher_.Watch(
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 458 }
452 459
453 void AppCacheURLLoaderJob::DisconnectFromNetworkLoader() { 460 void AppCacheURLLoaderJob::DisconnectFromNetworkLoader() {
454 // Close the pipe to the network loader as we are delivering a fallback 461 // Close the pipe to the network loader as we are delivering a fallback
455 // response to the client. 462 // response to the client.
456 network_loader_client_binding_.Close(); 463 network_loader_client_binding_.Close();
457 network_loader_ = nullptr; 464 network_loader_ = nullptr;
458 } 465 }
459 466
460 } // namespace content 467 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698