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

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 2846983002: Add more navigation tracing to RenderFrameHost and NavigationRequest. (Closed)
Patch Set: Move SetWaitingForRendererResponse implementation to .cc file. Created 3 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 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/frame_host/navigation_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "content/browser/appcache/appcache_navigation_handle.h" 10 #include "content/browser/appcache/appcache_navigation_handle.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 request_params_(request_params), 309 request_params_(request_params),
310 browser_initiated_(browser_initiated), 310 browser_initiated_(browser_initiated),
311 state_(NOT_STARTED), 311 state_(NOT_STARTED),
312 restore_type_(RestoreType::NONE), 312 restore_type_(RestoreType::NONE),
313 is_view_source_(false), 313 is_view_source_(false),
314 bindings_(NavigationEntryImpl::kInvalidBindings), 314 bindings_(NavigationEntryImpl::kInvalidBindings),
315 response_should_be_rendered_(true), 315 response_should_be_rendered_(true),
316 associated_site_instance_type_(AssociatedSiteInstanceType::NONE), 316 associated_site_instance_type_(AssociatedSiteInstanceType::NONE),
317 may_transfer_(may_transfer) { 317 may_transfer_(may_transfer) {
318 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); 318 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr));
319 TRACE_EVENT_ASYNC_BEGIN2("navigation", "NavigationRequest", this,
320 "frame_tree_node",
321 frame_tree_node_->frame_tree_node_id(), "url",
322 common_params_.url.possibly_invalid_spec());
319 323
320 // Sanitize the referrer. 324 // Sanitize the referrer.
321 common_params_.referrer = 325 common_params_.referrer =
322 Referrer::SanitizeForRequest(common_params_.url, common_params_.referrer); 326 Referrer::SanitizeForRequest(common_params_.url, common_params_.referrer);
323 327
324 if (may_transfer) { 328 if (may_transfer) {
325 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); 329 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node);
326 if (frame_entry) { 330 if (frame_entry) {
327 source_site_instance_ = frame_entry->source_site_instance(); 331 source_site_instance_ = frame_entry->source_site_instance();
328 dest_site_instance_ = frame_entry->site_instance(); 332 dest_site_instance_ = frame_entry->site_instance();
(...skipping 24 matching lines...) Expand all
353 net::HttpRequestHeaders headers; 357 net::HttpRequestHeaders headers;
354 headers.AddHeadersFromString(begin_params_.headers); 358 headers.AddHeadersFromString(begin_params_.headers);
355 AddAdditionalRequestHeaders( 359 AddAdditionalRequestHeaders(
356 &headers, common_params_.url, common_params_.navigation_type, 360 &headers, common_params_.url, common_params_.navigation_type,
357 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 361 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
358 common_params.method, user_agent_override, frame_tree_node); 362 common_params.method, user_agent_override, frame_tree_node);
359 begin_params_.headers = headers.ToString(); 363 begin_params_.headers = headers.ToString();
360 } 364 }
361 365
362 NavigationRequest::~NavigationRequest() { 366 NavigationRequest::~NavigationRequest() {
367 TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this);
363 } 368 }
364 369
365 void NavigationRequest::BeginNavigation() { 370 void NavigationRequest::BeginNavigation() {
366 DCHECK(!loader_); 371 DCHECK(!loader_);
367 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 372 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
373 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
374 "BeginNavigation");
368 state_ = STARTED; 375 state_ = STARTED;
369 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 376 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
370 377
371 if (ShouldMakeNetworkRequestForURL(common_params_.url) && 378 if (ShouldMakeNetworkRequestForURL(common_params_.url) &&
372 !navigation_handle_->IsSameDocument()) { 379 !navigation_handle_->IsSameDocument()) {
373 // It's safe to use base::Unretained because this NavigationRequest owns 380 // It's safe to use base::Unretained because this NavigationRequest owns
374 // the NavigationHandle where the callback will be stored. 381 // the NavigationHandle where the callback will be stored.
375 // TODO(clamy): pass the method to the NavigationHandle instead of a 382 // TODO(clamy): pass the method to the NavigationHandle instead of a
376 // boolean. 383 // boolean.
377 bool is_external_protocol = 384 bool is_external_protocol =
378 !GetContentClient()->browser()->IsHandledURL(common_params_.url); 385 !GetContentClient()->browser()->IsHandledURL(common_params_.url);
379 navigation_handle_->WillStartRequest( 386 navigation_handle_->WillStartRequest(
380 common_params_.method, common_params_.post_data, 387 common_params_.method, common_params_.post_data,
381 Referrer::SanitizeForRequest(common_params_.url, 388 Referrer::SanitizeForRequest(common_params_.url,
382 common_params_.referrer), 389 common_params_.referrer),
383 begin_params_.has_user_gesture, common_params_.transition, 390 begin_params_.has_user_gesture, common_params_.transition,
384 is_external_protocol, begin_params_.request_context_type, 391 is_external_protocol, begin_params_.request_context_type,
385 begin_params_.mixed_content_context_type, 392 begin_params_.mixed_content_context_type,
386 base::Bind(&NavigationRequest::OnStartChecksComplete, 393 base::Bind(&NavigationRequest::OnStartChecksComplete,
387 base::Unretained(this))); 394 base::Unretained(this)));
388 return; 395 return;
389 } 396 }
390 397
391 // There is no need to make a network request for this navigation, so commit 398 // There is no need to make a network request for this navigation, so commit
392 // it immediately. 399 // it immediately.
400 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
401 "ResponseStarted");
393 state_ = RESPONSE_STARTED; 402 state_ = RESPONSE_STARTED;
394 403
395 // Select an appropriate RenderFrameHost. 404 // Select an appropriate RenderFrameHost.
396 RenderFrameHostImpl* render_frame_host = 405 RenderFrameHostImpl* render_frame_host =
397 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 406 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this);
398 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 407 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
399 common_params_.url); 408 common_params_.url);
400 409
401 // Inform the NavigationHandle that the navigation will commit. 410 // Inform the NavigationHandle that the navigation will commit.
402 navigation_handle_->ReadyToCommitNavigation(render_frame_host); 411 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
403 412
404 CommitNavigation(); 413 CommitNavigation();
405 } 414 }
406 415
416 void NavigationRequest::SetWaitingForRendererResponse() {
417 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
418 "WaitingForRendererResponse");
419 DCHECK(state_ == NOT_STARTED);
420 state_ = WAITING_FOR_RENDERER_RESPONSE;
421 }
422
407 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 423 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
408 DCHECK_EQ(frame_tree_node_->navigation_request(), this); 424 DCHECK_EQ(frame_tree_node_->navigation_request(), this);
409 FrameTreeNode* frame_tree_node = frame_tree_node_; 425 FrameTreeNode* frame_tree_node = frame_tree_node_;
410 426
411 std::vector<GURL> redirect_chain; 427 std::vector<GURL> redirect_chain;
412 if (!begin_params_.client_side_redirect_url.is_empty()) 428 if (!begin_params_.client_side_redirect_url.is_empty())
413 redirect_chain.push_back(begin_params_.client_side_redirect_url); 429 redirect_chain.push_back(begin_params_.client_side_redirect_url);
414 redirect_chain.push_back(common_params_.url); 430 redirect_chain.push_back(common_params_.url);
415 431
416 std::unique_ptr<NavigationHandleImpl> navigation_handle = 432 std::unique_ptr<NavigationHandleImpl> navigation_handle =
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 const scoped_refptr<ResourceResponse>& response, 525 const scoped_refptr<ResourceResponse>& response,
510 std::unique_ptr<StreamHandle> body, 526 std::unique_ptr<StreamHandle> body,
511 mojo::ScopedDataPipeConsumerHandle consumer_handle, 527 mojo::ScopedDataPipeConsumerHandle consumer_handle,
512 const SSLStatus& ssl_status, 528 const SSLStatus& ssl_status,
513 std::unique_ptr<NavigationData> navigation_data, 529 std::unique_ptr<NavigationData> navigation_data,
514 const GlobalRequestID& request_id, 530 const GlobalRequestID& request_id,
515 bool is_download, 531 bool is_download,
516 bool is_stream) { 532 bool is_stream) {
517 DCHECK(state_ == STARTED); 533 DCHECK(state_ == STARTED);
518 DCHECK(response); 534 DCHECK(response);
535 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
536 "OnResponseStarted");
519 state_ = RESPONSE_STARTED; 537 state_ = RESPONSE_STARTED;
520 538
521 // Check if the response should be sent to a renderer. 539 // Check if the response should be sent to a renderer.
522 response_should_be_rendered_ = 540 response_should_be_rendered_ =
523 !is_download && (!response->head.headers.get() || 541 !is_download && (!response->head.headers.get() ||
524 (response->head.headers->response_code() != 204 && 542 (response->head.headers->response_code() != 204 &&
525 response->head.headers->response_code() != 205)); 543 response->head.headers->response_code() != 205));
526 544
527 // Response that will not commit should be marked as aborted in the 545 // Response that will not commit should be marked as aborted in the
528 // NavigationHandle. 546 // NavigationHandle.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 response->head.connection_info, ssl_status, request_id, 607 response->head.connection_info, ssl_status, request_id,
590 common_params_.should_replace_current_entry, is_download, is_stream, 608 common_params_.should_replace_current_entry, is_download, is_stream,
591 base::Closure(), 609 base::Closure(),
592 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete, 610 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete,
593 base::Unretained(this))); 611 base::Unretained(this)));
594 } 612 }
595 613
596 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, 614 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache,
597 int net_error) { 615 int net_error) {
598 DCHECK(state_ == STARTED || state_ == RESPONSE_STARTED); 616 DCHECK(state_ == STARTED || state_ == RESPONSE_STARTED);
617 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationRequest", this,
618 "OnRequestFailed", "error", net_error);
599 state_ = FAILED; 619 state_ = FAILED;
600 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 620 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
601 621
602 // With PlzNavigate, debug URLs will give a failed navigation because the 622 // With PlzNavigate, debug URLs will give a failed navigation because the
603 // WebUI backend won't find a handler for them. They will be processed in the 623 // WebUI backend won't find a handler for them. They will be processed in the
604 // renderer, however do not discard the pending entry so that the URL bar 624 // renderer, however do not discard the pending entry so that the URL bar
605 // shows them correctly. 625 // shows them correctly.
606 if (!IsRendererDebugURL(common_params_.url)) { 626 if (!IsRendererDebugURL(common_params_.url)) {
607 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( 627 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded(
608 navigation_handle_.get()); 628 navigation_handle_.get());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( 672 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(
653 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), 673 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(),
654 timestamp); 674 timestamp);
655 } 675 }
656 676
657 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 677 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
658 common_params_.url); 678 common_params_.url);
659 } 679 }
660 680
661 void NavigationRequest::OnStartChecksComplete( 681 void NavigationRequest::OnStartChecksComplete(
662 NavigationThrottle::ThrottleCheckResult result) { 682 NavigationThrottle::ThrottleCheckResult result) {
clamy 2017/04/28 14:07:15 How about adding some traces in the On*ChecksCompl
nasko 2017/04/28 14:18:56 All NavigationThrottle checks are already instrume
clamy 2017/04/28 14:21:00 Acknowledged. Seems we should be covered enough.
663 DCHECK(result != NavigationThrottle::DEFER); 683 DCHECK(result != NavigationThrottle::DEFER);
664 DCHECK(result != NavigationThrottle::BLOCK_RESPONSE); 684 DCHECK(result != NavigationThrottle::BLOCK_RESPONSE);
665 685
666 if (on_start_checks_complete_closure_) 686 if (on_start_checks_complete_closure_)
667 on_start_checks_complete_closure_.Run(); 687 on_start_checks_complete_closure_.Run();
668 688
669 // Abort the request if needed. This will destroy the NavigationRequest. 689 // Abort the request if needed. This will destroy the NavigationRequest.
670 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 690 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
671 result == NavigationThrottle::CANCEL) { 691 result == NavigationThrottle::CANCEL) {
672 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 692 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 860 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
841 861
842 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 862 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
843 std::move(handle_), common_params_, 863 std::move(handle_), common_params_,
844 request_params_, is_view_source_); 864 request_params_, is_view_source_);
845 865
846 frame_tree_node_->ResetNavigationRequest(true, true); 866 frame_tree_node_->ResetNavigationRequest(true, true);
847 } 867 }
848 868
849 } // namespace content 869 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698