Chromium Code Reviews| 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_navigation_handle_core.h " | 13 #include "content/browser/service_worker/service_worker_navigation_handle_core.h " |
| 14 #include "content/common/navigation_params.h" | 14 #include "content/common/navigation_params.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_data.h" | |
| 16 #include "content/public/browser/stream_handle.h" | 17 #include "content/public/browser/stream_handle.h" |
| 17 #include "content/public/common/resource_response.h" | 18 #include "content/public/common/resource_response.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/url_request/redirect_info.h" | 20 #include "net/url_request/redirect_info.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( | 24 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( |
| 24 const base::WeakPtr<NavigationURLLoaderImpl>& loader) | 25 const base::WeakPtr<NavigationURLLoaderImpl>& loader) |
| 25 : loader_(loader), | 26 : loader_(loader), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 // TODO(carlosk): extend this trace to support non-PlzNavigate navigations. | 88 // TODO(carlosk): extend this trace to support non-PlzNavigate navigations. |
| 88 // For the trace below we're using the NavigationURLLoaderImplCore as the | 89 // For the trace below we're using the NavigationURLLoaderImplCore as the |
| 89 // async trace id and reporting the new redirect URL as a parameter. | 90 // async trace id and reporting the new redirect URL as a parameter. |
| 90 TRACE_EVENT_ASYNC_BEGIN2("navigation", "Navigation redirectDelay", this, | 91 TRACE_EVENT_ASYNC_BEGIN2("navigation", "Navigation redirectDelay", this, |
| 91 "&NavigationURLLoaderImplCore", this, "New URL", | 92 "&NavigationURLLoaderImplCore", this, "New URL", |
| 92 redirect_info.new_url.spec()); | 93 redirect_info.new_url.spec()); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void NavigationURLLoaderImplCore::NotifyResponseStarted( | 96 void NavigationURLLoaderImplCore::NotifyResponseStarted( |
| 96 ResourceResponse* response, | 97 ResourceResponse* response, |
| 97 std::unique_ptr<StreamHandle> body) { | 98 std::unique_ptr<StreamHandle> body, |
| 99 NavigationData* navigation_data) { | |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 99 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); | 101 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); |
| 100 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, | 102 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, |
| 101 "&NavigationURLLoaderImplCore", this, "success", true); | 103 "&NavigationURLLoaderImplCore", this, "success", true); |
| 102 | 104 |
| 105 // Clone the embedder NavigationData before moving it to the UI thread. | |
| 106 std::unique_ptr<NavigationData> clone = | |
| 107 navigation_data ? navigation_data->Clone() : nullptr; | |
|
nasko
2016/04/26 20:18:40
Empty line after this and before next comment.
RyanSturm
2016/04/27 23:27:47
Done.
| |
| 103 // If, by the time the task reaches the UI thread, |loader_| has already been | 108 // If, by the time the task reaches the UI thread, |loader_| has already been |
| 104 // destroyed, NotifyResponseStarted will not run. |body| will be destructed | 109 // destroyed, NotifyResponseStarted will not run. |body| will be destructed |
| 105 // and the request released at that point. | 110 // and the request released at that point. |
| 106 | 111 |
| 107 // Make a copy of the ResourceResponse before it is passed to another thread. | 112 // Make a copy of the ResourceResponse before it is passed to another thread. |
| 108 // | 113 // |
| 109 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | 114 // TODO(davidben): This copy could be avoided if ResourceResponse weren't |
| 110 // reference counted and the loader stack passed unique ownership of the | 115 // reference counted and the loader stack passed unique ownership of the |
| 111 // response. https://crbug.com/416050 | 116 // response. https://crbug.com/416050 |
| 112 BrowserThread::PostTask( | 117 BrowserThread::PostTask( |
| 113 BrowserThread::UI, FROM_HERE, | 118 BrowserThread::UI, FROM_HERE, |
| 114 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, | 119 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, |
| 115 response->DeepCopy(), base::Passed(&body))); | 120 response->DeepCopy(), base::Passed(&body), |
| 121 base::Passed(&clone))); | |
| 116 } | 122 } |
| 117 | 123 |
| 118 void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, | 124 void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, |
| 119 int net_error) { | 125 int net_error) { |
| 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 121 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); | 127 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); |
| 122 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, | 128 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, |
| 123 "&NavigationURLLoaderImplCore", this, "success", | 129 "&NavigationURLLoaderImplCore", this, "success", |
| 124 false); | 130 false); |
| 125 | 131 |
| 126 BrowserThread::PostTask( | 132 BrowserThread::PostTask( |
| 127 BrowserThread::UI, FROM_HERE, | 133 BrowserThread::UI, FROM_HERE, |
| 128 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | 134 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, |
| 129 in_cache, net_error)); | 135 in_cache, net_error)); |
| 130 } | 136 } |
| 131 | 137 |
| 132 } // namespace content | 138 } // namespace content |
| OLD | NEW |