Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: content/browser/loader/navigation_resource_throttle.cc

Issue 1721813002: Adding DRP specfic UMA for FirstContentfulPaint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missing Header Include Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_resource_throttle.h" 5 #include "content/browser/loader/navigation_resource_throttle.h"
6 6
7 #include <memory>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/location.h" 11 #include "base/location.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "content/browser/frame_host/navigation_handle_impl.h" 13 #include "content/browser/frame_host/navigation_handle_impl.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 14 #include "content/browser/frame_host/render_frame_host_impl.h"
15 #include "content/browser/loader/resource_dispatcher_host_impl.h"
13 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_data.h"
14 #include "content/public/browser/resource_context.h" 18 #include "content/public/browser/resource_context.h"
15 #include "content/public/browser/resource_controller.h" 19 #include "content/public/browser/resource_controller.h"
20 #include "content/public/browser/resource_dispatcher_host_delegate.h"
16 #include "content/public/browser/resource_request_info.h" 21 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/common/referrer.h" 22 #include "content/public/common/referrer.h"
18 #include "net/url_request/redirect_info.h" 23 #include "net/url_request/redirect_info.h"
19 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_job_factory.h" 26 #include "net/url_request/url_request_job_factory.h"
22 #include "ui/base/page_transition_types.h" 27 #include "ui/base/page_transition_types.h"
23 28
24 namespace content { 29 namespace content {
25 30
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ->FilterURL(false, &new_validated_url); 97 ->FilterURL(false, &new_validated_url);
93 navigation_handle->WillRedirectRequest( 98 navigation_handle->WillRedirectRequest(
94 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, 99 new_validated_url, new_method, new_referrer_url, new_is_external_protocol,
95 headers, base::Bind(&SendCheckResultToIOThread, callback)); 100 headers, base::Bind(&SendCheckResultToIOThread, callback));
96 } 101 }
97 102
98 void WillProcessResponseOnUIThread( 103 void WillProcessResponseOnUIThread(
99 UIChecksPerformedCallback callback, 104 UIChecksPerformedCallback callback,
100 int render_process_id, 105 int render_process_id,
101 int render_frame_host_id, 106 int render_frame_host_id,
102 scoped_refptr<net::HttpResponseHeaders> headers) { 107 scoped_refptr<net::HttpResponseHeaders> headers,
108 std::unique_ptr<NavigationData> navigation_data) {
103 DCHECK_CURRENTLY_ON(BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(BrowserThread::UI);
104 RenderFrameHostImpl* render_frame_host = 110 RenderFrameHostImpl* render_frame_host =
105 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); 111 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
106 if (!render_frame_host) { 112 if (!render_frame_host) {
107 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 113 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
108 return; 114 return;
109 } 115 }
110 116
111 NavigationHandleImpl* navigation_handle = 117 NavigationHandleImpl* navigation_handle =
112 render_frame_host->navigation_handle(); 118 render_frame_host->navigation_handle();
113 if (!navigation_handle) { 119 if (!navigation_handle) {
114 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 120 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
115 return; 121 return;
116 } 122 }
117 123
124 if (navigation_data.get())
bengr 2016/04/29 21:14:22 Remove .get()
RyanSturm 2016/05/02 19:52:21 Done.
125 navigation_handle->SetNavigationData(std::move(navigation_data));
126
118 navigation_handle->WillProcessResponse( 127 navigation_handle->WillProcessResponse(
119 render_frame_host, headers, 128 render_frame_host, headers,
120 base::Bind(&SendCheckResultToIOThread, callback)); 129 base::Bind(&SendCheckResultToIOThread, callback));
121 } 130 }
122 131
123 } // namespace 132 } // namespace
124 133
125 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) 134 NavigationResourceThrottle::NavigationResourceThrottle(
126 : request_(request), weak_ptr_factory_(this) {} 135 net::URLRequest* request,
136 ResourceDispatcherHostImpl* resource_dispatcher_host)
137 : request_(request),
138 resource_dispatcher_host_(resource_dispatcher_host),
139 weak_ptr_factory_(this) {}
127 140
128 NavigationResourceThrottle::~NavigationResourceThrottle() {} 141 NavigationResourceThrottle::~NavigationResourceThrottle() {}
129 142
130 void NavigationResourceThrottle::WillStartRequest(bool* defer) { 143 void NavigationResourceThrottle::WillStartRequest(bool* defer) {
131 DCHECK_CURRENTLY_ON(BrowserThread::IO); 144 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); 145 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
133 if (!info) 146 if (!info)
134 return; 147 return;
135 148
136 int render_process_id, render_frame_id; 149 int render_process_id, render_frame_id;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return; 219 return;
207 220
208 // Send a copy of the response headers to the NavigationHandle on the UI 221 // Send a copy of the response headers to the NavigationHandle on the UI
209 // thread. 222 // thread.
210 scoped_refptr<net::HttpResponseHeaders> response_headers; 223 scoped_refptr<net::HttpResponseHeaders> response_headers;
211 if (request_->response_headers()) { 224 if (request_->response_headers()) {
212 response_headers = new net::HttpResponseHeaders( 225 response_headers = new net::HttpResponseHeaders(
213 request_->response_headers()->raw_headers()); 226 request_->response_headers()->raw_headers());
214 } 227 }
215 228
229 // Ask the embedder for a NavigationData instance.
230 std::unique_ptr<NavigationData> navigation_data(nullptr);
bengr 2016/04/29 21:14:22 remove (nullptr)
RyanSturm 2016/05/02 19:52:21 Done.
231 if (resource_dispatcher_host_ && resource_dispatcher_host_->delegate())
232 navigation_data =
233 resource_dispatcher_host_->delegate()->GetNavigationData(request_);
234
235 // Clone the embedder NavigationData before moving it to the UI thread.
236 std::unique_ptr<NavigationData> clone(nullptr);
bengr 2016/04/29 21:14:22 This might be clearer if you put this up after 230
RyanSturm 2016/05/02 19:52:21 Done.
237 if (navigation_data.get())
238 clone = navigation_data->Clone();
239
216 UIChecksPerformedCallback callback = 240 UIChecksPerformedCallback callback =
217 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, 241 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
218 weak_ptr_factory_.GetWeakPtr()); 242 weak_ptr_factory_.GetWeakPtr());
219 243
220 BrowserThread::PostTask( 244 BrowserThread::PostTask(
221 BrowserThread::UI, FROM_HERE, 245 BrowserThread::UI, FROM_HERE,
222 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, 246 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id,
223 render_frame_id, response_headers)); 247 render_frame_id, response_headers, base::Passed(&clone)));
224 *defer = true; 248 *defer = true;
225 } 249 }
226 250
227 const char* NavigationResourceThrottle::GetNameForLogging() const { 251 const char* NavigationResourceThrottle::GetNameForLogging() const {
228 return "NavigationResourceThrottle"; 252 return "NavigationResourceThrottle";
229 } 253 }
230 254
231 void NavigationResourceThrottle::OnUIChecksPerformed( 255 void NavigationResourceThrottle::OnUIChecksPerformed(
232 NavigationThrottle::ThrottleCheckResult result) { 256 NavigationThrottle::ThrottleCheckResult result) {
233 DCHECK_CURRENTLY_ON(BrowserThread::IO); 257 DCHECK_CURRENTLY_ON(BrowserThread::IO);
234 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { 258 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
235 controller()->CancelAndIgnore(); 259 controller()->CancelAndIgnore();
236 } else if (result == NavigationThrottle::CANCEL) { 260 } else if (result == NavigationThrottle::CANCEL) {
237 controller()->Cancel(); 261 controller()->Cancel();
238 } else { 262 } else {
239 controller()->Resume(); 263 controller()->Resume();
240 } 264 }
241 } 265 }
242 266
243 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698