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

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

Issue 2902653002: Get main frame and subframe AppCache loads to work. (Closed)
Patch Set: Use weak pointers and DeleteSoon in the job and the factory Created 3 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_request_handler.h" 5 #include "content/browser/appcache/appcache_request_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "content/browser/appcache/appcache.h" 10 #include "content/browser/appcache/appcache.h"
11 #include "content/browser/appcache/appcache_backend_impl.h" 11 #include "content/browser/appcache/appcache_backend_impl.h"
12 #include "content/browser/appcache/appcache_host.h"
13 #include "content/browser/appcache/appcache_navigation_handle_core.h"
12 #include "content/browser/appcache/appcache_policy.h" 14 #include "content/browser/appcache/appcache_policy.h"
13 #include "content/browser/appcache/appcache_request.h" 15 #include "content/browser/appcache/appcache_request.h"
16 #include "content/browser/appcache/appcache_url_loader_factory.h"
17 #include "content/browser/appcache/appcache_url_loader_job.h"
18 #include "content/browser/appcache/appcache_url_loader_request.h"
14 #include "content/browser/appcache/appcache_url_request_job.h" 19 #include "content/browser/appcache/appcache_url_request_job.h"
15 #include "content/browser/service_worker/service_worker_request_handler.h" 20 #include "content/browser/service_worker/service_worker_request_handler.h"
21 #include "content/browser/url_loader_factory_getter.h"
16 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_job.h" 23 #include "net/url_request/url_request_job.h"
18 24
19 namespace content { 25 namespace content {
20 26
21 AppCacheRequestHandler::AppCacheRequestHandler( 27 AppCacheRequestHandler::AppCacheRequestHandler(
22 AppCacheHost* host, 28 AppCacheHost* host,
23 ResourceType resource_type, 29 ResourceType resource_type,
24 bool should_reset_appcache, 30 bool should_reset_appcache,
25 std::unique_ptr<AppCacheRequest> request) 31 std::unique_ptr<AppCacheRequest> request)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 222
217 void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess( 223 void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess(
218 int old_process_id) { 224 int old_process_id) {
219 if (!host_ || !host_for_cross_site_transfer_.get() || 225 if (!host_ || !host_for_cross_site_transfer_.get() ||
220 old_process_id != old_process_id_) { 226 old_process_id != old_process_id_) {
221 return; 227 return;
222 } 228 }
223 CompleteCrossSiteTransfer(old_process_id_, old_host_id_); 229 CompleteCrossSiteTransfer(old_process_id_, old_host_id_);
224 } 230 }
225 231
232 // static
233 std::unique_ptr<AppCacheRequestHandler>
234 AppCacheRequestHandler::InitializeForNavigationNetworkService(
235 const ResourceRequest& request,
236 AppCacheNavigationHandleCore* appcache_handle_core,
237 URLLoaderFactoryGetter* url_loader_factory_getter) {
238 std::unique_ptr<AppCacheRequestHandler> handler =
jam 2017/06/07 01:42:17 I thought an earlier patchset didn't create an app
michaeln 2017/06/07 02:53:45 to support redirects to appcached pages, we can't
ananta 2017/06/07 20:57:16 You are correct there. However we decided to go wi
239 appcache_handle_core->host()->CreateRequestHandler(
jam 2017/06/07 01:42:17 can't this return null?
michaeln 2017/06/07 02:53:45 yes, it can
ananta 2017/06/07 20:57:16 yes
240 AppCacheURLLoaderRequest::Create(request), request.resource_type,
241 request.should_reset_appcache);
242 handler->url_loader_factory_getter_ = url_loader_factory_getter;
243 return handler;
244 }
245
226 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { 246 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) {
227 storage()->CancelDelegateCallbacks(this); 247 storage()->CancelDelegateCallbacks(this);
228 host_ = NULL; // no need to RemoveObserver, the host is being deleted 248 host_ = NULL; // no need to RemoveObserver, the host is being deleted
229 249
230 // Since the host is being deleted, we don't have to complete any job 250 // Since the host is being deleted, we don't have to complete any job
231 // that is current running. It's destined for the bit bucket anyway. 251 // that is current running. It's destined for the bit bucket anyway.
232 if (job_.get()) { 252 if (job_.get()) {
233 job_->Kill(); 253 job_->Kill();
234 job_.reset(); 254 job_.reset();
235 } 255 }
(...skipping 21 matching lines...) Expand all
257 DCHECK(host_ && job_.get() && job_->IsWaiting()); 277 DCHECK(host_ && job_.get() && job_->IsWaiting());
258 DCHECK(entry.has_response_id()); 278 DCHECK(entry.has_response_id());
259 279
260 // Cache information about the response, for use by GetExtraResponseInfo. 280 // Cache information about the response, for use by GetExtraResponseInfo.
261 cache_id_ = cache_id; 281 cache_id_ = cache_id;
262 manifest_url_ = manifest_url; 282 manifest_url_ = manifest_url;
263 283
264 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) 284 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty())
265 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); 285 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url);
266 286
287 if (navigation_request_job_.get()) {
288 appcache_factory_ = AppCacheURLLoaderFactory::CreateURLLoaderFactory(
289 url_loader_factory_getter_.get(),
290 navigation_request_job_.release());
291 std::move(loader_factory_callback_).Run(appcache_factory_.get());
michaeln 2017/06/07 02:53:45 Do we still need to retain the appcache_factory_ i
ananta 2017/06/07 20:57:16 Will look into that. I am not sure her patch lande
michaeln 2017/06/08 02:54:00 This logic also could be hoisted into the AppCache
ananta 2017/06/08 05:58:39 Done.
292 }
267 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); 293 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback);
268 } 294 }
269 295
270 void AppCacheRequestHandler::DeliverErrorResponse() { 296 void AppCacheRequestHandler::DeliverErrorResponse() {
271 DCHECK(job_.get() && job_->IsWaiting()); 297 DCHECK(job_.get() && job_->IsWaiting());
272 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); 298 DCHECK_EQ(kAppCacheNoCacheId, cache_id_);
273 DCHECK(manifest_url_.is_empty()); 299 DCHECK(manifest_url_.is_empty());
274 job_->DeliverErrorResponse(); 300 job_->DeliverErrorResponse();
275 } 301 }
276 302
277 void AppCacheRequestHandler::DeliverNetworkResponse() { 303 void AppCacheRequestHandler::DeliverNetworkResponse() {
278 DCHECK(job_.get() && job_->IsWaiting()); 304 DCHECK(job_.get() && job_->IsWaiting());
279 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); 305 DCHECK_EQ(kAppCacheNoCacheId, cache_id_);
280 DCHECK(manifest_url_.is_empty()); 306 DCHECK(manifest_url_.is_empty());
307
308 // In network service land, if we are processing a navigation request, we
309 // need to inform the loader callback that we are not going to handle this
310 // request.
311 if (navigation_request_job_.get()) {
michaeln 2017/06/08 02:54:00 This bit of logic to call the loadercallback could
ananta 2017/06/08 05:58:39 Done.
312 std::move(loader_factory_callback_).Run(nullptr);
313 navigation_request_job_.reset(nullptr);
314 return;
315 }
316
281 job_->DeliverNetworkResponse(); 317 job_->DeliverNetworkResponse();
282 } 318 }
283 319
284 void AppCacheRequestHandler::OnPrepareToRestart() { 320 void AppCacheRequestHandler::OnPrepareToRestart() {
285 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); 321 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound());
286 322
287 // Any information about the source of the response is no longer relevant. 323 // Any information about the source of the response is no longer relevant.
288 cache_id_ = kAppCacheNoCacheId; 324 cache_id_ = kAppCacheNoCacheId;
289 manifest_url_ = GURL(); 325 manifest_url_ = GURL();
290 326
(...skipping 18 matching lines...) Expand all
309 // Main-resource handling ---------------------------------------------- 345 // Main-resource handling ----------------------------------------------
310 346
311 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( 347 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
312 net::NetworkDelegate* network_delegate) { 348 net::NetworkDelegate* network_delegate) {
313 DCHECK(!job_.get()); 349 DCHECK(!job_.get());
314 DCHECK(host_); 350 DCHECK(host_);
315 351
316 // If a page falls into the scope of a ServiceWorker, any matching AppCaches 352 // If a page falls into the scope of a ServiceWorker, any matching AppCaches
317 // should be ignored. This depends on the ServiceWorker handler being invoked 353 // should be ignored. This depends on the ServiceWorker handler being invoked
318 // prior to the AppCache handler. 354 // prior to the AppCache handler.
319 if (ServiceWorkerRequestHandler::IsControlledByServiceWorker( 355 // TODO(ananta)
356 // We need to handle this for AppCache requests initiated for the network
357 // service
358 if (request_->GetURLRequest() &&
359 ServiceWorkerRequestHandler::IsControlledByServiceWorker(
320 request_->GetURLRequest())) { 360 request_->GetURLRequest())) {
321 host_->enable_cache_selection(false); 361 host_->enable_cache_selection(false);
322 return nullptr; 362 return nullptr;
323 } 363 }
324 364
365 if (storage()->IsInitialized() &&
366 service_->storage()->usage_map()->find(request_->GetURL().GetOrigin()) ==
michaeln 2017/06/07 02:53:45 @jam, this is where the origin test goes
367 service_->storage()->usage_map()->end()) {
368 return nullptr;
369 }
370
325 host_->enable_cache_selection(true); 371 host_->enable_cache_selection(true);
326 372
327 const AppCacheHost* spawning_host = 373 const AppCacheHost* spawning_host =
328 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? 374 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ?
329 host_ : host_->GetSpawningHost(); 375 host_ : host_->GetSpawningHost();
330 GURL preferred_manifest_url = spawning_host ? 376 GURL preferred_manifest_url = spawning_host ?
331 spawning_host->preferred_manifest_url() : GURL(); 377 spawning_host->preferred_manifest_url() : GURL();
332 378
333 // We may have to wait for our storage query to complete, but 379 // We may have to wait for our storage query to complete, but
334 // this query can also complete syncrhonously. 380 // this query can also complete syncrhonously.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 542
497 if (!host_->associated_cache() || 543 if (!host_->associated_cache() ||
498 !host_->associated_cache()->is_complete()) { 544 !host_->associated_cache()->is_complete()) {
499 DeliverNetworkResponse(); 545 DeliverNetworkResponse();
500 return; 546 return;
501 } 547 }
502 548
503 ContinueMaybeLoadSubResource(); 549 ContinueMaybeLoadSubResource();
504 } 550 }
505 551
552 void AppCacheRequestHandler::MaybeCreateLoaderFactory(
553 const ResourceRequest& resource_request,
554 ResourceContext* resource_context,
555 LoaderFactoryCallback callback) {
556 navigation_request_job_ = MaybeLoadMainResource(nullptr);
557 if (!navigation_request_job_.get()) {
558 std::move(callback).Run(nullptr);
559 return;
560 }
561 navigation_request_job_->AsURLLoaderJob()->SetURLLoaderFactoryGetter(
562 url_loader_factory_getter_.get());
563 loader_factory_callback_ = std::move(callback);
michaeln 2017/06/08 02:54:00 This datamember could go inside the AppCacheUrlLoa
ananta 2017/06/08 05:58:39 Done.
564 }
565
506 } // namespace content 566 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698