| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_RENDERER_HOST_RENDER_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // RenderProcessHost per renderer process. | 21 // RenderProcessHost per renderer process. |
| 22 // | 22 // |
| 23 // The concrete implementation of this class for normal use is the | 23 // The concrete implementation of this class for normal use is the |
| 24 // BrowserRenderProcessHost. It may also be implemented by a testing interface | 24 // BrowserRenderProcessHost. It may also be implemented by a testing interface |
| 25 // for mocking purposes. | 25 // for mocking purposes. |
| 26 class RenderProcessHost : public IPC::Channel::Sender, | 26 class RenderProcessHost : public IPC::Channel::Sender, |
| 27 public IPC::Channel::Listener { | 27 public IPC::Channel::Listener { |
| 28 public: | 28 public: |
| 29 typedef IDMap<RenderProcessHost>::const_iterator iterator; | 29 typedef IDMap<RenderProcessHost>::const_iterator iterator; |
| 30 | 30 |
| 31 // We classify renderers according to their highest privilege, and try |
| 32 // to group pages into renderers with similar privileges. |
| 33 // Note: it may be possible for a renderer to have multiple privileges, |
| 34 // in which case we call it an "extension" renderer. |
| 35 enum Type { |
| 36 TYPE_NORMAL, // Normal renderer, no extra privileges. |
| 37 TYPE_DOMUI, // Renderer with DOMUI privileges, like New Tab. |
| 38 TYPE_EXTENSION, // Renderer with extension privileges. |
| 39 }; |
| 40 |
| 31 RenderProcessHost(Profile* profile); | 41 RenderProcessHost(Profile* profile); |
| 32 virtual ~RenderProcessHost(); | 42 virtual ~RenderProcessHost(); |
| 33 | 43 |
| 34 // Returns the user profile associated with this renderer process. | 44 // Returns the user profile associated with this renderer process. |
| 35 Profile* profile() const { return profile_; } | 45 Profile* profile() const { return profile_; } |
| 36 | 46 |
| 37 // Returns the process id for this host. This can be used later in | 47 // Returns the process id for this host. This can be used later in |
| 38 // a call to FromID() to get back to this object (this is used to avoid | 48 // a call to FromID() to get back to this object (this is used to avoid |
| 39 // sending non-threadsafe pointers to other threads). | 49 // sending non-threadsafe pointers to other threads). |
| 40 int pid() const { return pid_; } | 50 int pid() const { return pid_; } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 177 |
| 168 // Returns the RenderProcessHost given its ID. Returns NULL if the ID does | 178 // Returns the RenderProcessHost given its ID. Returns NULL if the ID does |
| 169 // not correspond to a live RenderProcessHost. | 179 // not correspond to a live RenderProcessHost. |
| 170 static RenderProcessHost* FromID(int render_process_id); | 180 static RenderProcessHost* FromID(int render_process_id); |
| 171 | 181 |
| 172 // Returns true if the caller should attempt to use an existing | 182 // Returns true if the caller should attempt to use an existing |
| 173 // RenderProcessHost rather than creating a new one. | 183 // RenderProcessHost rather than creating a new one. |
| 174 static bool ShouldTryToUseExistingProcessHost(); | 184 static bool ShouldTryToUseExistingProcessHost(); |
| 175 | 185 |
| 176 // Get an existing RenderProcessHost associated with the given profile, if | 186 // Get an existing RenderProcessHost associated with the given profile, if |
| 177 // possible. The renderer process is chosen randomly from the | 187 // possible. The renderer process is chosen randomly from suitable renderers |
| 178 // processes associated with the given profile. | 188 // that share the same profile and type. |
| 179 // Returns NULL if no suitable renderer process is available. | 189 // Returns NULL if no suitable renderer process is available, in which case |
| 180 static RenderProcessHost* GetExistingProcessHost(Profile* profile); | 190 // the caller is free to create a new renderer. |
| 191 static RenderProcessHost* GetExistingProcessHost(Profile* profile, Type type); |
| 181 | 192 |
| 182 protected: | 193 protected: |
| 183 // Sets the process of this object, so that others access it using FromID. | 194 // Sets the process of this object, so that others access it using FromID. |
| 184 void SetProcessID(int pid); | 195 void SetProcessID(int pid); |
| 185 | 196 |
| 197 // For testing. Removes this host from the list of hosts. |
| 198 void RemoveFromList(); |
| 199 |
| 186 base::Process process_; | 200 base::Process process_; |
| 187 | 201 |
| 188 // A proxy for our IPC::Channel that lives on the IO thread (see | 202 // A proxy for our IPC::Channel that lives on the IO thread (see |
| 189 // browser_process.h) | 203 // browser_process.h) |
| 190 scoped_ptr<IPC::SyncChannel> channel_; | 204 scoped_ptr<IPC::SyncChannel> channel_; |
| 191 | 205 |
| 192 // the registered listeners. When this list is empty or all NULL, we should | 206 // the registered listeners. When this list is empty or all NULL, we should |
| 193 // delete ourselves | 207 // delete ourselves |
| 194 IDMap<IPC::Channel::Listener> listeners_; | 208 IDMap<IPC::Channel::Listener> listeners_; |
| 195 | 209 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 221 // Factory object for RenderProcessHosts. Using this factory allows tests to | 235 // Factory object for RenderProcessHosts. Using this factory allows tests to |
| 222 // swap out a different one to use a TestRenderProcessHost. | 236 // swap out a different one to use a TestRenderProcessHost. |
| 223 class RenderProcessHostFactory { | 237 class RenderProcessHostFactory { |
| 224 public: | 238 public: |
| 225 virtual ~RenderProcessHostFactory() {} | 239 virtual ~RenderProcessHostFactory() {} |
| 226 virtual RenderProcessHost* CreateRenderProcessHost( | 240 virtual RenderProcessHost* CreateRenderProcessHost( |
| 227 Profile* profile) const = 0; | 241 Profile* profile) const = 0; |
| 228 }; | 242 }; |
| 229 | 243 |
| 230 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_ | 244 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_ |
| OLD | NEW |