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 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "content/browser/renderer_host/render_process_host_impl.h" | 13 #include "content/browser/renderer_host/render_process_host_impl.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/render_process_host_observer.h" | 15 #include "content/public/browser/render_process_host_observer.h" |
16 #include "content/public/browser/site_instance.h" | 16 #include "content/public/browser/site_instance.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 class BrowsingInstance; | 20 class BrowsingInstance; |
21 class RenderProcessHostFactory; | 21 class RenderProcessHostFactory; |
22 | 22 |
23 class CONTENT_EXPORT SiteInstanceImpl : public SiteInstance, | 23 class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance, |
24 public RenderProcessHostObserver { | 24 public RenderProcessHostObserver { |
25 public: | 25 public: |
26 class CONTENT_EXPORT Observer { | 26 class CONTENT_EXPORT Observer { |
27 public: | 27 public: |
28 // Called when this SiteInstance transitions to having no active frames, | 28 // Called when this SiteInstance transitions to having no active frames, |
29 // as measured by active_frame_count(). | 29 // as measured by active_frame_count(). |
30 virtual void ActiveFrameCountIsZero(SiteInstanceImpl* site_instance) {} | 30 virtual void ActiveFrameCountIsZero(SiteInstanceImpl* site_instance) {} |
31 | 31 |
32 // Called when the renderer process of this SiteInstance has exited. | 32 // Called when the renderer process of this SiteInstance has exited. |
33 virtual void RenderProcessGone(SiteInstanceImpl* site_instance) = 0; | 33 virtual void RenderProcessGone(SiteInstanceImpl* site_instance) = 0; |
34 }; | 34 }; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 // Returns true if pages loaded from |effective_url| ought to be handled only | 123 // Returns true if pages loaded from |effective_url| ought to be handled only |
124 // by a renderer process isolated from other sites. If --site-per-process is | 124 // by a renderer process isolated from other sites. If --site-per-process is |
125 // on the command line, this is true for all sites. In other site isolation | 125 // on the command line, this is true for all sites. In other site isolation |
126 // modes, only a subset of sites will require dedicated processes. | 126 // modes, only a subset of sites will require dedicated processes. |
127 // | 127 // |
128 // |effective_url| must be an effective URL. | 128 // |effective_url| must be an effective URL. |
129 static bool DoesSiteRequireDedicatedProcess(BrowserContext* browser_context, | 129 static bool DoesSiteRequireDedicatedProcess(BrowserContext* browser_context, |
130 const GURL& effective_url); | 130 const GURL& effective_url); |
131 | 131 |
132 protected: | 132 private: |
133 friend class BrowsingInstance; | 133 friend class BrowsingInstance; |
| 134 friend class SiteInstanceTestBrowserClient; |
134 | 135 |
135 // Virtual to allow tests to extend it. | 136 // Create a new SiteInstance. Only BrowsingInstance should call this |
| 137 // directly; clients should use Create() or GetRelatedSiteInstance() instead. |
| 138 explicit SiteInstanceImpl(BrowsingInstance* browsing_instance); |
| 139 |
136 ~SiteInstanceImpl() override; | 140 ~SiteInstanceImpl() override; |
137 | 141 |
138 // Create a new SiteInstance. Protected to give access to BrowsingInstance | |
139 // and tests; most callers should use Create or GetRelatedSiteInstance | |
140 // instead. | |
141 explicit SiteInstanceImpl(BrowsingInstance* browsing_instance); | |
142 | |
143 // Only BrowsingInstance should call this. | |
144 void set_is_default_subframe_site_instance() { | |
145 is_default_subframe_site_instance_ = true; | |
146 } | |
147 | |
148 private: | |
149 // RenderProcessHostObserver implementation. | 142 // RenderProcessHostObserver implementation. |
150 void RenderProcessHostDestroyed(RenderProcessHost* host) override; | 143 void RenderProcessHostDestroyed(RenderProcessHost* host) override; |
151 void RenderProcessWillExit(RenderProcessHost* host) override; | 144 void RenderProcessWillExit(RenderProcessHost* host) override; |
152 void RenderProcessExited(RenderProcessHost* host, | 145 void RenderProcessExited(RenderProcessHost* host, |
153 base::TerminationStatus status, | 146 base::TerminationStatus status, |
154 int exit_code) override; | 147 int exit_code) override; |
155 | 148 |
156 // Used to restrict a process' origin access rights. | 149 // Used to restrict a process' origin access rights. |
157 void LockToOrigin(); | 150 void LockToOrigin(); |
158 | 151 |
| 152 void set_is_default_subframe_site_instance() { |
| 153 is_default_subframe_site_instance_ = true; |
| 154 } |
| 155 |
159 // An object used to construct RenderProcessHosts. | 156 // An object used to construct RenderProcessHosts. |
160 static const RenderProcessHostFactory* g_render_process_host_factory_; | 157 static const RenderProcessHostFactory* g_render_process_host_factory_; |
161 | 158 |
162 // The next available SiteInstance ID. | 159 // The next available SiteInstance ID. |
163 static int32_t next_site_instance_id_; | 160 static int32_t next_site_instance_id_; |
164 | 161 |
165 // A unique ID for this SiteInstance. | 162 // A unique ID for this SiteInstance. |
166 int32_t id_; | 163 int32_t id_; |
167 | 164 |
168 // The number of active frames in this SiteInstance. | 165 // The number of active frames in this SiteInstance. |
(...skipping 20 matching lines...) Expand all Loading... |
189 bool is_default_subframe_site_instance_; | 186 bool is_default_subframe_site_instance_; |
190 | 187 |
191 base::ObserverList<Observer, true> observers_; | 188 base::ObserverList<Observer, true> observers_; |
192 | 189 |
193 DISALLOW_COPY_AND_ASSIGN(SiteInstanceImpl); | 190 DISALLOW_COPY_AND_ASSIGN(SiteInstanceImpl); |
194 }; | 191 }; |
195 | 192 |
196 } // namespace content | 193 } // namespace content |
197 | 194 |
198 #endif // CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ | 195 #endif // CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
OLD | NEW |