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

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: Addressed CR comments, added simple test, other minor changes. Created 6 years, 1 month 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;
30 class FrameTreeNode;
29 class InterstitialPageImpl; 31 class InterstitialPageImpl;
30 class FrameTreeNode;
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 RenderFrameHost;
37 class RenderFrameHostImpl; 37 class RenderFrameHostImpl;
38 class RenderFrameHostManagerTest; 38 class RenderFrameHostManagerTest;
39 class RenderFrameProxyHost; 39 class RenderFrameProxyHost;
40 class RenderViewHost; 40 class RenderViewHost;
41 class RenderViewHostImpl; 41 class RenderViewHostImpl;
42 class RenderWidgetHostDelegate; 42 class RenderWidgetHostDelegate;
43 class RenderWidgetHostView; 43 class RenderWidgetHostView;
44 class TestWebContents; 44 class TestWebContents;
45 class WebUIImpl; 45 class WebUIImpl;
46 struct CommonNavigationParams;
46 47
47 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a 48 // Manages RenderFrameHosts for a FrameTreeNode. It maintains a
48 // 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
49 // 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
50 // SiteInstance), it will replace its current RenderFrameHost with a new 51 // SiteInstance), it will replace its current RenderFrameHost with a new
51 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process. 52 // RenderFrameHost dedicated to the new SiteInstance, possibly in a new process.
52 // 53 //
53 // Cross-process navigation works like this: 54 // Cross-process navigation works like this:
54 // 55 //
55 // - 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 288
288 // Resume navigation paused after receiving response headers. 289 // Resume navigation paused after receiving response headers.
289 void ResumeResponseDeferredAtStart(); 290 void ResumeResponseDeferredAtStart();
290 291
291 // Clear navigation transition data. 292 // Clear navigation transition data.
292 void ClearNavigationTransitionData(); 293 void ClearNavigationTransitionData();
293 294
294 // Called when a renderer's frame navigates. 295 // Called when a renderer's frame navigates.
295 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host); 296 void DidNavigateFrame(RenderFrameHostImpl* render_frame_host);
296 297
298 // PlzNavigate
299 // Cleans up ongoing navigation data.
300 void CancelNavigation();
301
297 // Called when a renderer sets its opener to null. 302 // Called when a renderer sets its opener to null.
298 void DidDisownOpener(RenderFrameHost* render_frame_host); 303 void DidDisownOpener(RenderFrameHost* render_frame_host);
299 304
300 // Helper method to create and initialize a RenderFrameHost. If |swapped_out| 305 // Helper method to create and initialize a RenderFrameHost. If |swapped_out|
301 // is true, it will be initially placed on the swapped out hosts list. 306 // is true, it will be initially placed on the swapped out hosts list.
302 // Returns the routing id of the *view* associated with the frame. 307 // Returns the routing id of the *view* associated with the frame.
303 int CreateRenderFrame(SiteInstance* instance, 308 int CreateRenderFrame(SiteInstance* instance,
304 int opener_route_id, 309 int opener_route_id,
305 bool swapped_out, 310 bool swapped_out,
306 bool for_main_frame_navigation, 311 bool for_main_frame_navigation,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 360
356 // Deletes any proxy hosts associated with this node. Used during destruction 361 // Deletes any proxy hosts associated with this node. Used during destruction
357 // of WebContentsImpl. 362 // of WebContentsImpl.
358 void ResetProxyHosts(); 363 void ResetProxyHosts();
359 364
360 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy 365 // Returns the routing id for a RenderFrameHost or RenderFrameHostProxy
361 // that has the given SiteInstance and is associated with this 366 // that has the given SiteInstance and is associated with this
362 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found. 367 // RenderFrameHostManager. Returns MSG_ROUTING_NONE if none is found.
363 int GetRoutingIdForSiteInstance(SiteInstance* site_instance); 368 int GetRoutingIdForSiteInstance(SiteInstance* site_instance);
364 369
365 // PlzNavigate: Called when a navigation is ready to commit, to select the 370 // PlzNavigate
366 // renderer that will commit it. 371 // Notifies the RFHM that a navigation is about to begin so that it can
372 // speculatively spawn a new renderer process if needed.
373 void BeginNavigation(const FrameHostMsg_BeginNavigation_Params& params,
374 const CommonNavigationParams& common_params);
375
376 // PlzNavigate
377 // Called when a navigation is ready to commit, to select the renderer that
378 // will commit it.
367 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url, 379 RenderFrameHostImpl* GetFrameHostForNavigation(const GURL& url,
368 ui::PageTransition transition); 380 ui::PageTransition transition);
369 381
382 // PlzNavigate
383 // Returns the speculative RenderFrameHost, or NULL if there is no pending
384 // one.
385 RenderFrameHostImpl* speculative_render_frame_host() const {
386 return speculative_render_frame_host_.get();
387 }
388
370 private: 389 private:
371 friend class RenderFrameHostManagerTest; 390 friend class RenderFrameHostManagerTest;
372 friend class TestWebContents; 391 friend class TestWebContents;
373 392
374 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest, 393 FRIEND_TEST_ALL_PREFIXES(CrossProcessFrameTreeBrowserTest,
375 CreateCrossProcessSubframeProxies); 394 CreateCrossProcessSubframeProxies);
376 395
377 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a 396 // Used with FrameTree::ForEach to erase RenderFrameProxyHosts from a
378 // FrameTreeNode's RenderFrameHostManager. 397 // FrameTreeNode's RenderFrameHostManager.
379 static bool ClearProxiesInSiteInstance(int32 site_instance_id, 398 static bool ClearProxiesInSiteInstance(int32 site_instance_id,
(...skipping 29 matching lines...) Expand all
409 bool ShouldReuseWebUI( 428 bool ShouldReuseWebUI(
410 const NavigationEntry* current_entry, 429 const NavigationEntry* current_entry,
411 const GURL& new_url) const; 430 const GURL& new_url) const;
412 431
413 // Returns the SiteInstance to use for the navigation. 432 // Returns the SiteInstance to use for the navigation.
414 SiteInstance* GetSiteInstanceForNavigation( 433 SiteInstance* GetSiteInstanceForNavigation(
415 const GURL& dest_url, 434 const GURL& dest_url,
416 SiteInstance* dest_instance, 435 SiteInstance* dest_instance,
417 ui::PageTransition dest_transition, 436 ui::PageTransition dest_transition,
418 bool dest_is_restore, 437 bool dest_is_restore,
419 bool dest_is_view_source_mode); 438 bool dest_is_view_source_mode,
439 bool create_unbounded_site_instance);
420 440
421 // Returns an appropriate SiteInstance object for the given |dest_url|, 441 // Returns an appropriate SiteInstance object for the given |dest_url|,
422 // possibly reusing the current SiteInstance. If --process-per-tab is used, 442 // possibly reusing the current SiteInstance. If --process-per-tab is used,
423 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns 443 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns
424 // true. |dest_instance| will be used if it is not null. 444 // true. |dest_instance| will be used if it is not null.
425 // This is a helper function for GetSiteInstanceForNavigation. 445 // This is a helper function for GetSiteInstanceForNavigation.
426 SiteInstance* GetSiteInstanceForURL( 446 SiteInstance* GetSiteInstanceForURL(const GURL& dest_url,
427 const GURL& dest_url, 447 SiteInstance* dest_instance,
428 SiteInstance* dest_instance, 448 ui::PageTransition dest_transition,
429 ui::PageTransition dest_transition, 449 bool dest_is_restore,
430 bool dest_is_restore, 450 bool dest_is_view_source_mode,
431 bool dest_is_view_source_mode, 451 SiteInstance* current_instance,
432 SiteInstance* current_instance, 452 bool force_browsing_instance_swap,
433 bool force_browsing_instance_swap); 453 bool create_unbounded_site_instance);
454
455 SiteInstance* CreateSiteInstanceForURL(BrowserContext* browser_context,
456 const GURL& creation_url,
457 bool create_unbounded_site_instance,
458 SiteInstanceImpl* current_instance);
459
460 SiteInstance* GetRelatedSiteInstanceForURL(
461 SiteInstanceImpl* current_instance,
462 const GURL& creation_url,
463 bool create_unbounded_site_instance);
434 464
435 // Determines the appropriate url to use as the current url for SiteInstance 465 // Determines the appropriate url to use as the current url for SiteInstance
436 // selection. 466 // selection.
437 const GURL& GetCurrentURLForSiteInstance( 467 const GURL& GetCurrentURLForSiteInstance(
438 SiteInstance* current_instance, 468 SiteInstance* current_instance,
439 NavigationEntry* current_entry); 469 NavigationEntry* current_entry);
440 470
441 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting 471 // Creates a new RenderFrameHostImpl for the |new_instance| while respecting
442 // the opener route if needed and stores it in pending_render_frame_host_. 472 // the opener route if needed and stores it in pending_render_frame_host_.
443 void CreateRenderFrameHostForNewSiteInstance( 473 void CreateRenderFrameHostForNewSiteInstance(
444 SiteInstance* old_instance, 474 SiteInstance* old_instance,
445 SiteInstance* new_instance, 475 SiteInstance* new_instance,
446 bool is_main_frame); 476 bool is_main_frame);
447 477
448 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary. 478 // Creates a RenderFrameHost and corresponding RenderViewHost if necessary.
449 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance, 479 scoped_ptr<RenderFrameHostImpl> CreateRenderFrameHost(SiteInstance* instance,
450 int view_routing_id, 480 int view_routing_id,
451 int frame_routing_id, 481 int frame_routing_id,
452 bool swapped_out, 482 bool swapped_out,
453 bool hidden); 483 bool hidden);
454 484
485 // PlzNavigate
486 // Creates a new RenderFrameHost and does all required supporting work for the
487 // speculative creation of a new renderer for an ongoing navigation request.
488 // This RenderFrameHost might be destroyed later if the final navigation
489 // destination doesn't match the initial one.
490 bool CreateSpeculativeRenderFrameHost(const GURL& url,
491 SiteInstance* old_instance,
492 SiteInstance* new_instance);
493
494 // PlzNavigate
495 // Cleans up the date related to the speculative RenderFrameHost.
496 void CleanUpSpeculativeRenderFrameHost();
497
455 // Sets up the necessary state for a new RenderViewHost with the given opener, 498 // Sets up the necessary state for a new RenderViewHost with the given opener,
456 // if necessary. It creates a RenderFrameProxy in the target renderer process 499 // if necessary. It creates a RenderFrameProxy in the target renderer process
457 // with the given |proxy_routing_id|, which is used to route IPC messages when 500 // with the given |proxy_routing_id|, which is used to route IPC messages when
458 // in swapped out state. Returns early if the RenderViewHost has already been 501 // in swapped out state. Returns early if the RenderViewHost has already been
459 // initialized for another RenderFrameHost. 502 // initialized for another RenderFrameHost.
460 // TODO(creis): opener_route_id is currently for the RenderViewHost but should 503 // TODO(creis): opener_route_id is currently for the RenderViewHost but should
461 // be for the RenderFrame, since frames can have openers. 504 // be for the RenderFrame, since frames can have openers.
462 bool InitRenderView(RenderViewHostImpl* render_view_host, 505 bool InitRenderView(RenderViewHostImpl* render_view_host,
463 int opener_route_id, 506 int opener_route_id,
464 int proxy_routing_id, 507 int proxy_routing_id,
465 bool for_main_frame_navigation); 508 bool for_main_frame_navigation);
466 509
467 // Initialization for RenderFrameHost uses the same sequence as InitRenderView 510 // Initialization for RenderFrameHost uses the same sequence as InitRenderView
468 // above. 511 // above.
469 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host); 512 bool InitRenderFrame(RenderFrameHostImpl* render_frame_host);
470 513
471 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this 514 // Sets the pending RenderFrameHost/WebUI to be the active one. Note that this
472 // doesn't require the pending render_frame_host_ pointer to be non-NULL, 515 // doesn't require the pending render_frame_host_ pointer to be non-NULL,
473 // since there could be Web UI switching as well. Call this for every commit. 516 // since there could be Web UI switching as well. Call this for every commit.
474 void CommitPending(); 517 // With PlzNavigate enabled, |use_speculative_rfh| can be set to true which
518 // will cause the speculative RenderFrameHost to be the active one.
519 void CommitPending(bool use_speculative_rfh);
475 520
476 // Runs the unload handler in the old RenderFrameHost, after the new 521 // Runs the unload handler in the old RenderFrameHost, after the new
477 // RenderFrameHost has committed. |old_render_frame_host| will either be 522 // RenderFrameHost has committed. |old_render_frame_host| will either be
478 // deleted or put on the pending delete list during this call. 523 // deleted or put on the pending delete list during this call.
479 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host); 524 void SwapOutOldFrame(scoped_ptr<RenderFrameHostImpl> old_render_frame_host);
480 525
526 // Called to properly discard a created RenderFrameHost that was never made
527 // active (for active ones SwapOutOldFrame is used instead). It can be swapped
528 // out or fully destroyed.
529 void RecycleRenderFrameHost(
530 scoped_ptr<RenderFrameHostImpl> render_frame_host);
531
481 // Holds |render_frame_host| until it can be deleted when its swap out ACK 532 // Holds |render_frame_host| until it can be deleted when its swap out ACK
482 // arrives. 533 // arrives.
483 void MoveToPendingDeleteHosts( 534 void MoveToPendingDeleteHosts(
484 scoped_ptr<RenderFrameHostImpl> render_frame_host); 535 scoped_ptr<RenderFrameHostImpl> render_frame_host);
485 536
486 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to 537 // Shutdown all RenderFrameProxyHosts in a SiteInstance. This is called to
487 // shutdown frames when all the frames in a SiteInstance are confirmed to be 538 // shutdown frames when all the frames in a SiteInstance are confirmed to be
488 // swapped out. 539 // swapped out.
489 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id); 540 void ShutdownRenderFrameProxyHostsInSiteInstance(int32 site_instance_id);
490 541
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 RFHPendingDeleteList pending_delete_hosts_; 628 RFHPendingDeleteList pending_delete_hosts_;
578 629
579 // The intersitial page currently shown if any, not own by this class 630 // The intersitial page currently shown if any, not own by this class
580 // (the InterstitialPage is self-owned, it deletes itself when hidden). 631 // (the InterstitialPage is self-owned, it deletes itself when hidden).
581 InterstitialPageImpl* interstitial_page_; 632 InterstitialPageImpl* interstitial_page_;
582 633
583 NotificationRegistrar registrar_; 634 NotificationRegistrar registrar_;
584 635
585 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_; 636 base::WeakPtrFactory<RenderFrameHostManager> weak_factory_;
586 637
638 // PlzNavigate
639 // Members to store the speculative RFH created upon starting a navigation
640 // allowing the creation of the renderer process as early as possible.
641 // Might be discarded later on if the final URL's SiteInstance doesn't match
642 // what was assumed in the beginning.
643 // Note: speculative RenderFrameHost is only used for PlzNavigate and pending
644 // only for the regular navigation (not yet true, but will be).
645 scoped_ptr<RenderFrameHostImpl> speculative_render_frame_host_;
646 scoped_ptr<WebUIImpl> speculative_web_ui_;
647
587 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager); 648 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManager);
588 }; 649 };
589 650
590 } // namespace content 651 } // namespace content
591 652
592 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_ 653 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698