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

Side by Side Diff: chrome/browser/site_instance.h

Issue 12451: Don't create separate SiteInstances for pages from the same domain and scheme... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/site_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_SITE_INSTANCE_H__ 5 #ifndef CHROME_BROWSER_SITE_INSTANCE_H__
6 #define CHROME_BROWSER_SITE_INSTANCE_H__ 6 #define CHROME_BROWSER_SITE_INSTANCE_H__
7 7
8 #include "chrome/browser/browsing_instance.h" 8 #include "chrome/browser/browsing_instance.h"
9 #include "chrome/browser/render_process_host.h" 9 #include "chrome/browser/render_process_host.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 11
12 /////////////////////////////////////////////////////////////////////////////// 12 ///////////////////////////////////////////////////////////////////////////////
13 // 13 //
14 // SiteInstance class 14 // SiteInstance class
15 // 15 //
16 // A SiteInstance is a data structure that is associated with all pages in a 16 // A SiteInstance is a data structure that is associated with all pages in a
17 // given instance of a web site. Here, a web site is identified by its 17 // given instance of a web site. Here, a web site is identified by its
18 // registered domain name, scheme, and port. An instance includes all pages 18 // registered domain name and scheme. An instance includes all pages
19 // that are connected (i.e., either a user or a script navigated from one 19 // that are connected (i.e., either a user or a script navigated from one
20 // to the other). We represent instances using the BrowsingInstance class. 20 // to the other). We represent instances using the BrowsingInstance class.
21 // 21 //
22 // In --process-per-tab, one SiteInstance is created for each tab (i.e., in the 22 // In --process-per-tab, one SiteInstance is created for each tab (i.e., in the
23 // WebContents constructor), unless the tab is created by script (i.e., in 23 // WebContents constructor), unless the tab is created by script (i.e., in
24 // WebContents::CreateNewView). This corresponds to one process per 24 // WebContents::CreateNewView). This corresponds to one process per
25 // BrowsingInstance. 25 // BrowsingInstance.
26 // 26 //
27 // In process-per-site-instance (the current default process model), 27 // In process-per-site-instance (the current default process model),
28 // SiteInstances are created (1) when the user manually creates a new tab 28 // SiteInstances are created (1) when the user manually creates a new tab
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 max_page_id_ = page_id; 63 max_page_id_ = page_id;
64 } 64 }
65 int32 max_page_id() const { return max_page_id_; } 65 int32 max_page_id() const { return max_page_id_; }
66 66
67 // Returns the current process being used to render pages in this 67 // Returns the current process being used to render pages in this
68 // SiteInstance. If the process has crashed or otherwise gone away, then 68 // SiteInstance. If the process has crashed or otherwise gone away, then
69 // this method will create a new process and update our host ID accordingly. 69 // this method will create a new process and update our host ID accordingly.
70 RenderProcessHost* GetProcess(); 70 RenderProcessHost* GetProcess();
71 71
72 // Set / Get the web site that this SiteInstance is rendering pages for. 72 // Set / Get the web site that this SiteInstance is rendering pages for.
73 // This includes the scheme, registered domain, and port. If the URL does 73 // This includes the scheme and registered domain, but not the port. If the
74 // not have a valid registered domain, then the full hostname is stored. 74 // URL does not have a valid registered domain, then the full hostname is
75 // stored.
75 void SetSite(const GURL& url); 76 void SetSite(const GURL& url);
76 const GURL& site() const { return site_; } 77 const GURL& site() const { return site_; }
77 bool has_site() const { return has_site_; } 78 bool has_site() const { return has_site_; }
78 79
79 // Returns whether there is currently a related SiteInstance (registered with 80 // Returns whether there is currently a related SiteInstance (registered with
80 // BrowsingInstance) for the site of the given url. If so, we should try to 81 // BrowsingInstance) for the site of the given url. If so, we should try to
81 // avoid dedicating an unused SiteInstance to it (e.g., in a new tab). 82 // avoid dedicating an unused SiteInstance to it (e.g., in a new tab).
82 bool HasRelatedSiteInstance(const GURL& url); 83 bool HasRelatedSiteInstance(const GURL& url);
83 84
84 // Gets a SiteInstance for the given URL that shares the current 85 // Gets a SiteInstance for the given URL that shares the current
85 // BrowsingInstance, creating a new SiteInstance if necessary. This ensures 86 // BrowsingInstance, creating a new SiteInstance if necessary. This ensures
86 // that a BrowsingInstance only has one SiteInstance per site, so that pages 87 // that a BrowsingInstance only has one SiteInstance per site, so that pages
87 // in a BrowsingInstance have the ability to script each other. Callers 88 // in a BrowsingInstance have the ability to script each other. Callers
88 // should ensure that this SiteInstance becomes ref counted, by storing it in 89 // should ensure that this SiteInstance becomes ref counted, by storing it in
89 // a scoped_refptr. (By having this method, we can hide the BrowsingInstance 90 // a scoped_refptr. (By having this method, we can hide the BrowsingInstance
90 // class from the rest of the codebase.) 91 // class from the rest of the codebase.)
91 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as 92 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as
92 // Darin suggests. 93 // Darin suggests.
93 SiteInstance* GetRelatedSiteInstance(const GURL& url); 94 SiteInstance* GetRelatedSiteInstance(const GURL& url);
94 95
95 // Factory method to create a new SiteInstance. This will create a new 96 // Factory method to create a new SiteInstance. This will create a new
96 // new BrowsingInstance, so it should only be used when creating a new tab 97 // new BrowsingInstance, so it should only be used when creating a new tab
97 // from scratch (or similar circumstances). Callers should ensure that 98 // from scratch (or similar circumstances). Callers should ensure that
98 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr. 99 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr.
99 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as 100 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as
100 // Darin suggests. 101 // Darin suggests.
101 static SiteInstance* CreateSiteInstance(Profile* profile); 102 static SiteInstance* CreateSiteInstance(Profile* profile);
102 103
103 // Returns the site for the given URL, which includes only the scheme, 104 // Returns the site for the given URL, which includes only the scheme and
104 // registered domain, and port. Returns an empty GURL if the URL has no 105 // registered domain. Returns an empty GURL if the URL has no host.
105 // host.
106 static GURL GetSiteForURL(const GURL& url); 106 static GURL GetSiteForURL(const GURL& url);
107 107
108 // Return whether both URLs are part of the same web site, for the purpose of 108 // Return whether both URLs are part of the same web site, for the purpose of
109 // assigning them to processes accordingly. The decision is currently based 109 // assigning them to processes accordingly. The decision is currently based
110 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as 110 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as
111 // the scheme (https, http) and port. This ensures that two pages will be in 111 // the scheme (https, http). This ensures that two pages will be in
112 // the same process if they can communicate with other via JavaScript. 112 // the same process if they can communicate with other via JavaScript.
113 // (e.g., docs.google.com and mail.google.com have DOM access to each other 113 // (e.g., docs.google.com and mail.google.com have DOM access to each other
114 // if they both set their document.domain properties to google.com.) 114 // if they both set their document.domain properties to google.com.)
115 static bool IsSameWebSite(const GURL& url1, const GURL& url2); 115 static bool IsSameWebSite(const GURL& url1, const GURL& url2);
116 116
117 protected: 117 protected:
118 friend class BrowsingInstance; 118 friend class BrowsingInstance;
119 119
120 // Create a new SiteInstance. Protected to give access to BrowsingInstance 120 // Create a new SiteInstance. Protected to give access to BrowsingInstance
121 // and tests; most callers should use CreateSiteInstance or 121 // and tests; most callers should use CreateSiteInstance or
(...skipping 25 matching lines...) Expand all
147 GURL site_; 147 GURL site_;
148 148
149 // Whether SetSite has been called. 149 // Whether SetSite has been called.
150 bool has_site_; 150 bool has_site_;
151 151
152 DISALLOW_EVIL_CONSTRUCTORS(SiteInstance); 152 DISALLOW_EVIL_CONSTRUCTORS(SiteInstance);
153 }; 153 };
154 154
155 #endif // CHROME_BROWSER_SITE_INSTANCE_H__ 155 #endif // CHROME_BROWSER_SITE_INSTANCE_H__
156 156
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/site_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698