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

Side by Side Diff: content/browser/renderer_host/render_process_host.cc

Issue 8033001: Delegate decision what site instances can be rendered in what process to chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 2 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
« no previous file with comments | « content/browser/renderer_host/render_process_host.h ('k') | content/browser/site_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "content/browser/renderer_host/render_process_host.h" 5 #include "content/browser/renderer_host/render_process_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
11 #include "content/browser/child_process_security_policy.h" 11 #include "content/browser/child_process_security_policy.h"
12 #include "content/browser/content_browser_client.h"
13 #include "content/browser/webui/web_ui_factory.h"
12 #include "content/common/child_process_info.h" 14 #include "content/common/child_process_info.h"
15 #include "content/common/content_client.h"
13 #include "content/common/content_constants.h" 16 #include "content/common/content_constants.h"
14 #include "content/common/content_switches.h" 17 #include "content/common/content_switches.h"
15 #include "content/common/notification_service.h" 18 #include "content/common/notification_service.h"
16 19
17 namespace { 20 namespace {
18 21
19 size_t max_renderer_count_override = 0; 22 size_t max_renderer_count_override = 0;
20 23
21 size_t GetMaxRendererProcessCount() { 24 size_t GetMaxRendererProcessCount() {
22 if (max_renderer_count_override) 25 if (max_renderer_count_override)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 else 60 else
58 max_count = kMaxRenderersByRamTier[memory_tier]; 61 max_count = kMaxRenderersByRamTier[memory_tier];
59 } 62 }
60 return max_count; 63 return max_count;
61 } 64 }
62 65
63 // Returns true if the given host is suitable for launching a new view 66 // Returns true if the given host is suitable for launching a new view
64 // associated with the given browser context. 67 // associated with the given browser context.
65 static bool IsSuitableHost(RenderProcessHost* host, 68 static bool IsSuitableHost(RenderProcessHost* host,
66 content::BrowserContext* browser_context, 69 content::BrowserContext* browser_context,
67 RenderProcessHost::Type type) { 70 const GURL& site_url) {
68 if (host->browser_context() != browser_context) 71 if (host->browser_context() != browser_context)
69 return false; 72 return false;
70 73
71 RenderProcessHost::Type host_type = RenderProcessHost::TYPE_NORMAL; 74 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(host->id()) !=
72 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(host->id())) 75 content::WebUIFactory::Get()->HasWebUIScheme(site_url))
73 host_type = RenderProcessHost::TYPE_WEBUI; 76 return false;
74 if (ChildProcessSecurityPolicy::GetInstance()->
75 HasExtensionBindings(host->id()) ||
76 host->is_extension_process())
77 host_type = RenderProcessHost::TYPE_EXTENSION;
78 77
79 return host_type == type; 78 return content::GetContentClient()->browser()->IsSuitableHost(host, site_url);
80 } 79 }
81 80
82 // the global list of all renderer processes 81 // the global list of all renderer processes
83 IDMap<RenderProcessHost> all_hosts; 82 IDMap<RenderProcessHost> all_hosts;
84 83
85 } // namespace 84 } // namespace
86 85
87 // static 86 // static
88 bool RenderProcessHost::run_renderer_in_process_ = false; 87 bool RenderProcessHost::run_renderer_in_process_ = false;
89 88
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // a renderer process for a browser context that has no existing 211 // a renderer process for a browser context that has no existing
213 // renderers. This is OK in moderation, since the 212 // renderers. This is OK in moderation, since the
214 // GetMaxRendererProcessCount() is conservative. 213 // GetMaxRendererProcessCount() is conservative.
215 214
216 return run_renderer_in_process() || 215 return run_renderer_in_process() ||
217 (renderer_process_count >= GetMaxRendererProcessCount()); 216 (renderer_process_count >= GetMaxRendererProcessCount());
218 } 217 }
219 218
220 // static 219 // static
221 RenderProcessHost* RenderProcessHost::GetExistingProcessHost( 220 RenderProcessHost* RenderProcessHost::GetExistingProcessHost(
222 content::BrowserContext* browser_context, Type type) { 221 content::BrowserContext* browser_context,
222 const GURL& site_url) {
223 // First figure out which existing renderers we can use. 223 // First figure out which existing renderers we can use.
224 std::vector<RenderProcessHost*> suitable_renderers; 224 std::vector<RenderProcessHost*> suitable_renderers;
225 suitable_renderers.reserve(all_hosts.size()); 225 suitable_renderers.reserve(all_hosts.size());
226 226
227 iterator iter(AllHostsIterator()); 227 iterator iter(AllHostsIterator());
228 while (!iter.IsAtEnd()) { 228 while (!iter.IsAtEnd()) {
229 if (run_renderer_in_process() || 229 if (run_renderer_in_process() ||
230 IsSuitableHost(iter.GetCurrentValue(), browser_context, type)) 230 IsSuitableHost(iter.GetCurrentValue(), browser_context, site_url))
231 suitable_renderers.push_back(iter.GetCurrentValue()); 231 suitable_renderers.push_back(iter.GetCurrentValue());
232 232
233 iter.Advance(); 233 iter.Advance();
234 } 234 }
235 235
236 // Now pick a random suitable renderer, if we have any. 236 // Now pick a random suitable renderer, if we have any.
237 if (!suitable_renderers.empty()) { 237 if (!suitable_renderers.empty()) {
238 int suitable_count = static_cast<int>(suitable_renderers.size()); 238 int suitable_count = static_cast<int>(suitable_renderers.size());
239 int random_index = base::RandInt(0, suitable_count - 1); 239 int random_index = base::RandInt(0, suitable_count - 1);
240 return suitable_renderers[random_index]; 240 return suitable_renderers[random_index];
241 } 241 }
242 242
243 return NULL; 243 return NULL;
244 } 244 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host.h ('k') | content/browser/site_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698