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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.h

Issue 701953006: PlzNavigate: Speculatively spawns a renderer process for navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replaced "renderer" to something more meaningful in 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 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace content { 25 namespace content {
26 class BrowserContext; 26 class BrowserContext;
27 class CrossProcessFrameConnector; 27 class CrossProcessFrameConnector;
28 class CrossSiteTransferringRequest; 28 class CrossSiteTransferringRequest;
29 class FrameTreeNode; 29 class FrameTreeNode;
30 class InterstitialPageImpl; 30 class InterstitialPageImpl;
31 class NavigationControllerImpl; 31 class NavigationControllerImpl;
32 class NavigationEntry; 32 class NavigationEntry;
33 class NavigationEntryImpl; 33 class NavigationEntryImpl;
34 class NavigatorTestWithBrowserSideNavigation;
34 class RenderFrameHost; 35 class RenderFrameHost;
35 class RenderFrameHostDelegate; 36 class RenderFrameHostDelegate;
36 class RenderFrameHostImpl; 37 class RenderFrameHostImpl;
37 class RenderFrameHostManagerTest; 38 class RenderFrameHostManagerTest;
38 class RenderFrameProxyHost; 39 class RenderFrameProxyHost;
39 class RenderViewHost; 40 class RenderViewHost;
40 class RenderViewHostImpl; 41 class RenderViewHostImpl;
41 class RenderWidgetHostDelegate; 42 class RenderWidgetHostDelegate;
42 class RenderWidgetHostView; 43 class RenderWidgetHostView;
43 class TestWebContents; 44 class TestWebContents;
44 class WebUIImpl; 45 class WebUIImpl;
46 struct CommonNavigationParams;
45 47
46 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a 48 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
47 // current_frame_host() which is the content currently visible to the user. When 49 // current_frame_host() which is the content currently visible to the user. When
48 // a frame is told to navigate to a different web site (as determined by 50 // a frame is told to navigate to a different web site (as determined by
49 // SiteInstance), it will replace its current RenderFrameHost with a new 51 // SiteInstance), it will replace its current RenderFrameHost with a new
50 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. 52 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
51 // 53 //
52 // Cross-process navigation works like this: 54 // Cross-process navigation works like this:
53 // 55 //
54 // - RFHM::Navigate determines whether the destination is cross-site, and if so, 56 // - RFHM::Navigate determines whether the destination is cross-site, and if so,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 362
361 // Deletes any proxy hosts associated with this node. Used during destruction 363 // Deletes any proxy hosts associated with this node. Used during destruction
362 // of WebContentsImpl. 364 // of WebContentsImpl.
363 void ResetProxyHosts(); 365 void ResetProxyHosts();
364 366
365 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy 367 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
366 // that has the given SiteInstance and is associated with this 368 // that has the given SiteInstance and is associated with this
367 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. 369 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
368 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); 370 int GetRoutingIdForSiteInstance(SiteInstance* site_instance);
369 371
370 // PlzNavigate: Called when a navigation is ready to commit, to select the 372 // PlzNavigate
371 // renderer that will commit it. 373 // Notifies the RFHM that a navigation has begun so that it can speculatively
374 // create a new RenderFrameHost (and potentially a new process) if needed.
375 void BeginNavigation(const CommonNavigationParams& common_params);
376
377 // PlzNavigate
378 // Called (possibly several times) during a navigation to select or create an
379 // appropriate RenderFrameHost for the provided URL. The returned pointer will
380 // be for the current or the speculative RenderFrameHost and the instance is
381 // owned by this manager.
372 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, 382 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url,
373 ui::PageTransition transition); 383 ui::PageTransition transition);
374 384
385 // PlzNavigate
386 // Clean up any state for any ongoing navigation.
387 void CleanUpNavigation();
388
389 // PlzNavigate
390 // Clears the speculative members, returning the RenderFrameHost to the caller
391 // for disposal.
392 scoped_ptr<RenderFrameHostImpl> UnsetSpeculativeRenderFrameHost();
393
375 // Notification methods to tell this RenderFrameHostManager that the frame it 394 // Notification methods to tell this RenderFrameHostManager that the frame it
376 // is responsible for has started or stopped loading a document. 395 // is responsible for has started or stopped loading a document.
377 void OnDidStartLoading(); 396 void OnDidStartLoading();
378 void OnDidStopLoading(); 397 void OnDidStopLoading();
379 398
380 private: 399 private:
400 friend class NavigatorTestWithBrowserSideNavigation;
381 friend class RenderFrameHostManagerTest; 401 friend class RenderFrameHostManagerTest;
382 friend class TestWebContents; 402 friend class TestWebContents;
383 403
384 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, 404 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest,
385 CreateCrossProcessSubframeProxies); 405 CreateCrossProcessSubframeProxies);
386 406
387 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a 407 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
388 // FrameTreeNode's RenderFrameHostManager. 408 // FrameTreeNode's RenderFrameHostManager.
389 static bool ClearProxiesInSiteInstance(int32 site_instance_id, 409 static bool ClearProxiesInSiteInstance(int32 site_instance_id,
390 FrameTreeNode* node); 410 FrameTreeNode* node);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // route ID to be used for the new RenderView to be created. 491 // route ID to be used for the new RenderView to be created.
472 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, 492 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance,
473 SiteInstance* new_instance); 493 SiteInstance* new_instance);
474 494
475 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. 495 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
476 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, 496 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
477 int view_routing_id, 497 int view_routing_id,
478 int frame_routing_id, 498 int frame_routing_id,
479 int flags); 499 int flags);
480 500
501 // PlzNavigate
502 // Creates and initializes a speculative RenderFrameHost and/or WebUI for an
503 // ongoing navigation. They might be destroyed and re-created later if the
504 // navigation is redirected to a different SiteInstance.
505 bool CreateSpeculativeRenderFrameHost(const GURL& url,
506 SiteInstance* old_instance,
507 SiteInstance* new_instance,
508 int bindings);
509
481 // Sets up the necessary state for a new RenderViewHost with the given opener, 510 // Sets up the necessary state for a new RenderViewHost with the given opener,
482 // if necessary. It creates a RenderFrameProxy in the target renderer process 511 // if necessary. It creates a RenderFrameProxy in the target renderer process
483 // with the given |proxy_routing_id|, which is used to route IPC messages when 512 // with the given |proxy_routing_id|, which is used to route IPC messages when
484 // in swapped out state. Returns early if the RenderViewHost has already been 513 // in swapped out state. Returns early if the RenderViewHost has already been
485 // initialized for another RenderFrameHost. 514 // initialized for another RenderFrameHost.
486 // TODO(creis): opener_route_id is currently for the RenderViewHost but should 515 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
487 // be for the RenderFrame, since frames can have openers. 516 // be for the RenderFrame, since frames can have openers.
488 bool InitRenderView(RenderViewHostImpl* render_view_host, 517 bool InitRenderView(RenderViewHostImpl* render_view_host,
489 int opener_route_id, 518 int opener_route_id,
490 int proxy_routing_id, 519 int proxy_routing_id,
491 bool for_main_frame_navigation); 520 bool for_main_frame_navigation);
492 521
493 // Initialization for RenderFrameHost uses the same sequence as InitRenderView 522 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
494 // above. 523 // above.
495 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); 524 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host);
496 525
497 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this 526 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
498 // doesn't require the pending render_frame_host_ pointer to be non-NULL, 527 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
499 // since there could be Web UI switching as well. Call this for every commit. 528 // since there could be Web UI switching as well. Call this for every commit.
529 // If PlzNavigate is enabled the method will set the speculative (not pending)
530 // RenderFrameHost to be the active one.
500 void CommitPending(); 531 void CommitPending();
501 532
502 // Runs the unload handler in the old RenderFrameHost, after the new 533 // Runs the unload handler in the old RenderFrameHost, after the new
503 // RenderFrameHost has committed. |old_render_frame_host| will either be 534 // RenderFrameHost has committed. |old_render_frame_host| will either be
504 // deleted or put on the pending delete list during this call. 535 // deleted or put on the pending delete list during this call.
505 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); 536 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host);
506 537
507 // Discards a RenderFrameHost that was never made active (for active ones 538 // Discards a RenderFrameHost that was never made active (for active ones
508 // SwapOutOldFrame is used instead). 539 // SwapOutOldFrame is used instead).
509 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host); 540 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 581
551 // For use in creating RenderFrameHosts. 582 // For use in creating RenderFrameHosts.
552 FrameTreeNode* frame_tree_node_; 583 FrameTreeNode* frame_tree_node_;
553 584
554 // Our delegate, not owned by us. Guaranteed non-NULL. 585 // Our delegate, not owned by us. Guaranteed non-NULL.
555 Delegate* delegate_; 586 Delegate* delegate_;
556 587
557 // Whether a navigation requiring different RenderFrameHosts is pending. This 588 // Whether a navigation requiring different RenderFrameHosts is pending. This
558 // is either for cross-site requests or when required for the process type 589 // is either for cross-site requests or when required for the process type
559 // (like WebUI). 590 // (like WebUI).
591 // PlzNavigate: |cross_navigation_pending_| is not used for browser-side
592 // navigation.
560 bool cross_navigation_pending_; 593 bool cross_navigation_pending_;
561 594
562 // Implemented by the owner of this class. These delegates are installed into 595 // Implemented by the owner of this class. These delegates are installed into
563 // all the RenderFrameHosts that we create. 596 // all the RenderFrameHosts that we create.
564 RenderFrameHostDelegate* render_frame_delegate_; 597 RenderFrameHostDelegate* render_frame_delegate_;
565 RenderViewHostDelegate* render_view_delegate_; 598 RenderViewHostDelegate* render_view_delegate_;
566 RenderWidgetHostDelegate* render_widget_delegate_; 599 RenderWidgetHostDelegate* render_widget_delegate_;
567 600
568 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for 601 // Our RenderFrameHost and its associated Web UI (if any, will be NULL for
569 // non-WebUI pages). This object is responsible for all communication with 602 // non-WebUI pages). This object is responsible for all communication with
570 // a child RenderFrame instance. 603 // a child RenderFrame instance.
571 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive. 604 // For now, RenderFrameHost keeps a RenderViewHost in its SiteInstance alive.
572 // Eventually, RenderViewHost will be replaced with a page context. 605 // Eventually, RenderViewHost will be replaced with a page context.
573 scoped_ptr<RenderFrameHostImpl> render_frame_host_; 606 scoped_ptr<RenderFrameHostImpl> render_frame_host_;
574 scoped_ptr<WebUIImpl> web_ui_; 607 scoped_ptr<WebUIImpl> web_ui_;
575 608
576 // A RenderFrameHost used to load a cross-site page. This remains hidden 609 // A RenderFrameHost used to load a cross-site page. This remains hidden
577 // while a cross-site request is pending until it calls DidNavigate. It may 610 // while a cross-site request is pending until it calls DidNavigate. It may
578 // have an associated Web UI, in which case the Web UI pointer will be non- 611 // have an associated Web UI, in which case the Web UI pointer will be non-
579 // NULL. 612 // NULL.
580 // 613 //
581 // The |pending_web_ui_| may be non-NULL even when the 614 // The |pending_web_ui_| may be non-NULL even when the
582 // |pending_render_frame_host_| is NULL. This will happen when we're 615 // |pending_render_frame_host_| is NULL. This will happen when we're
583 // transitioning between two Web UI pages: the RFH won't be swapped, so the 616 // transitioning between two Web UI pages: the RFH won't be swapped, so the
584 // pending pointer will be unused, but there will be a pending Web UI 617 // pending pointer will be unused, but there will be a pending Web UI
585 // associated with the navigation. 618 // associated with the navigation.
619 // Note: This is not used in PlzNavigate.
586 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; 620 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_;
587 621
588 // If a pending request needs to be transferred to another process, this 622 // If a pending request needs to be transferred to another process, this
589 // owns the request until it's transferred to the new process, so it will be 623 // owns the request until it's transferred to the new process, so it will be
590 // cleaned up if the navigation is cancelled. Otherwise, this is NULL. 624 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
591 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; 625 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_;
592 626
593 // Tracks information about any navigation paused after receiving response 627 // Tracks information about any navigation paused after receiving response
594 // headers. 628 // headers.
595 scoped_ptr<GlobalRequestID> response_started_id_; 629 scoped_ptr<GlobalRequestID> response_started_id_;
596 630
597 // If either of these is non-NULL, the pending navigation is to a chrome: 631 // If either of these is non-NULL, the pending navigation is to a chrome:
598 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is 632 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
599 // used for when they reference the same object. If either is non-NULL, the 633 // used for when they reference the same object. If either is non-NULL, the
600 // other should be NULL. 634 // other should be NULL.
635 // Note: These are not used in PlzNavigate.
601 scoped_ptr<WebUIImpl> pending_web_ui_; 636 scoped_ptr<WebUIImpl> pending_web_ui_;
602 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; 637 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_;
603 638
604 // A map of site instance ID to RenderFrameProxyHosts. 639 // A map of site instance ID to RenderFrameProxyHosts.
605 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap; 640 typedef base::hash_map<int32, RenderFrameProxyHost*> RenderFrameProxyHostMap;
606 RenderFrameProxyHostMap proxy_hosts_; 641 RenderFrameProxyHostMap proxy_hosts_;
607 642
608 // A list of RenderFrameHosts waiting to shut down after swapping out. We use 643 // A list of RenderFrameHosts waiting to shut down after swapping out. We use
609 // a linked list since we expect frequent deletes and no indexed access, and 644 // a linked list since we expect frequent deletes and no indexed access, and
610 // because sets don't appear to support linked_ptrs. 645 // because sets don't appear to support linked_ptrs.
611 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; 646 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList;
612 RFHPendingDeleteList pending_delete_hosts_; 647 RFHPendingDeleteList pending_delete_hosts_;
613 648
614 // The intersitial page currently shown if any, not own by this class 649 // The intersitial page currently shown if any, not own by this class
615 // (the InterstitialPage is self-owned, it deletes itself when hidden). 650 // (the InterstitialPage is self-owned, it deletes itself when hidden).
616 InterstitialPageImpl* interstitial_page_; 651 InterstitialPageImpl* interstitial_page_;
617 652
618 NotificationRegistrar registrar_; 653 NotificationRegistrar registrar_;
619 654
655 // PlzNavigate
656 // These members store a speculative RenderFrameHost and WebUI. They are
657 // created early in a navigation so a renderer process can be started in
658 // parallel, if needed. This is purely a performance optimization and is not
659 // required for correct behavior. The created RenderFrameHost might be
660 // discarded later on if the final URL's SiteInstance isn't compatible with
661 // what was used to create it.
662 // Note: PlzNavigate only uses speculative RenderFrameHost and WebUI, not
663 // the pending ones.
664 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
665 scoped_ptr<WebUIImpl> speculative_web_ui_;
666
667 // PlzNavigate
668 // If true at navigation commit time the current WebUI will be kept instead of
669 // creating a new one.
670 bool should_reuse_web_ui_;
671
620 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; 672 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
621 673
622 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); 674 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
623 }; 675 };
624 676
625 } // namespace content 677 } // namespace content
626 678
627 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 679 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.cc ('k') | content/browser/frame_host/render_frame_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698