Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/navigator_impl.h" | 5 #include "content/browser/frame_host/navigator_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } else { | 172 } else { |
| 173 params->redirects.clear(); | 173 params->redirects.clear(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 params->can_load_local_resources = entry.GetCanLoadLocalResources(); | 176 params->can_load_local_resources = entry.GetCanLoadLocalResources(); |
| 177 params->frame_to_navigate = entry.GetFrameToNavigate(); | 177 params->frame_to_navigate = entry.GetFrameToNavigate(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace | 180 } // namespace |
| 181 | 181 |
| 182 struct NavigatorImpl::NavigationMetricsData { | |
| 183 NavigationMetricsData(base::TimeTicks start_time, | |
| 184 GURL url, | |
| 185 NavigationEntryImpl::RestoreType restore_type) | |
| 186 : start_time_(start_time), url_(url) { | |
| 187 is_restoring_from_last_session_ = | |
| 188 (restore_type == | |
| 189 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY || | |
| 190 restore_type == NavigationEntryImpl::RESTORE_LAST_SESSION_CRASHED); | |
| 191 } | |
| 192 | |
| 193 base::TimeTicks start_time_; | |
| 194 GURL url_; | |
| 195 bool is_restoring_from_last_session_; | |
| 196 base::TimeTicks url_job_start_time_; | |
| 197 base::TimeDelta before_unload_delay_; | |
| 198 }; | |
| 182 | 199 |
| 183 NavigatorImpl::NavigatorImpl( | 200 NavigatorImpl::NavigatorImpl( |
| 184 NavigationControllerImpl* navigation_controller, | 201 NavigationControllerImpl* navigation_controller, |
| 185 NavigatorDelegate* delegate) | 202 NavigatorDelegate* delegate) |
| 186 : controller_(navigation_controller), | 203 : controller_(navigation_controller), |
| 187 delegate_(delegate) { | 204 delegate_(delegate) { |
| 188 } | 205 } |
| 189 | 206 |
| 190 NavigatorImpl::~NavigatorImpl() {} | 207 NavigatorImpl::~NavigatorImpl() {} |
| 191 | 208 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to | 371 // "Open link in new tab"). We need to keep it above RFHM::Navigate() call to |
| 355 // capture the time needed for the RenderFrameHost initialization. | 372 // capture the time needed for the RenderFrameHost initialization. |
| 356 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 373 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
| 357 | 374 |
| 358 RenderFrameHostManager* manager = | 375 RenderFrameHostManager* manager = |
| 359 render_frame_host->frame_tree_node()->render_manager(); | 376 render_frame_host->frame_tree_node()->render_manager(); |
| 360 | 377 |
| 361 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. | 378 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. |
| 362 if (CommandLine::ForCurrentProcess()->HasSwitch( | 379 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 363 switches::kEnableBrowserSideNavigation)) { | 380 switches::kEnableBrowserSideNavigation)) { |
| 364 navigation_start_time_and_url = MakeTuple(navigation_start, entry.GetURL()); | 381 navigation_data_.reset(new NavigationMetricsData( |
| 382 navigation_start, entry.GetURL(), entry.restore_type())); | |
| 365 return RequestNavigation(render_frame_host->frame_tree_node(), | 383 return RequestNavigation(render_frame_host->frame_tree_node(), |
| 366 entry, | 384 entry, |
| 367 reload_type, | 385 reload_type, |
| 368 navigation_start); | 386 navigation_start); |
| 369 } | 387 } |
| 370 | 388 |
| 371 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 389 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
| 372 if (!dest_render_frame_host) | 390 if (!dest_render_frame_host) |
| 373 return false; // Unable to create the desired RenderFrameHost. | 391 return false; // Unable to create the desired RenderFrameHost. |
| 374 | 392 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 393 | 411 |
| 394 // Navigate in the desired RenderFrameHost. | 412 // Navigate in the desired RenderFrameHost. |
| 395 // We can skip this step in the rare case that this is a transfer navigation | 413 // We can skip this step in the rare case that this is a transfer navigation |
| 396 // which began in the chosen RenderFrameHost, since the request has already | 414 // which began in the chosen RenderFrameHost, since the request has already |
| 397 // been issued. In that case, simply resume the response. | 415 // been issued. In that case, simply resume the response. |
| 398 bool is_transfer_to_same = | 416 bool is_transfer_to_same = |
| 399 navigate_params.transferred_request_child_id != -1 && | 417 navigate_params.transferred_request_child_id != -1 && |
| 400 navigate_params.transferred_request_child_id == | 418 navigate_params.transferred_request_child_id == |
| 401 dest_render_frame_host->GetProcess()->GetID(); | 419 dest_render_frame_host->GetProcess()->GetID(); |
| 402 if (!is_transfer_to_same) { | 420 if (!is_transfer_to_same) { |
| 403 navigation_start_time_and_url = MakeTuple(navigation_start, entry.GetURL()); | 421 navigation_data_.reset(new NavigationMetricsData( |
| 422 navigation_start, entry.GetURL(), entry.restore_type())); | |
| 404 dest_render_frame_host->Navigate(navigate_params); | 423 dest_render_frame_host->Navigate(navigate_params); |
| 405 } else { | 424 } else { |
| 406 // No need to navigate again. Just resume the deferred request. | 425 // No need to navigate again. Just resume the deferred request. |
| 407 dest_render_frame_host->GetProcess()->ResumeDeferredNavigation( | 426 dest_render_frame_host->GetProcess()->ResumeDeferredNavigation( |
| 408 GlobalRequestID(navigate_params.transferred_request_child_id, | 427 GlobalRequestID(navigate_params.transferred_request_child_id, |
| 409 navigate_params.transferred_request_request_id)); | 428 navigate_params.transferred_request_request_id)); |
| 410 } | 429 } |
| 411 | 430 |
| 412 // Make sure no code called via RFH::Navigate clears the pending entry. | 431 // Make sure no code called via RFH::Navigate clears the pending entry. |
| 413 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 432 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 if (!did_navigate) | 585 if (!did_navigate) |
| 567 return; // No navigation happened. | 586 return; // No navigation happened. |
| 568 | 587 |
| 569 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen | 588 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 570 // for the appropriate notification (best) or you can add it to | 589 // for the appropriate notification (best) or you can add it to |
| 571 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if | 590 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 572 // necessary, please). | 591 // necessary, please). |
| 573 | 592 |
| 574 // TODO(carlosk): Move this out when PlzNavigate implementation properly calls | 593 // TODO(carlosk): Move this out when PlzNavigate implementation properly calls |
| 575 // the observer methods. | 594 // the observer methods. |
| 576 if (details.is_main_frame && | 595 RecordNavigationMetrics(details, params, site_instance); |
| 577 navigation_start_time_and_url.a.ToInternalValue() != 0 | |
| 578 && navigation_start_time_and_url.b == params.original_request_url) { | |
| 579 base::TimeDelta time_to_commit = | |
| 580 base::TimeTicks::Now() - navigation_start_time_and_url.a; | |
| 581 UMA_HISTOGRAM_TIMES("Navigation.TimeToCommit", time_to_commit); | |
| 582 navigation_start_time_and_url = MakeTuple(base::TimeTicks(), GURL()); | |
| 583 } | |
| 584 | 596 |
| 585 // Run post-commit tasks. | 597 // Run post-commit tasks. |
| 586 if (delegate_) { | 598 if (delegate_) { |
| 587 if (details.is_main_frame) | 599 if (details.is_main_frame) |
| 588 delegate_->DidNavigateMainFramePostCommit(details, params); | 600 delegate_->DidNavigateMainFramePostCommit(details, params); |
| 589 | 601 |
| 590 delegate_->DidNavigateAnyFramePostCommit( | 602 delegate_->DidNavigateAnyFramePostCommit( |
| 591 render_frame_host, details, params); | 603 render_frame_host, details, params); |
| 592 } | 604 } |
| 593 } | 605 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 | 778 |
| 767 // PlzNavigate | 779 // PlzNavigate |
| 768 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { | 780 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { |
| 769 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 781 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 770 switches::kEnableBrowserSideNavigation)); | 782 switches::kEnableBrowserSideNavigation)); |
| 771 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); | 783 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); |
| 772 } | 784 } |
| 773 | 785 |
| 774 void NavigatorImpl::LogResourceRequestTime( | 786 void NavigatorImpl::LogResourceRequestTime( |
| 775 base::TimeTicks timestamp, const GURL& url) { | 787 base::TimeTicks timestamp, const GURL& url) { |
| 776 if (navigation_start_time_and_url.a.ToInternalValue() != 0 | 788 if (navigation_data_ && navigation_data_->url_ == url) { |
| 777 && navigation_start_time_and_url.b == url) { | 789 navigation_data_->url_job_start_time_ = timestamp; |
| 778 base::TimeDelta time_to_network = | 790 UMA_HISTOGRAM_TIMES( |
| 779 timestamp - navigation_start_time_and_url.a; | 791 "Navigation.TimeToURLJobStart", |
| 780 UMA_HISTOGRAM_TIMES("Navigation.TimeToURLJobStart", time_to_network); | 792 navigation_data_->url_job_start_time_ - navigation_data_->start_time_); |
| 781 } | 793 } |
| 782 } | 794 } |
| 783 | 795 |
| 796 void NavigatorImpl::LogBeforeUnloadTime( | |
| 797 const base::TimeTicks& renderer_before_unload_start_time, | |
| 798 const base::TimeTicks& renderer_before_unload_end_time) { | |
| 799 // Only stores the beforeunload delay if we're tracking the navigation and it | |
| 800 // happened later than the navigation request | |
|
nasko
2014/10/13 15:55:24
nit: It will be useful to point out that this happ
carlosk
2014/10/13 18:01:46
Done.
| |
| 801 if (navigation_data_ && | |
| 802 renderer_before_unload_start_time > navigation_data_->start_time_) { | |
| 803 navigation_data_->before_unload_delay_ = | |
| 804 renderer_before_unload_end_time - renderer_before_unload_start_time; | |
| 805 } | |
| 806 } | |
| 807 | |
| 784 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | 808 void NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
| 785 RenderFrameHostImpl* render_frame_host, | 809 RenderFrameHostImpl* render_frame_host, |
| 786 const GURL& url) { | 810 const GURL& url) { |
| 787 int enabled_bindings = | 811 int enabled_bindings = |
| 788 render_frame_host->render_view_host()->GetEnabledBindings(); | 812 render_frame_host->render_view_host()->GetEnabledBindings(); |
| 789 bool is_allowed_in_web_ui_renderer = | 813 bool is_allowed_in_web_ui_renderer = |
| 790 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 814 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 791 controller_->GetBrowserContext(), url); | 815 controller_->GetBrowserContext(), url); |
| 792 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 816 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
| 793 !is_allowed_in_web_ui_renderer) { | 817 !is_allowed_in_web_ui_renderer) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 } | 859 } |
| 836 | 860 |
| 837 // The navigation request is sent directly to the IO thread. | 861 // The navigation request is sent directly to the IO thread. |
| 838 OnBeginNavigation( | 862 OnBeginNavigation( |
| 839 frame_tree_node, | 863 frame_tree_node, |
| 840 MakeDefaultBeginNavigation(request_params, navigation_type), | 864 MakeDefaultBeginNavigation(request_params, navigation_type), |
| 841 navigation_request_map_.get(frame_tree_node_id)->common_params()); | 865 navigation_request_map_.get(frame_tree_node_id)->common_params()); |
| 842 return true; | 866 return true; |
| 843 } | 867 } |
| 844 | 868 |
| 869 void NavigatorImpl::RecordNavigationMetrics( | |
| 870 const LoadCommittedDetails& details, | |
| 871 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | |
| 872 SiteInstance* site_instance) { | |
| 873 DCHECK(site_instance->HasProcess()); | |
| 874 if (details.is_main_frame && navigation_data_ && | |
|
nasko
2014/10/13 15:55:24
nit: Code is a bit more readable if it is less ind
carlosk
2014/10/13 18:01:46
Done.
| |
| 875 navigation_data_->url_ == params.original_request_url) { | |
| 876 base::TimeDelta time_to_commit = | |
| 877 base::TimeTicks::Now() - navigation_data_->start_time_; | |
| 878 UMA_HISTOGRAM_TIMES("Navigation.TimeToCommit", time_to_commit); | |
| 879 | |
| 880 time_to_commit -= navigation_data_->before_unload_delay_; | |
| 881 base::TimeDelta time_to_network = navigation_data_->url_job_start_time_ - | |
| 882 navigation_data_->start_time_ - | |
| 883 navigation_data_->before_unload_delay_; | |
| 884 RenderProcessHostImpl* process_host = | |
| 885 static_cast<RenderProcessHostImpl*>(site_instance->GetProcess()); | |
| 886 bool spawned_new_process = | |
| 887 process_host->GetInitTime() > navigation_data_->start_time_; | |
| 888 if (spawned_new_process) { | |
| 889 if (navigation_data_->is_restoring_from_last_session_) { | |
| 890 UMA_HISTOGRAM_TIMES( | |
| 891 "Navigation.TimeToCommit_NewRenderer_Restored_BeforeUnloadDiscounted ", | |
|
clamy
2014/10/13 15:28:33
Line should be under 80 characters.
carlosk
2014/10/13 18:01:46
Done.
| |
| 892 time_to_commit); | |
| 893 UMA_HISTOGRAM_TIMES( | |
| 894 "Navigation.TimeToURLJobStart_NewRenderer_Restored_BeforeUnloadDisco unted", | |
|
clamy
2014/10/13 15:28:33
Line should be under 80 characters.
carlosk
2014/10/13 18:01:46
Done.
| |
| 895 time_to_network); | |
| 896 } else { | |
| 897 UMA_HISTOGRAM_TIMES( | |
| 898 "Navigation.TimeToCommit_NewRenderer_BeforeUnloadDiscounted", | |
| 899 time_to_commit); | |
| 900 UMA_HISTOGRAM_TIMES( | |
| 901 "Navigation.TimeToURLJobStart_NewRenderer_BeforeUnloadDiscounted", | |
| 902 time_to_network); | |
| 903 } | |
| 904 } else { | |
| 905 DCHECK(!navigation_data_->is_restoring_from_last_session_); | |
| 906 UMA_HISTOGRAM_TIMES( | |
| 907 "Navigation.TimeToCommit_OldRenderer_BeforeUnloadDiscounted", | |
| 908 time_to_commit); | |
| 909 UMA_HISTOGRAM_TIMES( | |
| 910 "Navigation.TimeToURLJobStart_OldRenderer_BeforeUnloadDiscounted", | |
| 911 time_to_network); | |
| 912 } | |
| 913 | |
| 914 navigation_data_.reset(); | |
| 915 } | |
| 916 } | |
| 917 | |
| 845 } // namespace content | 918 } // namespace content |
| OLD | NEW |