| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SITE_INSTANCE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ | 6 #define CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 bool HasProcess() const override; | 44 bool HasProcess() const override; |
| 45 RenderProcessHost* GetProcess() override; | 45 RenderProcessHost* GetProcess() override; |
| 46 BrowserContext* GetBrowserContext() const override; | 46 BrowserContext* GetBrowserContext() const override; |
| 47 const GURL& GetSiteURL() const override; | 47 const GURL& GetSiteURL() const override; |
| 48 scoped_refptr<SiteInstance> GetRelatedSiteInstance(const GURL& url) override; | 48 scoped_refptr<SiteInstance> GetRelatedSiteInstance(const GURL& url) override; |
| 49 bool IsRelatedSiteInstance(const SiteInstance* instance) override; | 49 bool IsRelatedSiteInstance(const SiteInstance* instance) override; |
| 50 size_t GetRelatedActiveContentsCount() override; | 50 size_t GetRelatedActiveContentsCount() override; |
| 51 bool RequiresDedicatedProcess() override; | 51 bool RequiresDedicatedProcess() override; |
| 52 bool IsDefaultSubframeSiteInstance() const override; | 52 bool IsDefaultSubframeSiteInstance() const override; |
| 53 | 53 |
| 54 // The policy to apply when selecting a RenderProcessHost for the |
| 55 // SiteInstance. Normal SiteInstances don't proactively reuse processes, but |
| 56 // when over the limit, they reuse randomly, not based on site. In contrast, |
| 57 // process-per-site and ServiceWorkers proactively join a process that already |
| 58 // contains the site. |
| 59 enum class ProcessReusePolicy { |
| 60 // In this mode, all instances of the site will be hosted in the same |
| 61 // RenderProcessHost. |
| 62 PROCESS_PER_SITE, |
| 63 |
| 64 // In this mode, subframes will be hosted in a designated RenderProcessHost. |
| 65 USE_DEFAULT_SUBFRAME_PROCESS, |
| 66 |
| 67 // By default, a new RenderProcessHost will be created unless the process |
| 68 // limit has been reached. The RenderProcessHost reused will be chosen |
| 69 // randomly and not based on the site. |
| 70 DEFAULT, |
| 71 }; |
| 72 |
| 73 void set_process_reuse_policy(ProcessReusePolicy policy) { |
| 74 process_reuse_policy_ = policy; |
| 75 } |
| 76 ProcessReusePolicy process_reuse_policy() const { |
| 77 return process_reuse_policy_; |
| 78 } |
| 79 |
| 54 // Returns the SiteInstance, related to this one, that should be used | 80 // Returns the SiteInstance, related to this one, that should be used |
| 55 // for subframes when an oopif is required, but a dedicated process is not. | 81 // for subframes when an oopif is required, but a dedicated process is not. |
| 56 // This SiteInstance will be created if it doesn't already exist. There is | 82 // This SiteInstance will be created if it doesn't already exist. There is |
| 57 // at most one of these per BrowsingInstance. | 83 // at most one of these per BrowsingInstance. |
| 58 scoped_refptr<SiteInstanceImpl> GetDefaultSubframeSiteInstance(); | 84 scoped_refptr<SiteInstanceImpl> GetDefaultSubframeSiteInstance(); |
| 59 | 85 |
| 60 // Set the web site that this SiteInstance is rendering pages for. | 86 // Set the web site that this SiteInstance is rendering pages for. |
| 61 // This includes the scheme and registered domain, but not the port. If the | 87 // This includes the scheme and registered domain, but not the port. If the |
| 62 // URL does not have a valid registered domain, then the full hostname is | 88 // URL does not have a valid registered domain, then the full hostname is |
| 63 // stored. | 89 // stored. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 94 // that, unlike active_frame_count, this does not count pending RFHs. | 120 // that, unlike active_frame_count, this does not count pending RFHs. |
| 95 void IncrementRelatedActiveContentsCount(); | 121 void IncrementRelatedActiveContentsCount(); |
| 96 | 122 |
| 97 // Decrease the number of active WebContentses using this SiteInstance. Note | 123 // Decrease the number of active WebContentses using this SiteInstance. Note |
| 98 // that, unlike active_frame_count, this does not count pending RFHs. | 124 // that, unlike active_frame_count, this does not count pending RFHs. |
| 99 void DecrementRelatedActiveContentsCount(); | 125 void DecrementRelatedActiveContentsCount(); |
| 100 | 126 |
| 101 void AddObserver(Observer* observer); | 127 void AddObserver(Observer* observer); |
| 102 void RemoveObserver(Observer* observer); | 128 void RemoveObserver(Observer* observer); |
| 103 | 129 |
| 104 // Sets the global factory used to create new RenderProcessHosts. It may be | |
| 105 // NULL, in which case the default RenderProcessHost will be created (this is | |
| 106 // the behavior if you don't call this function). The factory must be set | |
| 107 // back to NULL before it's destroyed; ownership is not transferred. | |
| 108 static void set_render_process_host_factory( | |
| 109 const RenderProcessHostFactory* rph_factory); | |
| 110 | |
| 111 // Get the effective URL for the given actual URL. This allows the | 130 // Get the effective URL for the given actual URL. This allows the |
| 112 // ContentBrowserClient to override the SiteInstance's site for certain URLs. | 131 // ContentBrowserClient to override the SiteInstance's site for certain URLs. |
| 113 // For example, Chrome uses this to replace hosted app URLs with extension | 132 // For example, Chrome uses this to replace hosted app URLs with extension |
| 114 // hosts. | 133 // hosts. |
| 115 // Only public so that we can make a consistent process swap decision in | 134 // Only public so that we can make a consistent process swap decision in |
| 116 // RenderFrameHostManager. | 135 // RenderFrameHostManager. |
| 117 static GURL GetEffectiveURL(BrowserContext* browser_context, | 136 static GURL GetEffectiveURL(BrowserContext* browser_context, |
| 118 const GURL& url); | 137 const GURL& url); |
| 119 | 138 |
| 120 // Returns true if pages loaded from |url| ought to be handled only by a | 139 // Returns true if pages loaded from |url| ought to be handled only by a |
| (...skipping 21 matching lines...) Expand all Loading... |
| 142 int exit_code) override; | 161 int exit_code) override; |
| 143 | 162 |
| 144 // Used to restrict a process' origin access rights. | 163 // Used to restrict a process' origin access rights. |
| 145 void LockToOrigin(); | 164 void LockToOrigin(); |
| 146 | 165 |
| 147 // This gets the render process to use for default subframe site instances. | 166 // This gets the render process to use for default subframe site instances. |
| 148 RenderProcessHost* GetDefaultSubframeProcessHost( | 167 RenderProcessHost* GetDefaultSubframeProcessHost( |
| 149 BrowserContext* browser_context, | 168 BrowserContext* browser_context, |
| 150 bool is_for_guests_only); | 169 bool is_for_guests_only); |
| 151 | 170 |
| 152 void set_is_default_subframe_site_instance() { | |
| 153 is_default_subframe_site_instance_ = true; | |
| 154 } | |
| 155 | |
| 156 // An object used to construct RenderProcessHosts. | 171 // An object used to construct RenderProcessHosts. |
| 157 static const RenderProcessHostFactory* g_render_process_host_factory_; | 172 static const RenderProcessHostFactory* g_render_process_host_factory_; |
| 158 | 173 |
| 159 // The next available SiteInstance ID. | 174 // The next available SiteInstance ID. |
| 160 static int32_t next_site_instance_id_; | 175 static int32_t next_site_instance_id_; |
| 161 | 176 |
| 162 // A unique ID for this SiteInstance. | 177 // A unique ID for this SiteInstance. |
| 163 int32_t id_; | 178 int32_t id_; |
| 164 | 179 |
| 165 // The number of active frames in this SiteInstance. | 180 // The number of active frames in this SiteInstance. |
| 166 size_t active_frame_count_; | 181 size_t active_frame_count_; |
| 167 | 182 |
| 168 // BrowsingInstance to which this SiteInstance belongs. | 183 // BrowsingInstance to which this SiteInstance belongs. |
| 169 scoped_refptr<BrowsingInstance> browsing_instance_; | 184 scoped_refptr<BrowsingInstance> browsing_instance_; |
| 170 | 185 |
| 171 // Current RenderProcessHost that is rendering pages for this SiteInstance. | 186 // Current RenderProcessHost that is rendering pages for this SiteInstance. |
| 172 // This pointer will only change once the RenderProcessHost is destructed. It | 187 // This pointer will only change once the RenderProcessHost is destructed. It |
| 173 // will still remain the same even if the process crashes, since in that | 188 // will still remain the same even if the process crashes, since in that |
| 174 // scenario the RenderProcessHost remains the same. | 189 // scenario the RenderProcessHost remains the same. |
| 175 RenderProcessHost* process_; | 190 RenderProcessHost* process_; |
| 176 | 191 |
| 177 // The web site that this SiteInstance is rendering pages for. | 192 // The web site that this SiteInstance is rendering pages for. |
| 178 GURL site_; | 193 GURL site_; |
| 179 | 194 |
| 180 // Whether SetSite has been called. | 195 // Whether SetSite has been called. |
| 181 bool has_site_; | 196 bool has_site_; |
| 182 | 197 |
| 183 // Whether this SiteInstance is the default subframe SiteInstance for its | 198 // The ProcessReusePolicy to use when creating a RenderProcessHost for this |
| 184 // BrowsingInstance. Only one SiteInstance per BrowsingInstance can have this | 199 // SiteInstance. |
| 185 // be true. | 200 ProcessReusePolicy process_reuse_policy_; |
| 186 bool is_default_subframe_site_instance_; | |
| 187 | 201 |
| 188 base::ObserverList<Observer, true> observers_; | 202 base::ObserverList<Observer, true> observers_; |
| 189 | 203 |
| 190 DISALLOW_COPY_AND_ASSIGN(SiteInstanceImpl); | 204 DISALLOW_COPY_AND_ASSIGN(SiteInstanceImpl); |
| 191 }; | 205 }; |
| 192 | 206 |
| 193 } // namespace content | 207 } // namespace content |
| 194 | 208 |
| 195 #endif // CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ | 209 #endif // CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
| OLD | NEW |