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

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

Issue 701953006: PlzNavigate: Speculatively spawns a renderer process for navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CR comments.. Created 5 years, 11 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 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 527
528 // Run tasks that must execute just before the commit. 528 // Run tasks that must execute just before the commit.
529 bool is_navigation_within_page = controller_->IsURLInPageNavigation( 529 bool is_navigation_within_page = controller_->IsURLInPageNavigation(
530 params.url, params.was_within_same_page, render_frame_host); 530 params.url, params.was_within_same_page, render_frame_host);
531 delegate_->DidNavigateMainFramePreCommit(is_navigation_within_page); 531 delegate_->DidNavigateMainFramePreCommit(is_navigation_within_page);
532 } 532 }
533 533
534 if (!use_site_per_process) 534 if (!use_site_per_process)
535 frame_tree->root()->render_manager()->DidNavigateFrame( 535 frame_tree->root()->render_manager()->DidNavigateFrame(
536 render_frame_host, params.gesture == NavigationGestureUser); 536 render_frame_host, params.gesture == NavigationGestureUser,
537 params.was_within_same_page);
537 } 538 }
538 539
539 // Save the origin of the new page. Do this before calling 540 // Save the origin of the new page. Do this before calling
540 // DidNavigateFrame(), because the origin needs to be included in the SwapOut 541 // DidNavigateFrame(), because the origin needs to be included in the SwapOut
541 // message, which is sent inside DidNavigateFrame(). SwapOut needs the 542 // message, which is sent inside DidNavigateFrame(). SwapOut needs the
542 // origin because it creates a RenderFrameProxy that needs this to initialize 543 // origin because it creates a RenderFrameProxy that needs this to initialize
543 // its security context. This origin will also be sent to RenderFrameProxies 544 // its security context. This origin will also be sent to RenderFrameProxies
544 // created via ViewMsg_New and FrameMsg_NewFrameProxy. 545 // created via ViewMsg_New and FrameMsg_NewFrameProxy.
545 render_frame_host->frame_tree_node()->set_current_origin(params.origin); 546 render_frame_host->frame_tree_node()->set_current_origin(params.origin);
546 547
547 // When using --site-per-process, we notify the RFHM for all navigations, 548 // When using --site-per-process, we notify the RFHM for all navigations,
548 // not just main frame navigations. 549 // not just main frame navigations.
549 if (use_site_per_process) { 550 if (use_site_per_process) {
550 FrameTreeNode* frame = render_frame_host->frame_tree_node(); 551 FrameTreeNode* frame = render_frame_host->frame_tree_node();
551 frame->render_manager()->DidNavigateFrame( 552 frame->render_manager()->DidNavigateFrame(
552 render_frame_host, params.gesture == NavigationGestureUser); 553 render_frame_host, params.gesture == NavigationGestureUser,
554 params.was_within_same_page);
553 } 555 }
554 556
555 // Update the site of the SiteInstance if it doesn't have one yet, unless 557 // Update the site of the SiteInstance if it doesn't have one yet, unless
556 // assigning a site is not necessary for this URL. In that case, the 558 // assigning a site is not necessary for this URL. In that case, the
557 // SiteInstance can still be considered unused until a navigation to a real 559 // SiteInstance can still be considered unused until a navigation to a real
558 // page. 560 // page.
559 SiteInstanceImpl* site_instance = 561 SiteInstanceImpl* site_instance =
560 static_cast<SiteInstanceImpl*>(render_frame_host->GetSiteInstance()); 562 static_cast<SiteInstanceImpl*>(render_frame_host->GetSiteInstance());
561 if (!site_instance->HasSite() && 563 if (!site_instance->HasSite() &&
562 ShouldAssignSiteForURL(params.url)) { 564 ShouldAssignSiteForURL(params.url)) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params)); 771 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params));
770 772
771 info->first_party_for_cookies = 773 info->first_party_for_cookies =
772 frame_tree_node->IsMainFrame() 774 frame_tree_node->IsMainFrame()
773 ? navigation_request->common_params().url 775 ? navigation_request->common_params().url
774 : frame_tree_node->frame_tree()->root()->current_url(); 776 : frame_tree_node->frame_tree()->root()->current_url();
775 info->is_main_frame = frame_tree_node->IsMainFrame(); 777 info->is_main_frame = frame_tree_node->IsMainFrame();
776 info->parent_is_main_frame = !frame_tree_node->parent() ? 778 info->parent_is_main_frame = !frame_tree_node->parent() ?
777 false : frame_tree_node->parent()->IsMainFrame(); 779 false : frame_tree_node->parent()->IsMainFrame();
778 780
779 // TODO(clamy): Inform the RenderFrameHostManager that a navigation is about 781 // First start the request on the IO thread.
780 // to begin, so that it can speculatively spawn a new renderer if needed. 782 navigation_request->BeginNavigation(info.Pass(), params.request_body);
781 783
782 navigation_request->BeginNavigation(info.Pass(), params.request_body); 784 // Then notify the RenderFrameHostManager so it can speculatively create a
785 // renderer in parallel.
786 frame_tree_node->render_manager()->BeginNavigation(common_params);
783 } 787 }
784 788
785 // PlzNavigate 789 // PlzNavigate
786 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, 790 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node,
787 ResourceResponse* response, 791 ResourceResponse* response,
788 scoped_ptr<StreamHandle> body) { 792 scoped_ptr<StreamHandle> body) {
789 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 793 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
790 switches::kEnableBrowserSideNavigation)); 794 switches::kEnableBrowserSideNavigation));
791 795
792 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not 796 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not
793 // commit; they leave the frame showing the previous page. 797 // commit; they leave the frame showing the previous page.
794 if (response->head.headers.get() && 798 if (response->head.headers.get() &&
795 (response->head.headers->response_code() == 204 || 799 (response->head.headers->response_code() == 204 ||
796 response->head.headers->response_code() == 205)) { 800 response->head.headers->response_code() == 205)) {
797 CancelNavigation(frame_tree_node); 801 CancelNavigation(frame_tree_node);
798 return; 802 return;
799 } 803 }
800 804
801 NavigationRequest* navigation_request = 805 NavigationRequest* navigation_request =
802 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); 806 navigation_request_map_.get(frame_tree_node->frame_tree_node_id());
803 DCHECK(navigation_request); 807 DCHECK(navigation_request);
804 808
805 // Select an appropriate renderer to commit the navigation. 809 // Select an appropriate renderer to commit the navigation.
806 RenderFrameHostImpl* render_frame_host = 810 RenderFrameHostImpl* render_frame_host =
807 frame_tree_node->render_manager()->GetFrameHostForNavigation( 811 frame_tree_node->render_manager()->SelectFrameHostForNavigation(
808 navigation_request->common_params().url, 812 navigation_request->common_params().url,
809 navigation_request->common_params().transition); 813 navigation_request->common_params().transition);
810 CheckWebUIRendererDoesNotDisplayNormalURL( 814 CheckWebUIRendererDoesNotDisplayNormalURL(
811 render_frame_host, navigation_request->common_params().url); 815 render_frame_host, navigation_request->common_params().url);
812 816
813 render_frame_host->CommitNavigation(response, body.Pass(), 817 render_frame_host->CommitNavigation(response, body.Pass(),
814 navigation_request->common_params(), 818 navigation_request->common_params(),
815 navigation_request->commit_params()); 819 navigation_request->commit_params());
816 } 820 }
817 821
818 // PlzNavigate 822 // PlzNavigate
819 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { 823 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) {
820 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 824 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
821 switches::kEnableBrowserSideNavigation)); 825 switches::kEnableBrowserSideNavigation));
822 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); 826 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id());
827 // TODO(carlosk): move this cleanup into the NavigationRequest destructor once
828 // we properly cancel ongoing navigations.
829 frame_tree_node->render_manager()->CleanUpNavigation();
823 } 830 }
824 831
825 // PlzNavigate 832 // PlzNavigate
826 NavigationRequest* NavigatorImpl::GetNavigationRequestForNodeForTesting( 833 NavigationRequest* NavigatorImpl::GetNavigationRequestForNodeForTesting(
827 FrameTreeNode* frame_tree_node) { 834 FrameTreeNode* frame_tree_node) {
828 return navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); 835 return navigation_request_map_.get(frame_tree_node->frame_tree_node_id());
829 } 836 }
830 837
831 void NavigatorImpl::LogResourceRequestTime( 838 void NavigatorImpl::LogResourceRequestTime(
832 base::TimeTicks timestamp, const GURL& url) { 839 base::TimeTicks timestamp, const GURL& url) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", 969 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted",
963 time_to_commit); 970 time_to_commit);
964 UMA_HISTOGRAM_TIMES( 971 UMA_HISTOGRAM_TIMES(
965 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", 972 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted",
966 time_to_network); 973 time_to_network);
967 } 974 }
968 navigation_data_.reset(); 975 navigation_data_.reset();
969 } 976 }
970 977
971 } // namespace content 978 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698