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 int frame_tree_node_id, | 45 int frame_tree_node_id, |
41 scoped_ptr<NavigationRequestInfo> request_info) { | 46 scoped_ptr<NavigationRequestInfo> request_info) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 47 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
43 | 48 |
44 BrowserThread::PostTask( | 49 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 50 BrowserThread::UI, FROM_HERE, |
46 base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, | 51 base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, |
47 base::TimeTicks::Now())); | 52 base::TimeTicks::Now())); |
48 | 53 |
49 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( | 54 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( |
50 resource_context, frame_tree_node_id, | 55 resource_context, *request_info, this, |
51 *request_info, this); | 56 service_worker_context_.get()); |
52 } | 57 } |
53 | 58 |
54 void NavigationURLLoaderImplCore::FollowRedirect() { | 59 void NavigationURLLoaderImplCore::FollowRedirect() { |
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
56 | 61 |
57 if (resource_handler_) | 62 if (resource_handler_) |
58 resource_handler_->FollowRedirect(); | 63 resource_handler_->FollowRedirect(); |
59 } | 64 } |
60 | 65 |
61 | |
62 void NavigationURLLoaderImplCore::NotifyRequestRedirected( | 66 void NavigationURLLoaderImplCore::NotifyRequestRedirected( |
63 const net::RedirectInfo& redirect_info, | 67 const net::RedirectInfo& redirect_info, |
64 ResourceResponse* response) { | 68 ResourceResponse* response) { |
65 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 69 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
66 | 70 |
67 // Make a copy of the ResourceResponse before it is passed to another thread. | 71 // Make a copy of the ResourceResponse before it is passed to another thread. |
68 // | 72 // |
69 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | 73 // TODO(davidben): This copy could be avoided if ResourceResponse weren't |
70 // reference counted and the loader stack passed unique ownership of the | 74 // reference counted and the loader stack passed unique ownership of the |
71 // response. https://crbug.com/416050 | 75 // response. https://crbug.com/416050 |
(...skipping 27 matching lines...) Expand all Loading... |
99 int net_error) { | 103 int net_error) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
101 | 105 |
102 BrowserThread::PostTask( | 106 BrowserThread::PostTask( |
103 BrowserThread::UI, FROM_HERE, | 107 BrowserThread::UI, FROM_HERE, |
104 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | 108 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, |
105 in_cache, net_error)); | 109 in_cache, net_error)); |
106 } | 110 } |
107 | 111 |
108 } // namespace content | 112 } // namespace content |
OLD | NEW |