| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl_core.h" | 5 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/navigation_request_info.h" | 10 #include "content/browser/frame_host/navigation_request_info.h" |
| 11 #include "content/browser/loader/navigation_resource_handler.h" | 11 #include "content/browser/loader/navigation_resource_handler.h" |
| 12 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 12 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/common/navigation_params.h" | 14 #include "content/common/navigation_params.h" |
| 15 #include "content/common/service_worker/service_worker_types.h" |
| 14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/stream_handle.h" | 17 #include "content/public/browser/stream_handle.h" |
| 16 #include "content/public/common/resource_response.h" | 18 #include "content/public/common/resource_response.h" |
| 17 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 18 #include "net/url_request/redirect_info.h" | 20 #include "net/url_request/redirect_info.h" |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( | 24 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( |
| 23 const base::WeakPtr<NavigationURLLoaderImpl>& loader) | 25 const base::WeakPtr<NavigationURLLoaderImpl>& loader, |
| 26 ServiceWorkerContext* service_worker_context) |
| 24 : loader_(loader), | 27 : loader_(loader), |
| 25 resource_handler_(nullptr) { | 28 resource_handler_(nullptr), |
| 29 service_worker_context_( |
| 30 static_cast<ServiceWorkerContextWrapper*>(service_worker_context)) { |
| 26 // This object is created on the UI thread but otherwise is accessed and | 31 // This object is created on the UI thread but otherwise is accessed and |
| 27 // deleted on the IO thread. | 32 // deleted on the IO thread. |
| 28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 33 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 29 } | 34 } |
| 30 | 35 |
| 31 NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() { | 36 NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 37 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 33 | 38 |
| 34 if (resource_handler_) | 39 if (resource_handler_) |
| 35 resource_handler_->Cancel(); | 40 resource_handler_->Cancel(); |
| 36 } | 41 } |
| 37 | 42 |
| 38 void NavigationURLLoaderImplCore::Start( | 43 void NavigationURLLoaderImplCore::Start( |
| 39 ResourceContext* resource_context, | 44 ResourceContext* resource_context, |
| 40 scoped_ptr<NavigationRequestInfo> request_info) { | 45 scoped_ptr<NavigationRequestInfo> request_info) { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 46 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 42 | 47 |
| 43 BrowserThread::PostTask( | 48 BrowserThread::PostTask( |
| 44 BrowserThread::UI, FROM_HERE, | 49 BrowserThread::UI, FROM_HERE, |
| 45 base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, | 50 base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, |
| 46 base::TimeTicks::Now())); | 51 base::TimeTicks::Now())); |
| 47 | 52 |
| 48 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( | 53 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( |
| 49 resource_context, *request_info, this); | 54 resource_context, *request_info, this, service_worker_context_); |
| 50 } | 55 } |
| 51 | 56 |
| 52 void NavigationURLLoaderImplCore::FollowRedirect() { | 57 void NavigationURLLoaderImplCore::FollowRedirect() { |
| 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 54 | 59 |
| 55 if (resource_handler_) | 60 if (resource_handler_) |
| 56 resource_handler_->FollowRedirect(); | 61 resource_handler_->FollowRedirect(); |
| 57 } | 62 } |
| 58 | 63 |
| 59 | |
| 60 void NavigationURLLoaderImplCore::NotifyRequestRedirected( | 64 void NavigationURLLoaderImplCore::NotifyRequestRedirected( |
| 61 const net::RedirectInfo& redirect_info, | 65 const net::RedirectInfo& redirect_info, |
| 62 ResourceResponse* response) { | 66 ResourceResponse* response) { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 67 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 64 | 68 |
| 65 // Make a copy of the ResourceResponse before it is passed to another thread. | 69 // Make a copy of the ResourceResponse before it is passed to another thread. |
| 66 // | 70 // |
| 67 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | 71 // TODO(davidben): This copy could be avoided if ResourceResponse weren't |
| 68 // reference counted and the loader stack passed unique ownership of the | 72 // reference counted and the loader stack passed unique ownership of the |
| 69 // response. https://crbug.com/416050 | 73 // response. https://crbug.com/416050 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 97 int net_error) { | 101 int net_error) { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 99 | 103 |
| 100 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 101 BrowserThread::UI, FROM_HERE, | 105 BrowserThread::UI, FROM_HERE, |
| 102 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | 106 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, |
| 103 in_cache, net_error)); | 107 in_cache, net_error)); |
| 104 } | 108 } |
| 105 | 109 |
| 106 } // namespace content | 110 } // namespace content |
| OLD | NEW |