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" | |
14 #include "content/browser/service_worker/service_worker_request_handler.h" | |
13 #include "content/common/navigation_params.h" | 15 #include "content/common/navigation_params.h" |
16 #include "content/common/service_worker/service_worker_types.h" | |
14 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/stream_handle.h" | 18 #include "content/public/browser/stream_handle.h" |
16 #include "content/public/common/resource_response.h" | 19 #include "content/public/common/resource_response.h" |
17 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
18 #include "net/url_request/redirect_info.h" | 21 #include "net/url_request/redirect_info.h" |
19 | 22 |
20 namespace content { | 23 namespace content { |
21 | 24 |
22 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( | 25 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( |
23 const base::WeakPtr<NavigationURLLoaderImpl>& loader) | 26 const base::WeakPtr<NavigationURLLoaderImpl>& loader, |
27 ServiceWorkerContext* service_worker_context) | |
24 : loader_(loader), | 28 : loader_(loader), |
25 resource_handler_(nullptr) { | 29 resource_handler_(nullptr), |
30 service_worker_context_( | |
31 static_cast<ServiceWorkerContextWrapper*>(service_worker_context)), | |
32 service_worker_handler_(nullptr) { | |
26 // This object is created on the UI thread but otherwise is accessed and | 33 // This object is created on the UI thread but otherwise is accessed and |
27 // deleted on the IO thread. | 34 // deleted on the IO thread. |
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
29 } | 36 } |
30 | 37 |
31 NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() { | 38 NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() { |
32 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
33 | 40 |
34 if (resource_handler_) | 41 if (resource_handler_) |
35 resource_handler_->Cancel(); | 42 resource_handler_->Cancel(); |
36 } | 43 } |
37 | 44 |
38 void NavigationURLLoaderImplCore::Start( | 45 void NavigationURLLoaderImplCore::Start( |
39 ResourceContext* resource_context, | 46 ResourceContext* resource_context, |
40 int frame_tree_node_id, | 47 int frame_tree_node_id, |
41 scoped_ptr<NavigationRequestInfo> request_info) { | 48 scoped_ptr<NavigationRequestInfo> request_info) { |
42 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
43 | 50 |
44 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
45 BrowserThread::UI, FROM_HERE, | 52 BrowserThread::UI, FROM_HERE, |
46 base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, | 53 base::Bind(&NavigationURLLoaderImpl::NotifyRequestStarted, loader_, |
47 base::TimeTicks::Now())); | 54 base::TimeTicks::Now())); |
48 | 55 |
49 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( | 56 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( |
michaeln
2015/09/23 19:18:17
Upon return from this function, the newly created
Fabrice (no longer in Chrome)
2015/09/30 17:32:08
This is now completely different.
| |
50 resource_context, frame_tree_node_id, | 57 resource_context, frame_tree_node_id, *request_info, this, |
51 *request_info, this); | 58 service_worker_context_.get()); |
52 } | 59 } |
53 | 60 |
54 void NavigationURLLoaderImplCore::FollowRedirect() { | 61 void NavigationURLLoaderImplCore::FollowRedirect() { |
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 62 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
56 | 63 |
57 if (resource_handler_) | 64 if (resource_handler_) |
58 resource_handler_->FollowRedirect(); | 65 resource_handler_->FollowRedirect(); |
59 } | 66 } |
60 | 67 |
68 void NavigationURLLoaderImplCore::SetServiceWorkerHandler( | |
69 ServiceWorkerRequestHandler* service_worker_handler) { | |
70 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
71 service_worker_handler_ = service_worker_handler; | |
72 } | |
61 | 73 |
62 void NavigationURLLoaderImplCore::NotifyRequestRedirected( | 74 void NavigationURLLoaderImplCore::NotifyRequestRedirected( |
63 const net::RedirectInfo& redirect_info, | 75 const net::RedirectInfo& redirect_info, |
64 ResourceResponse* response) { | 76 ResourceResponse* response) { |
65 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
66 | 78 |
67 // Make a copy of the ResourceResponse before it is passed to another thread. | 79 // Make a copy of the ResourceResponse before it is passed to another thread. |
68 // | 80 // |
69 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | 81 // TODO(davidben): This copy could be avoided if ResourceResponse weren't |
70 // reference counted and the loader stack passed unique ownership of the | 82 // reference counted and the loader stack passed unique ownership of the |
71 // response. https://crbug.com/416050 | 83 // response. https://crbug.com/416050 |
72 BrowserThread::PostTask( | 84 BrowserThread::PostTask( |
73 BrowserThread::UI, FROM_HERE, | 85 BrowserThread::UI, FROM_HERE, |
74 base::Bind(&NavigationURLLoaderImpl::NotifyRequestRedirected, loader_, | 86 base::Bind(&NavigationURLLoaderImpl::NotifyRequestRedirected, loader_, |
75 redirect_info, response->DeepCopy())); | 87 redirect_info, response->DeepCopy())); |
76 } | 88 } |
77 | 89 |
78 void NavigationURLLoaderImplCore::NotifyResponseStarted( | 90 void NavigationURLLoaderImplCore::NotifyResponseStarted( |
79 ResourceResponse* response, | 91 ResourceResponse* response, |
80 scoped_ptr<StreamHandle> body) { | 92 scoped_ptr<StreamHandle> body) { |
81 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
82 | 94 |
95 if (service_worker_handler_) { | |
96 scoped_ptr<ServiceWorkerProviderHost> provider_host = | |
97 service_worker_handler_->TakeBrowserProviderHost(); | |
98 if (provider_host) | |
99 service_worker_context_->RegisterBrowserProviderHost( | |
100 provider_host.Pass()); | |
101 } | |
102 | |
83 // If, by the time the task reaches the UI thread, |loader_| has already been | 103 // If, by the time the task reaches the UI thread, |loader_| has already been |
84 // destroyed, NotifyResponseStarted will not run. |body| will be destructed | 104 // destroyed, NotifyResponseStarted will not run. |body| will be destructed |
85 // and the request released at that point. | 105 // and the request released at that point. |
86 | 106 |
87 // Make a copy of the ResourceResponse before it is passed to another thread. | 107 // Make a copy of the ResourceResponse before it is passed to another thread. |
88 // | 108 // |
89 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | 109 // TODO(davidben): This copy could be avoided if ResourceResponse weren't |
90 // reference counted and the loader stack passed unique ownership of the | 110 // reference counted and the loader stack passed unique ownership of the |
91 // response. https://crbug.com/416050 | 111 // response. https://crbug.com/416050 |
92 BrowserThread::PostTask( | 112 BrowserThread::PostTask( |
93 BrowserThread::UI, FROM_HERE, | 113 BrowserThread::UI, FROM_HERE, |
94 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, | 114 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, |
95 response->DeepCopy(), base::Passed(&body))); | 115 response->DeepCopy(), base::Passed(&body))); |
96 } | 116 } |
97 | 117 |
98 void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, | 118 void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, |
99 int net_error) { | 119 int net_error) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
101 | 121 |
102 BrowserThread::PostTask( | 122 BrowserThread::PostTask( |
103 BrowserThread::UI, FROM_HERE, | 123 BrowserThread::UI, FROM_HERE, |
104 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | 124 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, |
105 in_cache, net_error)); | 125 in_cache, net_error)); |
106 } | 126 } |
107 | 127 |
108 } // namespace content | 128 } // namespace content |
OLD | NEW |