| OLD | NEW |
| 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 "chrome/common/notification_observer.h" |
| 10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 11 | 12 |
| 12 /////////////////////////////////////////////////////////////////////////////// | 13 /////////////////////////////////////////////////////////////////////////////// |
| 13 // | 14 // |
| 14 // SiteInstance class | 15 // SiteInstance class |
| 15 // | 16 // |
| 16 // A SiteInstance is a data structure that is associated with all pages in a | 17 // 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 | 18 // given instance of a web site. Here, a web site is identified by its |
| 18 // registered domain name and scheme. An instance includes all pages | 19 // 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 | 20 // that are connected (i.e., either a user or a script navigated from one |
| (...skipping 16 matching lines...) Expand all Loading... |
| 36 // dedicated to each site. | 37 // dedicated to each site. |
| 37 // | 38 // |
| 38 // Each NavigationEntry for a WebContents points to the SiteInstance that | 39 // Each NavigationEntry for a WebContents points to the SiteInstance that |
| 39 // rendered it. Each RenderViewHost also points to the SiteInstance that it is | 40 // rendered it. Each RenderViewHost also points to the SiteInstance that it is |
| 40 // associated with. A SiteInstance keeps track of the number of these | 41 // associated with. A SiteInstance keeps track of the number of these |
| 41 // references and deletes itself when the count goes to zero. This means that | 42 // references and deletes itself when the count goes to zero. This means that |
| 42 // a SiteInstance is only live as long as it is accessible, either from new | 43 // a SiteInstance is only live as long as it is accessible, either from new |
| 43 // tabs with no NavigationEntries or in NavigationEntries in the history. | 44 // tabs with no NavigationEntries or in NavigationEntries in the history. |
| 44 // | 45 // |
| 45 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
| 46 class SiteInstance : public base::RefCounted<SiteInstance> { | 47 class SiteInstance : public base::RefCounted<SiteInstance>, |
| 48 public NotificationObserver { |
| 47 public: | 49 public: |
| 48 // Virtual to allow tests to extend it. | 50 // Virtual to allow tests to extend it. |
| 49 virtual ~SiteInstance(); | 51 virtual ~SiteInstance(); |
| 50 | 52 |
| 51 // Get the BrowsingInstance to which this SiteInstance belongs. | 53 // Get the BrowsingInstance to which this SiteInstance belongs. |
| 52 BrowsingInstance* browsing_instance() { return browsing_instance_; } | 54 BrowsingInstance* browsing_instance() { return browsing_instance_; } |
| 53 | 55 |
| 54 // Sets the factory used to create new RenderProcessHosts. This will also be | 56 // Sets the factory used to create new RenderProcessHosts. This will also be |
| 55 // passed on to SiteInstances spawned by this one. | 57 // passed on to SiteInstances spawned by this one. |
| 56 // | 58 // |
| 57 // The factory must outlive the SiteInstance; ownership is not transferred. It | 59 // The factory must outlive the SiteInstance; ownership is not transferred. It |
| 58 // may be NULL, in which case the default BrowserRenderProcessHost will be | 60 // may be NULL, in which case the default BrowserRenderProcessHost will be |
| 59 // created (this is the behavior if you don't call this function). | 61 // created (this is the behavior if you don't call this function). |
| 60 void set_render_process_host_factory(RenderProcessHostFactory* rph_factory) { | 62 void set_render_process_host_factory(RenderProcessHostFactory* rph_factory) { |
| 61 render_process_host_factory_ = rph_factory; | 63 render_process_host_factory_ = rph_factory; |
| 62 } | 64 } |
| 63 | 65 |
| 64 // Set / Get the host ID for this SiteInstance's current RenderProcessHost. | |
| 65 void set_process_host_id(int process_host_id) { | |
| 66 process_host_id_ = process_host_id; | |
| 67 } | |
| 68 int process_host_id() const { return process_host_id_; } | |
| 69 | |
| 70 // Update / Get the max page ID for this SiteInstance. | 66 // Update / Get the max page ID for this SiteInstance. |
| 71 void UpdateMaxPageID(int32 page_id) { | 67 void UpdateMaxPageID(int32 page_id) { |
| 72 if (page_id > max_page_id_) | 68 if (page_id > max_page_id_) |
| 73 max_page_id_ = page_id; | 69 max_page_id_ = page_id; |
| 74 } | 70 } |
| 75 int32 max_page_id() const { return max_page_id_; } | 71 int32 max_page_id() const { return max_page_id_; } |
| 76 | 72 |
| 77 // Returns the current process being used to render pages in this | 73 // Returns the current process being used to render pages in this |
| 78 // SiteInstance. If the process has crashed or otherwise gone away, then | 74 // SiteInstance. If the process has crashed or otherwise gone away, then |
| 79 // this method will create a new process and update our host ID accordingly. | 75 // this method will create a new process and update our host ID accordingly. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // (e.g., docs.google.com and mail.google.com have DOM access to each other | 122 // (e.g., docs.google.com and mail.google.com have DOM access to each other |
| 127 // if they both set their document.domain properties to google.com.) | 123 // if they both set their document.domain properties to google.com.) |
| 128 static bool IsSameWebSite(const GURL& url1, const GURL& url2); | 124 static bool IsSameWebSite(const GURL& url1, const GURL& url2); |
| 129 | 125 |
| 130 protected: | 126 protected: |
| 131 friend class BrowsingInstance; | 127 friend class BrowsingInstance; |
| 132 | 128 |
| 133 // Create a new SiteInstance. Protected to give access to BrowsingInstance | 129 // Create a new SiteInstance. Protected to give access to BrowsingInstance |
| 134 // and tests; most callers should use CreateSiteInstance or | 130 // and tests; most callers should use CreateSiteInstance or |
| 135 // GetRelatedSiteInstance instead. | 131 // GetRelatedSiteInstance instead. |
| 136 SiteInstance(BrowsingInstance* browsing_instance) | 132 SiteInstance(BrowsingInstance* browsing_instance); |
| 137 : browsing_instance_(browsing_instance), | |
| 138 render_process_host_factory_(NULL), | |
| 139 process_host_id_(-1), | |
| 140 max_page_id_(-1), | |
| 141 has_site_(false) { | |
| 142 DCHECK(browsing_instance); | |
| 143 } | |
| 144 | 133 |
| 145 private: | 134 private: |
| 135 // NotificationObserver implementation. |
| 136 void Observe(NotificationType type, |
| 137 const NotificationSource& source, |
| 138 const NotificationDetails& details); |
| 139 |
| 146 // BrowsingInstance to which this SiteInstance belongs. | 140 // BrowsingInstance to which this SiteInstance belongs. |
| 147 scoped_refptr<BrowsingInstance> browsing_instance_; | 141 scoped_refptr<BrowsingInstance> browsing_instance_; |
| 148 | 142 |
| 149 // Factory for new RenderProcessHosts, not owned by this class. NULL indiactes | 143 // Factory for new RenderProcessHosts, not owned by this class. NULL indiactes |
| 150 // that the default BrowserRenderProcessHost should be created. | 144 // that the default BrowserRenderProcessHost should be created. |
| 151 const RenderProcessHostFactory* render_process_host_factory_; | 145 const RenderProcessHostFactory* render_process_host_factory_; |
| 152 | 146 |
| 153 // Current host ID for the RenderProcessHost that is rendering pages for this | 147 // Current RenderProcessHost that is rendering pages for this SiteInstance. |
| 154 // SiteInstance. If the rendering process dies, this host ID can be | 148 RenderProcessHost* process_; |
| 155 // replaced when a new process is created, without losing the association | |
| 156 // between all pages in this SiteInstance. | |
| 157 int process_host_id_; | |
| 158 | 149 |
| 159 // The current max_page_id in the SiteInstance's RenderProcessHost. If the | 150 // The current max_page_id in the SiteInstance's RenderProcessHost. If the |
| 160 // rendering process dies, its replacement should start issuing page IDs that | 151 // rendering process dies, its replacement should start issuing page IDs that |
| 161 // are larger than this value. | 152 // are larger than this value. |
| 162 int32 max_page_id_; | 153 int32 max_page_id_; |
| 163 | 154 |
| 164 // The web site that this SiteInstance is rendering pages for. | 155 // The web site that this SiteInstance is rendering pages for. |
| 165 GURL site_; | 156 GURL site_; |
| 166 | 157 |
| 167 // Whether SetSite has been called. | 158 // Whether SetSite has been called. |
| 168 bool has_site_; | 159 bool has_site_; |
| 169 | 160 |
| 170 DISALLOW_EVIL_CONSTRUCTORS(SiteInstance); | 161 DISALLOW_EVIL_CONSTRUCTORS(SiteInstance); |
| 171 }; | 162 }; |
| 172 | 163 |
| 173 #endif // CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_ | 164 #endif // CHROME_BROWSER_TAB_CONTENTS_SITE_INSTANCE_H_ |
| OLD | NEW |