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

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

Issue 18432: Factor out the test web contents from the WebContents unit test so that it ca... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
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_TAB_CONTENTS_SITE_INSTANCE_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_
7 7
8 #include "chrome/browser/browsing_instance.h" 8 #include "chrome/browser/browsing_instance.h"
9 #include "chrome/browser/renderer_host/render_process_host.h" 9 #include "chrome/browser/renderer_host/render_process_host.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // 44 //
45 /////////////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////////////
46 class SiteInstance : public base::RefCounted<SiteInstance> { 46 class SiteInstance : public base::RefCounted<SiteInstance> {
47 public: 47 public:
48 // Virtual to allow tests to extend it. 48 // Virtual to allow tests to extend it.
49 virtual ~SiteInstance(); 49 virtual ~SiteInstance();
50 50
51 // Get the BrowsingInstance to which this SiteInstance belongs. 51 // Get the BrowsingInstance to which this SiteInstance belongs.
52 BrowsingInstance* browsing_instance() { return browsing_instance_; } 52 BrowsingInstance* browsing_instance() { return browsing_instance_; }
53 53
54 // Sets the factory used to create new RenderProcessHosts. This will also be
55 // passed on to SiteInstances spawned by this one.
56 //
57 // The factory must outlive the SiteInstance; ownership is not transferred. It
58 // may be NULL, in which case the default BrowserRenderProcessHost will be
59 // created (this is the behavior if you don't call this function).
60 void set_render_process_host_factory(RenderProcessHostFactory* rph_factory) {
61 render_process_host_factory_ = rph_factory;
62 }
63
54 // Set / Get the host ID for this SiteInstance's current RenderProcessHost. 64 // Set / Get the host ID for this SiteInstance's current RenderProcessHost.
55 void set_process_host_id(int process_host_id) { 65 void set_process_host_id(int process_host_id) {
56 process_host_id_ = process_host_id; 66 process_host_id_ = process_host_id;
57 } 67 }
58 int process_host_id() const { return process_host_id_; } 68 int process_host_id() const { return process_host_id_; }
59 69
60 // Update / Get the max page ID for this SiteInstance. 70 // Update / Get the max page ID for this SiteInstance.
61 void UpdateMaxPageID(int32 page_id) { 71 void UpdateMaxPageID(int32 page_id) {
62 if (page_id > max_page_id_) 72 if (page_id > max_page_id_)
63 max_page_id_ = page_id; 73 max_page_id_ = page_id;
(...skipping 26 matching lines...) Expand all
90 // a scoped_refptr. (By having this method, we can hide the BrowsingInstance 100 // a scoped_refptr. (By having this method, we can hide the BrowsingInstance
91 // class from the rest of the codebase.) 101 // class from the rest of the codebase.)
92 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as 102 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as
93 // Darin suggests. 103 // Darin suggests.
94 SiteInstance* GetRelatedSiteInstance(const GURL& url); 104 SiteInstance* GetRelatedSiteInstance(const GURL& url);
95 105
96 // Factory method to create a new SiteInstance. This will create a new 106 // Factory method to create a new SiteInstance. This will create a new
97 // new BrowsingInstance, so it should only be used when creating a new tab 107 // new BrowsingInstance, so it should only be used when creating a new tab
98 // from scratch (or similar circumstances). Callers should ensure that 108 // from scratch (or similar circumstances). Callers should ensure that
99 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr. 109 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr.
110 //
111 // The render process host factory may be NULL. See SiteInstance constructor.
112 //
100 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as 113 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as
101 // Darin suggests. 114 // Darin suggests.
102 static SiteInstance* CreateSiteInstance(Profile* profile); 115 static SiteInstance* CreateSiteInstance(Profile* profile);
103 116
104 // Returns the site for the given URL, which includes only the scheme and 117 // Returns the site for the given URL, which includes only the scheme and
105 // registered domain. Returns an empty GURL if the URL has no host. 118 // registered domain. Returns an empty GURL if the URL has no host.
106 static GURL GetSiteForURL(const GURL& url); 119 static GURL GetSiteForURL(const GURL& url);
107 120
108 // Return whether both URLs are part of the same web site, for the purpose of 121 // 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 122 // 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 123 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as
111 // the scheme (https, http). This ensures that two pages will be in 124 // the scheme (https, http). This ensures that two pages will be in
112 // the same process if they can communicate with other via JavaScript. 125 // 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 126 // (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.) 127 // if they both set their document.domain properties to google.com.)
115 static bool IsSameWebSite(const GURL& url1, const GURL& url2); 128 static bool IsSameWebSite(const GURL& url1, const GURL& url2);
116 129
117 protected: 130 protected:
118 friend class BrowsingInstance; 131 friend class BrowsingInstance;
119 132
120 // Create a new SiteInstance. Protected to give access to BrowsingInstance 133 // Create a new SiteInstance. Protected to give access to BrowsingInstance
121 // and tests; most callers should use CreateSiteInstance or 134 // and tests; most callers should use CreateSiteInstance or
122 // GetRelatedSiteInstance instead. 135 // GetRelatedSiteInstance instead.
123 SiteInstance(BrowsingInstance* browsing_instance) 136 SiteInstance(BrowsingInstance* browsing_instance)
124 : browsing_instance_(browsing_instance), 137 : browsing_instance_(browsing_instance),
138 render_process_host_factory_(NULL),
125 process_host_id_(-1), 139 process_host_id_(-1),
126 max_page_id_(-1), 140 max_page_id_(-1),
127 has_site_(false) { 141 has_site_(false) {
128 DCHECK(browsing_instance); 142 DCHECK(browsing_instance);
129 } 143 }
130 144
131 private: 145 private:
132 // BrowsingInstance to which this SiteInstance belongs. 146 // BrowsingInstance to which this SiteInstance belongs.
133 scoped_refptr<BrowsingInstance> browsing_instance_; 147 scoped_refptr<BrowsingInstance> browsing_instance_;
134 148
149 // Factory for new RenderProcessHosts, not owned by this class. NULL indiactes
150 // that the default BrowserRenderProcessHost should be created.
151 const RenderProcessHostFactory* render_process_host_factory_;
152
135 // Current host ID for the RenderProcessHost that is rendering pages for this 153 // Current host ID for the RenderProcessHost that is rendering pages for this
136 // SiteInstance. If the rendering process dies, this host ID can be 154 // SiteInstance. If the rendering process dies, this host ID can be
137 // replaced when a new process is created, without losing the association 155 // replaced when a new process is created, without losing the association
138 // between all pages in this SiteInstance. 156 // between all pages in this SiteInstance.
139 int process_host_id_; 157 int process_host_id_;
140 158
141 // The current max_page_id in the SiteInstance's RenderProcessHost. If the 159 // The current max_page_id in the SiteInstance's RenderProcessHost. If the
142 // rendering process dies, its replacement should start issuing page IDs that 160 // rendering process dies, its replacement should start issuing page IDs that
143 // are larger than this value. 161 // are larger than this value.
144 int32 max_page_id_; 162 int32 max_page_id_;
145 163
146 // The web site that this SiteInstance is rendering pages for. 164 // The web site that this SiteInstance is rendering pages for.
147 GURL site_; 165 GURL site_;
148 166
149 // Whether SetSite has been called. 167 // Whether SetSite has been called.
150 bool has_site_; 168 bool has_site_;
151 169
152 DISALLOW_EVIL_CONSTRUCTORS(SiteInstance); 170 DISALLOW_EVIL_CONSTRUCTORS(SiteInstance);
153 }; 171 };
154 172
155 #endif // CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_ 173 #endif // CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/test_render_view_host.cc ('k') | chrome/browser/tab_contents/site_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698