OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading |
6 | 6 |
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "content/browser/renderer_host/render_view_host_delegate.h" | 42 #include "content/browser/renderer_host/render_view_host_delegate.h" |
43 #include "content/browser/renderer_host/render_view_host_impl.h" | 43 #include "content/browser/renderer_host/render_view_host_impl.h" |
44 #include "content/browser/resource_context_impl.h" | 44 #include "content/browser/resource_context_impl.h" |
45 #include "content/browser/worker_host/worker_service_impl.h" | 45 #include "content/browser/worker_host/worker_service_impl.h" |
46 #include "content/common/resource_messages.h" | 46 #include "content/common/resource_messages.h" |
47 #include "content/common/ssl_status_serialization.h" | 47 #include "content/common/ssl_status_serialization.h" |
48 #include "content/common/view_messages.h" | 48 #include "content/common/view_messages.h" |
49 #include "content/public/browser/browser_thread.h" | 49 #include "content/public/browser/browser_thread.h" |
50 #include "content/public/browser/content_browser_client.h" | 50 #include "content/public/browser/content_browser_client.h" |
51 #include "content/public/browser/download_manager.h" | 51 #include "content/public/browser/download_manager.h" |
52 #include "content/public/browser/download_save_info.h" | |
52 #include "content/public/browser/global_request_id.h" | 53 #include "content/public/browser/global_request_id.h" |
53 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
54 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 55 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
55 #include "content/public/browser/resource_request_details.h" | 56 #include "content/public/browser/resource_request_details.h" |
56 #include "content/public/browser/resource_throttle.h" | 57 #include "content/public/browser/resource_throttle.h" |
57 #include "content/public/browser/user_metrics.h" | 58 #include "content/public/browser/user_metrics.h" |
58 #include "content/public/common/content_switches.h" | 59 #include "content/public/common/content_switches.h" |
59 #include "content/public/common/process_type.h" | 60 #include "content/public/common/process_type.h" |
60 #include "content/public/common/url_constants.h" | 61 #include "content/public/common/url_constants.h" |
61 #include "net/base/auth.h" | 62 #include "net/base/auth.h" |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 } | 492 } |
492 | 493 |
493 net::Error ResourceDispatcherHostImpl::BeginDownload( | 494 net::Error ResourceDispatcherHostImpl::BeginDownload( |
494 scoped_ptr<net::URLRequest> request, | 495 scoped_ptr<net::URLRequest> request, |
495 bool is_content_initiated, | 496 bool is_content_initiated, |
496 ResourceContext* context, | 497 ResourceContext* context, |
497 int child_id, | 498 int child_id, |
498 int route_id, | 499 int route_id, |
499 bool prefer_cache, | 500 bool prefer_cache, |
500 scoped_ptr<DownloadSaveInfo> save_info, | 501 scoped_ptr<DownloadSaveInfo> save_info, |
502 const std::string& last_modified, | |
503 const std::string& etag, | |
504 content::DownloadId download_id, | |
501 const DownloadStartedCallback& started_callback) { | 505 const DownloadStartedCallback& started_callback) { |
502 if (is_shutdown_) | 506 if (is_shutdown_) |
503 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); | 507 return CallbackAndReturn(started_callback, net::ERR_INSUFFICIENT_RESOURCES); |
504 | 508 |
505 const GURL& url = request->original_url(); | 509 const GURL& url = request->original_url(); |
506 | 510 |
507 // http://crbug.com/90971 | 511 // http://crbug.com/90971 |
508 char url_buf[128]; | 512 char url_buf[128]; |
509 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); | 513 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); |
510 base::debug::Alias(url_buf); | 514 base::debug::Alias(url_buf); |
(...skipping 18 matching lines...) Expand all Loading... | |
529 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> | 533 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
530 CanRequestURL(child_id, url)) { | 534 CanRequestURL(child_id, url)) { |
531 VLOG(1) << "Denied unauthorized download request for " | 535 VLOG(1) << "Denied unauthorized download request for " |
532 << url.possibly_invalid_spec(); | 536 << url.possibly_invalid_spec(); |
533 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); | 537 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); |
534 } | 538 } |
535 | 539 |
536 request_id_--; | 540 request_id_--; |
537 | 541 |
538 const net::URLRequestContext* request_context = context->GetRequestContext(); | 542 const net::URLRequestContext* request_context = context->GetRequestContext(); |
543 | |
asanka
2012/12/28 22:01:42
Can we move this to where we construct the URLRequ
Randy Smith (Not in Mondays)
2012/12/29 17:16:16
Chuckle. Sure. I was going to do a separate eval
| |
544 // If we're not at the beginning of the file, retrieve only the remaining | |
545 // portion. | |
546 if (save_info->offset > 0) { | |
547 request->SetExtraRequestHeaderByName( | |
548 "Range", | |
549 StringPrintf("bytes=%" PRId64 "-", save_info->offset), | |
550 true); | |
551 | |
552 // If we've asked for a range, we want to make sure that we only | |
553 // get that range if our current copy of the information is good. | |
554 if (!last_modified.empty()) { | |
555 request->SetExtraRequestHeaderByName("If-Unmodified-Since", | |
556 last_modified, | |
557 true); | |
558 } | |
559 if (!etag.empty()) { | |
560 request->SetExtraRequestHeaderByName("If-Match", etag, true); | |
561 } | |
562 } | |
563 | |
539 if (!request_context->job_factory()->IsHandledURL(url)) { | 564 if (!request_context->job_factory()->IsHandledURL(url)) { |
540 VLOG(1) << "Download request for unsupported protocol: " | 565 VLOG(1) << "Download request for unsupported protocol: " |
541 << url.possibly_invalid_spec(); | 566 << url.possibly_invalid_spec(); |
542 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); | 567 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); |
543 } | 568 } |
544 | 569 |
545 ResourceRequestInfoImpl* extra_info = | 570 ResourceRequestInfoImpl* extra_info = |
546 CreateRequestInfo(child_id, route_id, true, context); | 571 CreateRequestInfo(child_id, route_id, true, context); |
547 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. | 572 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
548 | 573 |
549 // From this point forward, the |DownloadResourceHandler| is responsible for | 574 // From this point forward, the |DownloadResourceHandler| is responsible for |
550 // |started_callback|. | 575 // |started_callback|. |
551 scoped_ptr<ResourceHandler> handler( | 576 scoped_ptr<ResourceHandler> handler( |
552 CreateResourceHandlerForDownload(request.get(), is_content_initiated, | 577 CreateResourceHandlerForDownload(request.get(), is_content_initiated, |
553 true, save_info.Pass(), | 578 true, download_id, save_info.Pass(), |
554 started_callback)); | 579 started_callback)); |
555 | 580 |
556 BeginRequestInternal(request.Pass(), handler.Pass()); | 581 BeginRequestInternal(request.Pass(), handler.Pass()); |
557 | 582 |
558 return net::OK; | 583 return net::OK; |
559 } | 584 } |
560 | 585 |
561 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( | 586 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( |
562 net::URLRequest* request) { | 587 net::URLRequest* request) { |
563 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 588 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
(...skipping 10 matching lines...) Expand all Loading... | |
574 FROM_HERE, | 599 FROM_HERE, |
575 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, | 600 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, |
576 base::Unretained(this))); | 601 base::Unretained(this))); |
577 } | 602 } |
578 | 603 |
579 scoped_ptr<ResourceHandler> | 604 scoped_ptr<ResourceHandler> |
580 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( | 605 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( |
581 net::URLRequest* request, | 606 net::URLRequest* request, |
582 bool is_content_initiated, | 607 bool is_content_initiated, |
583 bool must_download, | 608 bool must_download, |
609 DownloadId id, | |
584 scoped_ptr<DownloadSaveInfo> save_info, | 610 scoped_ptr<DownloadSaveInfo> save_info, |
585 const DownloadResourceHandler::OnStartedCallback& started_cb) { | 611 const DownloadResourceHandler::OnStartedCallback& started_cb) { |
586 scoped_ptr<ResourceHandler> handler( | 612 scoped_ptr<ResourceHandler> handler( |
587 new DownloadResourceHandler(request, started_cb, save_info.Pass())); | 613 new DownloadResourceHandler(id, request, started_cb, save_info.Pass())); |
588 if (delegate_) { | 614 if (delegate_) { |
589 const ResourceRequestInfo* request_info( | 615 const ResourceRequestInfo* request_info( |
590 ResourceRequestInfo::ForRequest(request)); | 616 ResourceRequestInfo::ForRequest(request)); |
591 | 617 |
592 ScopedVector<ResourceThrottle> throttles; | 618 ScopedVector<ResourceThrottle> throttles; |
593 delegate_->DownloadStarting( | 619 delegate_->DownloadStarting( |
594 request, request_info->GetContext(), request_info->GetChildID(), | 620 request, request_info->GetContext(), request_info->GetChildID(), |
595 request_info->GetRouteID(), request_info->GetRequestID(), | 621 request_info->GetRouteID(), request_info->GetRequestID(), |
596 is_content_initiated, must_download, &throttles); | 622 is_content_initiated, must_download, &throttles); |
597 if (!throttles.empty()) { | 623 if (!throttles.empty()) { |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 | 1748 |
1723 return i->second.get(); | 1749 return i->second.get(); |
1724 } | 1750 } |
1725 | 1751 |
1726 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, | 1752 ResourceLoader* ResourceDispatcherHostImpl::GetLoader(int child_id, |
1727 int request_id) const { | 1753 int request_id) const { |
1728 return GetLoader(GlobalRequestID(child_id, request_id)); | 1754 return GetLoader(GlobalRequestID(child_id, request_id)); |
1729 } | 1755 } |
1730 | 1756 |
1731 } // namespace content | 1757 } // namespace content |
OLD | NEW |