| 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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // TODO(carlosk): extend this trace to support non-PlzNavigate navigations. | 80 // TODO(carlosk): extend this trace to support non-PlzNavigate navigations. |
| 81 // For the trace below we're using the NavigationURLLoaderImplCore as the | 81 // For the trace below we're using the NavigationURLLoaderImplCore as the |
| 82 // async trace id and reporting the new redirect URL as a parameter. | 82 // async trace id and reporting the new redirect URL as a parameter. |
| 83 TRACE_EVENT_ASYNC_BEGIN2("navigation", "Navigation redirectDelay", this, | 83 TRACE_EVENT_ASYNC_BEGIN2("navigation", "Navigation redirectDelay", this, |
| 84 "&NavigationURLLoaderImplCore", this, "New URL", | 84 "&NavigationURLLoaderImplCore", this, "New URL", |
| 85 redirect_info.new_url.spec()); | 85 redirect_info.new_url.spec()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void NavigationURLLoaderImplCore::NotifyResponseStarted( | 88 void NavigationURLLoaderImplCore::NotifyResponseStarted( |
| 89 ResourceResponse* response, | 89 ResourceResponse* response, |
| 90 scoped_ptr<StreamHandle> body) { | 90 mojo::ScopedDataPipeConsumerHandle data_consumer_handle, |
| 91 int request_id) { |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 92 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 92 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); | 93 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); |
| 93 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, | 94 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, |
| 94 "&NavigationURLLoaderImplCore", this, "success", true); | 95 "&NavigationURLLoaderImplCore", this, "success", true); |
| 95 | 96 |
| 96 // If, by the time the task reaches the UI thread, |loader_| has already been | 97 // If, by the time the task reaches the UI thread, |loader_| has already been |
| 97 // destroyed, NotifyResponseStarted will not run. |body| will be destructed | 98 // destroyed, NotifyResponseStarted will not run. |body| will be destructed |
| 98 // and the request released at that point. | 99 // and the request released at that point. |
| 99 | 100 |
| 100 // Make a copy of the ResourceResponse before it is passed to another thread. | 101 // Make a copy of the ResourceResponse before it is passed to another thread. |
| 101 // | 102 // |
| 102 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | 103 // TODO(davidben): This copy could be avoided if ResourceResponse weren't |
| 103 // reference counted and the loader stack passed unique ownership of the | 104 // reference counted and the loader stack passed unique ownership of the |
| 104 // response. https://crbug.com/416050 | 105 // response. https://crbug.com/416050 |
| 105 BrowserThread::PostTask( | 106 BrowserThread::PostTask( |
| 106 BrowserThread::UI, FROM_HERE, | 107 BrowserThread::UI, FROM_HERE, |
| 107 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, | 108 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, |
| 108 response->DeepCopy(), base::Passed(&body))); | 109 response->DeepCopy(), base::Passed(&data_consumer_handle), |
| 110 request_id)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, | 113 void NavigationURLLoaderImplCore::NotifyRequestFailed(bool in_cache, |
| 112 int net_error) { | 114 int net_error) { |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 115 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 114 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); | 116 TRACE_EVENT_ASYNC_END0("navigation", "Navigation redirectDelay", this); |
| 115 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, | 117 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, |
| 116 "&NavigationURLLoaderImplCore", this, "success", | 118 "&NavigationURLLoaderImplCore", this, "success", |
| 117 false); | 119 false); |
| 118 | 120 |
| 119 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 120 BrowserThread::UI, FROM_HERE, | 122 BrowserThread::UI, FROM_HERE, |
| 121 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | 123 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, |
| 122 in_cache, net_error)); | 124 in_cache, net_error)); |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // namespace content | 127 } // namespace content |
| OLD | NEW |