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

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: Updated tests and refactored code based on CR comments. 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;
35 class NavigatorTestWithBrowserSideNavigation;
34 class RenderFrameHost; 36 class RenderFrameHost;
35 class RenderFrameHostDelegate; 37 class RenderFrameHostDelegate;
36 class RenderFrameHostImpl; 38 class RenderFrameHostImpl;
37 class RenderFrameHostManagerTest; 39 class RenderFrameHostManagerTest;
38 class RenderFrameProxyHost; 40 class RenderFrameProxyHost;
39 class RenderViewHost; 41 class RenderViewHost;
40 class RenderViewHostImpl; 42 class RenderViewHostImpl;
41 class RenderWidgetHostDelegate; 43 class RenderWidgetHostDelegate;
42 class RenderWidgetHostView; 44 class RenderWidgetHostView;
43 class TestWebContents; 45 class TestWebContents;
44 class WebUIImpl; 46 class WebUIImpl;
47 struct CommonNavigationParams;
45 48
46 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a 49 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
47 // current_frame_host() which is the content currently visible to the user. When 50 // 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 51 // 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 52 // SiteInstance), it will replace its current RenderFrameHost with a new
50 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. 53 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
51 // 54 //
52 // Cross-process navigation works like this: 55 // Cross-process navigation works like this:
53 // 56 //
54 // - RFHM::Navigate determines whether the destination is cross-site, and if so, 57 // - 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 362
360 // Deletes any proxy hosts associated with this node. Used during destruction 363 // Deletes any proxy hosts associated with this node. Used during destruction
361 // of WebContentsImpl. 364 // of WebContentsImpl.
362 void ResetProxyHosts(); 365 void ResetProxyHosts();
363 366
364 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy 367 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
365 // that has the given SiteInstance and is associated with this 368 // that has the given SiteInstance and is associated with this
366 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. 369 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
367 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); 370 int GetRoutingIdForSiteInstance(SiteInstance* site_instance);
368 371
369 // PlzNavigate: Called when a navigation is ready to commit, to select the 372 // PlzNavigate
370 // renderer that will commit it. 373 // Notifies the RFHM that a navigation is about to begin so that it can
nasko 2014/12/10 23:11:34 nit: s/about to begin/has begun/ since we issue th
carlosk 2014/12/16 01:53:48 Done.
374 // speculatively spawn a new renderer process if needed.
nasko 2014/12/10 23:11:34 nit: s/spawn/create/
carlosk 2014/12/16 01:53:48 Done.
375 void BeginNavigation(const FrameHostMsg_BeginNavigation_Params& params,
376 const CommonNavigationParams& common_params);
377
378 // PlzNavigate
379 // Called when a navigation is ready to commit, to select the RenderFrameHost
nasko 2014/12/10 23:11:34 nit: no need for comma
carlosk 2014/12/16 01:53:48 Done.
380 // that will commit it.
371 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, 381 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url,
372 ui::PageTransition transition); 382 ui::PageTransition transition);
373 383
384 // PlzNavigate
385 // Cancels any state for any ongoing navigation.
386 void CleanUpNavigation();
387
374 private: 388 private:
389 friend class NavigatorTestWithBrowserSideNavigation;
375 friend class RenderFrameHostManagerTest; 390 friend class RenderFrameHostManagerTest;
376 friend class TestWebContents; 391 friend class TestWebContents;
377 392
378 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, 393 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest,
379 CreateCrossProcessSubframeProxies); 394 CreateCrossProcessSubframeProxies);
380 395
381 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a 396 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
382 // FrameTreeNode's RenderFrameHostManager. 397 // FrameTreeNode's RenderFrameHostManager.
383 static bool ClearProxiesInSiteInstance(int32 site_instance_id, 398 static bool ClearProxiesInSiteInstance(int32 site_instance_id,
384 FrameTreeNode* node); 399 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. 474 // route ID to be used for the new RenderView to be created.
460 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance, 475 int CreateOpenerRenderViewsIfNeeded(SiteInstance* old_instance,
461 SiteInstance* new_instance); 476 SiteInstance* new_instance);
462 477
463 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. 478 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
464 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, 479 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
465 int view_routing_id, 480 int view_routing_id,
466 int frame_routing_id, 481 int frame_routing_id,
467 int flags); 482 int flags);
468 483
484 // PlzNavigate
485 // Creates a new RenderFrameHost and does all required supporting work for the
486 // speculative creation of a new speculative RenderFrameHost for an ongoing
nasko 2014/12/10 23:11:34 nit: It will be nice to avoid using "speculative"
carlosk 2014/12/16 01:53:48 Yeah, this was very bad Engrish. ;) I updated the
487 // navigation request. This RenderFrameHost might be destroyed later if the
488 // final navigation destination doesn't match the initial one.
489 bool CreateSpeculativeRenderFrameHost(const GURL& url,
490 SiteInstance* old_instance,
491 SiteInstance* new_instance,
492 int bindings);
493
469 // Sets up the necessary state for a new RenderViewHost with the given opener, 494 // 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 495 // 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 496 // 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 497 // in swapped out state. Returns early if the RenderViewHost has already been
473 // initialized for another RenderFrameHost. 498 // initialized for another RenderFrameHost.
474 // TODO(creis): opener_route_id is currently for the RenderViewHost but should 499 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
475 // be for the RenderFrame, since frames can have openers. 500 // be for the RenderFrame, since frames can have openers.
476 bool InitRenderView(RenderViewHostImpl* render_view_host, 501 bool InitRenderView(RenderViewHostImpl* render_view_host,
477 int opener_route_id, 502 int opener_route_id,
478 int proxy_routing_id, 503 int proxy_routing_id,
479 bool for_main_frame_navigation); 504 bool for_main_frame_navigation);
480 505
481 // Initialization for RenderFrameHost uses the same sequence as InitRenderView 506 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
482 // above. 507 // above.
483 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); 508 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host);
484 509
485 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this 510 // 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, 511 // 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. 512 // since there could be Web UI switching as well. Call this for every commit.
513 // If PlzNavigate is enabled the method will set the speculative (not pending)
514 // RenderFrameHost to be the active one.
488 void CommitPending(); 515 void CommitPending();
489 516
490 // Runs the unload handler in the old RenderFrameHost, after the new 517 // Runs the unload handler in the old RenderFrameHost, after the new
491 // RenderFrameHost has committed. |old_render_frame_host| will either be 518 // RenderFrameHost has committed. |old_render_frame_host| will either be
492 // deleted or put on the pending delete list during this call. 519 // deleted or put on the pending delete list during this call.
493 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); 520 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host);
494 521
495 // Discards a RenderFrameHost that was never made active (for active ones 522 // Discards a RenderFrameHost that was never made active (for active ones
496 // SwapOutOldFrame is used instead). 523 // SwapOutOldFrame is used instead).
497 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host); 524 void DiscardUnusedFrame(scoped_ptr<RenderFrameHostImpl> render_frame_host);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // A RenderFrameHost used to load a cross-site page. This remains hidden 586 // A RenderFrameHost used to load a cross-site page. This remains hidden
560 // while a cross-site request is pending until it calls DidNavigate. It may 587 // while a cross-site request is pending until it calls DidNavigate. It may
561 // have an associated Web UI, in which case the Web UI pointer will be non- 588 // have an associated Web UI, in which case the Web UI pointer will be non-
562 // NULL. 589 // NULL.
563 // 590 //
564 // The |pending_web_ui_| may be non-NULL even when the 591 // The |pending_web_ui_| may be non-NULL even when the
565 // |pending_render_frame_host_| is NULL. This will happen when we're 592 // |pending_render_frame_host_| is NULL. This will happen when we're
566 // transitioning between two Web UI pages: the RFH won't be swapped, so the 593 // transitioning between two Web UI pages: the RFH won't be swapped, so the
567 // pending pointer will be unused, but there will be a pending Web UI 594 // pending pointer will be unused, but there will be a pending Web UI
568 // associated with the navigation. 595 // associated with the navigation.
596 // Note: This is not used in PlzNavigate.
569 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_; 597 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host_;
570 598
571 // If a pending request needs to be transferred to another process, this 599 // If a pending request needs to be transferred to another process, this
572 // owns the request until it's transferred to the new process, so it will be 600 // owns the request until it's transferred to the new process, so it will be
573 // cleaned up if the navigation is cancelled. Otherwise, this is NULL. 601 // cleaned up if the navigation is cancelled. Otherwise, this is NULL.
574 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_; 602 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request_;
575 603
576 // Tracks information about any navigation paused after receiving response 604 // Tracks information about any navigation paused after receiving response
577 // headers. 605 // headers.
578 scoped_ptr<GlobalRequestID> response_started_id_; 606 scoped_ptr<GlobalRequestID> response_started_id_;
(...skipping 14 matching lines...) Expand all
593 // because sets don't appear to support linked_ptrs. 621 // because sets don't appear to support linked_ptrs.
594 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList; 622 typedef std::list<linked_ptr<RenderFrameHostImpl> > RFHPendingDeleteList;
595 RFHPendingDeleteList pending_delete_hosts_; 623 RFHPendingDeleteList pending_delete_hosts_;
596 624
597 // The intersitial page currently shown if any, not own by this class 625 // The intersitial page currently shown if any, not own by this class
598 // (the InterstitialPage is self-owned, it deletes itself when hidden). 626 // (the InterstitialPage is self-owned, it deletes itself when hidden).
599 InterstitialPageImpl* interstitial_page_; 627 InterstitialPageImpl* interstitial_page_;
600 628
601 NotificationRegistrar registrar_; 629 NotificationRegistrar registrar_;
602 630
631 // PlzNavigate
632 // These members store a speculative RenderFrameHost and WebUI. They are
633 // created early in during a navigation so the renderer process can be started
634 // in parallel with it. This is purely an optimization and is not required for
635 // correct behavior. The created instance might be discarded later on if the
636 // final URL's SiteInstance isn't compatible with what was used to create it.
637 // Note: PlzNavigate only uses speculative RenderFrameHosts and not pending
638 // ones.
639 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
640 scoped_ptr<WebUIImpl> speculative_web_ui_;
641
642 // PlzNavigate
643 // If true at navigation commit time the current WebUI will be kept instead of
644 // creating a new one.
645 bool should_reuse_web_ui_;
646
603 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; 647 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
604 648
605 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); 649 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
606 }; 650 };
607 651
608 } // namespace content 652 } // namespace content
609 653
610 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 654 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698