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

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: Re-applied full CL changes, addressed comments, rebased, added tests and fixes. Created 6 years 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/browser/renderer_host/render_view_host_delegate.h" 14 #include "content/browser/renderer_host/render_view_host_delegate.h"
15 #include "content/browser/site_instance_impl.h" 15 #include "content/browser/site_instance_impl.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/public/browser/global_request_id.h" 17 #include "content/public/browser/global_request_id.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/common/referrer.h" 20 #include "content/public/common/referrer.h"
21 #include "ui/base/page_transition_types.h" 21 #include "ui/base/page_transition_types.h"
22 22
23 struct FrameHostMsg_BeginNavigation_Params;
23 struct FrameMsg_Navigate_Params; 24 struct FrameMsg_Navigate_Params;
24 25
25 namespace content { 26 namespace content {
26 class BrowserContext; 27 class BrowserContext;
27 class CrossProcessFrameConnector; 28 class CrossProcessFrameConnector;
28 class CrossSiteTransferringRequest; 29 class CrossSiteTransferringRequest;
29 class FrameTreeNode; 30 class FrameTreeNode;
30 class InterstitialPageImpl; 31 class InterstitialPageImpl;
31 class NavigationControllerImpl; 32 class NavigationControllerImpl;
32 class NavigationEntry; 33 class NavigationEntry;
33 class NavigationEntryImpl; 34 class NavigationEntryImpl;
34 class RenderFrameHost; 35 class RenderFrameHost;
35 class RenderFrameHostDelegate; 36 class RenderFrameHostDelegate;
36 class RenderFrameHostImpl; 37 class RenderFrameHostImpl;
37 class RenderFrameHostManagerTest;
38 class RenderFrameProxyHost; 38 class RenderFrameProxyHost;
39 class RenderViewHost; 39 class RenderViewHost;
40 class RenderViewHostImpl; 40 class RenderViewHostImpl;
41 class RenderWidgetHostDelegate; 41 class RenderWidgetHostDelegate;
42 class RenderWidgetHostView; 42 class RenderWidgetHostView;
43 class TestWebContents;
44 class WebUIImpl; 43 class WebUIImpl;
44 struct CommonNavigationParams;
45 45
46 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a 46 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
47 // current_frame_host() which is the content currently visible to the user. When 47 // 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 48 // 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 49 // SiteInstance), it will replace its current RenderFrameHost with a new
50 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. 50 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
51 // 51 //
52 // Cross-process navigation works like this: 52 // Cross-process navigation works like this:
53 // 53 //
54 // - RFHM::Navigate determines whether the destination is cross-site, and if so, 54 // - RFHM::Navigate determines whether the destination is cross-site, and if so,
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 359
360 // Deletes any proxy hosts associated with this node. Used during destruction 360 // Deletes any proxy hosts associated with this node. Used during destruction
361 // of WebContentsImpl. 361 // of WebContentsImpl.
362 void ResetProxyHosts(); 362 void ResetProxyHosts();
363 363
364 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy 364 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
365 // that has the given SiteInstance and is associated with this 365 // that has the given SiteInstance and is associated with this
366 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. 366 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
367 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); 367 int GetRoutingIdForSiteInstance(SiteInstance* site_instance);
368 368
369 // PlzNavigate: Called when a navigation is ready to commit, to select the 369 // PlzNavigate
370 // renderer that will commit it. 370 // Notifies the RFHM that a navigation is about to begin so that it can
371 // speculatively spawn a new renderer process if needed.
372 void BeginNavigation(const FrameHostMsg_BeginNavigation_Params& params,
373 const CommonNavigationParams& common_params);
374
375 // PlzNavigate
376 // Called when a navigation is ready to commit, to select the renderer that
377 // will commit it.
371 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, 378 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url,
372 ui::PageTransition transition); 379 ui::PageTransition transition);
373 380
381 // PlzNavigate
382 // Cancels any ongoing navigation.
383 void CleanUpNavigation();
384
374 private: 385 private:
386 friend class NavigatorTestWithBrowserSideNavigation;
375 friend class RenderFrameHostManagerTest; 387 friend class RenderFrameHostManagerTest;
376 friend class TestWebContents; 388 friend class TestWebContents;
377 389
378 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, 390 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest,
379 CreateCrossProcessSubframeProxies); 391 CreateCrossProcessSubframeProxies);
380 392
381 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a 393 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
382 // FrameTreeNode's RenderFrameHostManager. 394 // FrameTreeNode's RenderFrameHostManager.
383 static bool ClearProxiesInSiteInstance(int32 site_instance_id, 395 static bool ClearProxiesInSiteInstance(int32 site_instance_id,
384 FrameTreeNode* node); 396 FrameTreeNode* node);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // route ID to be used for the new RenderView to be created. 471 // route ID to be used for the new RenderView to be created.
460 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, 472 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance,
461 SiteInstance* new_instance); 473 SiteInstance* new_instance);
462 474
463 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. 475 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
464 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, 476 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
465 int view_routing_id, 477 int view_routing_id,
466 int frame_routing_id, 478 int frame_routing_id,
467 int flags); 479 int flags);
468 480
481 // PlzNavigate
482 // Creates a new RenderFrameHost and does all required supporting work for the
483 // speculative creation of a new renderer for an ongoing navigation request.
484 // This RenderFrameHost might be destroyed later if the final navigation
485 // destination doesn't match the initial one.
486 bool CreateSpeculativeRenderFrameHost(const GURL& url,
487 SiteInstance* old_instance,
488 SiteInstance* new_instance,
489 int bindings);
490
469 // Sets up the necessary state for a new RenderViewHost with the given opener, 491 // Sets up the necessary state for a new RenderViewHost with the given opener,
470 // if necessary. It creates a RenderFrameProxy in the target renderer process 492 // if necessary. It creates a RenderFrameProxy in the target renderer process
471 // with the given |proxy_routing_id|, which is used to route IPC messages when 493 // with the given |proxy_routing_id|, which is used to route IPC messages when
472 // in swapped out state. Returns early if the RenderViewHost has already been 494 // in swapped out state. Returns early if the RenderViewHost has already been
473 // initialized for another RenderFrameHost. 495 // initialized for another RenderFrameHost.
474 // TODO(creis): opener_route_id is currently for the RenderViewHost but should 496 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
475 // be for the RenderFrame, since frames can have openers. 497 // be for the RenderFrame, since frames can have openers.
476 bool InitRenderView(RenderViewHostImpl* render_view_host, 498 bool InitRenderView(RenderViewHostImpl* render_view_host,
477 int opener_route_id, 499 int opener_route_id,
478 int proxy_routing_id, 500 int proxy_routing_id,
479 bool for_main_frame_navigation); 501 bool for_main_frame_navigation);
480 502
481 // Initialization for RenderFrameHost uses the same sequence as InitRenderView 503 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
482 // above. 504 // above.
483 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); 505 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host);
484 506
485 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this 507 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
486 // doesn't require the pending render_frame_host_ pointer to be non-NULL, 508 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
487 // since there could be Web UI switching as well. Call this for every commit. 509 // since there could be Web UI switching as well. Call this for every commit.
510 // If PlzNavigate is enabled the method will set the speculative
511 // RenderFrameHost to be the active one instead of the pending.
488 void CommitPending(); 512 void CommitPending();
489 513
490 // Runs the unload handler in the old RenderFrameHost, after the new 514 // Runs the unload handler in the old RenderFrameHost, after the new
491 // RenderFrameHost has committed. |old_render_frame_host| will either be 515 // RenderFrameHost has committed. |old_render_frame_host| will either be
492 // deleted or put on the pending delete list during this call. 516 // deleted or put on the pending delete list during this call.
493 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); 517 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host);
494 518
495 // Discards a RenderFrameHost that was never made active (for active ones 519 // Discards a RenderFrameHost that was never made active (for active ones
496 // SwapOutOldFrame is used instead). 520 // SwapOutOldFrame is used instead).
497 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host); 521 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host);
(...skipping 26 matching lines...) Expand all
524 int bindings); 548 int bindings);
525 549
526 // Called when a renderer process is starting to close. We should not 550 // Called when a renderer process is starting to close. We should not
527 // schedule new navigations in its swapped out RenderFrameHosts after this. 551 // schedule new navigations in its swapped out RenderFrameHosts after this.
528 void RendererProcessClosing(RenderProcessHost* render_process_host); 552 void RendererProcessClosing(RenderProcessHost* render_process_host);
529 553
530 // Helper method to delete a RenderFrameProxyHost from the list, if one exists 554 // Helper method to delete a RenderFrameProxyHost from the list, if one exists
531 // for the given |instance|. 555 // for the given |instance|.
532 void DeleteRenderFrameProxyHost(SiteInstance* instance); 556 void DeleteRenderFrameProxyHost(SiteInstance* instance);
533 557
558 // PlzNavigate
559 // Returns the speculative RenderFrameHost or nullptr if there is no pending
560 // one.
561 RenderFrameHostImpl* speculative_render_frame_host() const {
562 return speculative_render_frame_host_.get();
563 }
564
534 // For use in creating RenderFrameHosts. 565 // For use in creating RenderFrameHosts.
535 FrameTreeNode* frame_tree_node_; 566 FrameTreeNode* frame_tree_node_;
536 567
537 // Our delegate, not owned by us. Guaranteed non-NULL. 568 // Our delegate, not owned by us. Guaranteed non-NULL.
538 Delegate* delegate_; 569 Delegate* delegate_;
539 570
540 // Whether a navigation requiring different RenderFrameHosts is pending. This 571 // Whether a navigation requiring different RenderFrameHosts is pending. This
541 // is either for cross-site requests or when required for the process type 572 // is either for cross-site requests or when required for the process type
542 // (like WebUI). 573 // (like WebUI).
543 bool cross_navigation_pending_; 574 bool cross_navigation_pending_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 RFHPendingDeleteList pending_delete_hosts_; 626 RFHPendingDeleteList pending_delete_hosts_;
596 627
597 // The intersitial page currently shown if any, not own by this class 628 // The intersitial page currently shown if any, not own by this class
598 // (the InterstitialPage is self-owned, it deletes itself when hidden). 629 // (the InterstitialPage is self-owned, it deletes itself when hidden).
599 InterstitialPageImpl* interstitial_page_; 630 InterstitialPageImpl* interstitial_page_;
600 631
601 NotificationRegistrar registrar_; 632 NotificationRegistrar registrar_;
602 633
603 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; 634 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
604 635
636 // PlzNavigate
637 // Members to store the speculative RFH created upon starting a navigation
638 // allowing the creation of the renderer process as early as possible.
639 // The created instance might be discarded later on if the final URL's
640 // SiteInstance isn't compatible with what was used to create it.
641 // Note: speculative RenderFrameHost is only used for PlzNavigate and the
642 // pending one only for the regular navigation.
643 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
644 scoped_ptr<WebUIImpl> speculative_web_ui_;
645
646 // PlzNavigate
647 // If true at navigation commit time the current WebUI will be kept instead of
648 // creating a new one.
649 bool should_reuse_web_ui_;
650
605 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); 651 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
606 }; 652 };
607 653
608 } // namespace content 654 } // namespace content
609 655
610 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 656 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698