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

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

Issue 7464009: Removal of Profile from content part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: slight tweaking for comments Created 9 years, 5 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
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/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "chrome/browser/profiles/profile.h"
9 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
10 #include "content/browser/child_process_security_policy.h" 11 #include "content/browser/child_process_security_policy.h"
11 #include "content/common/child_process_info.h" 12 #include "content/common/child_process_info.h"
12 #include "content/common/content_constants.h" 13 #include "content/common/content_constants.h"
13 #include "content/common/notification_service.h" 14 #include "content/common/notification_service.h"
14 15
15 namespace { 16 namespace {
16 17
17 size_t max_renderer_count_override = 0; 18 size_t max_renderer_count_override = 0;
18 19
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 size_t memory_tier = base::SysInfo::AmountOfPhysicalMemoryMB() / 256; 53 size_t memory_tier = base::SysInfo::AmountOfPhysicalMemoryMB() / 256;
53 if (memory_tier >= arraysize(kMaxRenderersByRamTier)) 54 if (memory_tier >= arraysize(kMaxRenderersByRamTier))
54 max_count = content::kMaxRendererProcessCount; 55 max_count = content::kMaxRendererProcessCount;
55 else 56 else
56 max_count = kMaxRenderersByRamTier[memory_tier]; 57 max_count = kMaxRenderersByRamTier[memory_tier];
57 } 58 }
58 return max_count; 59 return max_count;
59 } 60 }
60 61
61 // Returns true if the given host is suitable for launching a new view 62 // Returns true if the given host is suitable for launching a new view
62 // associated with the given profile. 63 // associated with the given browser context.
63 static bool IsSuitableHost(RenderProcessHost* host, Profile* profile, 64 static bool IsSuitableHost(RenderProcessHost* host,
65 content::BrowserContext* browser_context,
64 RenderProcessHost::Type type) { 66 RenderProcessHost::Type type) {
65 if (host->profile() != profile) 67 if (host->browser_context() != browser_context)
66 return false; 68 return false;
67 69
68 RenderProcessHost::Type host_type = RenderProcessHost::TYPE_NORMAL; 70 RenderProcessHost::Type host_type = RenderProcessHost::TYPE_NORMAL;
69 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(host->id())) 71 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(host->id()))
70 host_type = RenderProcessHost::TYPE_WEBUI; 72 host_type = RenderProcessHost::TYPE_WEBUI;
71 if (ChildProcessSecurityPolicy::GetInstance()-> 73 if (ChildProcessSecurityPolicy::GetInstance()->
72 HasExtensionBindings(host->id())) 74 HasExtensionBindings(host->id()))
73 host_type = RenderProcessHost::TYPE_EXTENSION; 75 host_type = RenderProcessHost::TYPE_EXTENSION;
74 76
75 return host_type == type; 77 return host_type == type;
76 } 78 }
77 79
78 // the global list of all renderer processes 80 // the global list of all renderer processes
79 IDMap<RenderProcessHost> all_hosts; 81 IDMap<RenderProcessHost> all_hosts;
80 82
81 } // namespace 83 } // namespace
82 84
83 extern bool g_log_bug53991; 85 extern bool g_log_bug53991;
84 86
85 // static 87 // static
86 bool RenderProcessHost::run_renderer_in_process_ = false; 88 bool RenderProcessHost::run_renderer_in_process_ = false;
87 89
88 // static 90 // static
89 void RenderProcessHost::SetMaxRendererProcessCount(size_t count) { 91 void RenderProcessHost::SetMaxRendererProcessCount(size_t count) {
90 max_renderer_count_override = count; 92 max_renderer_count_override = count;
91 } 93 }
92 94
93 RenderProcessHost::RenderProcessHost(Profile* profile) 95 RenderProcessHost::RenderProcessHost(content::BrowserContext* browser_context)
94 : max_page_id_(-1), 96 : max_page_id_(-1),
95 fast_shutdown_started_(false), 97 fast_shutdown_started_(false),
96 deleting_soon_(false), 98 deleting_soon_(false),
97 is_extension_process_(false), 99 is_extension_process_(false),
98 pending_views_(0), 100 pending_views_(0),
99 id_(ChildProcessInfo::GenerateChildProcessUniqueId()), 101 id_(ChildProcessInfo::GenerateChildProcessUniqueId()),
100 profile_(profile), 102 browser_context_(browser_context),
101 sudden_termination_allowed_(true), 103 sudden_termination_allowed_(true),
102 ignore_input_events_(false) { 104 ignore_input_events_(false) {
103 all_hosts.AddWithID(this, id()); 105 all_hosts.AddWithID(this, id());
104 all_hosts.set_check_on_null_data(true); 106 all_hosts.set_check_on_null_data(true);
105 // Initialize |child_process_activity_time_| to a reasonable value. 107 // Initialize |child_process_activity_time_| to a reasonable value.
106 mark_child_process_activity_time(); 108 mark_child_process_activity_time();
107 } 109 }
108 110
109 RenderProcessHost::~RenderProcessHost() { 111 RenderProcessHost::~RenderProcessHost() {
110 // In unit tests, Release() might not have been called. 112 // In unit tests, Release() might not have been called.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
177 return all_hosts.Lookup(render_process_id); 179 return all_hosts.Lookup(render_process_id);
178 } 180 }
179 181
180 // static 182 // static
181 bool RenderProcessHost::ShouldTryToUseExistingProcessHost() { 183 bool RenderProcessHost::ShouldTryToUseExistingProcessHost() {
182 size_t renderer_process_count = all_hosts.size(); 184 size_t renderer_process_count = all_hosts.size();
183 185
184 // NOTE: Sometimes it's necessary to create more render processes than 186 // NOTE: Sometimes it's necessary to create more render processes than
185 // GetMaxRendererProcessCount(), for instance when we want to create 187 // GetMaxRendererProcessCount(), for instance when we want to create
186 // a renderer process for a profile that has no existing renderers. 188 // a renderer process for a browser context that has no existing
187 // This is OK in moderation, since the GetMaxRendererProcessCount() 189 // renderers. This is OK in moderation, since the
188 // is conservative. 190 // GetMaxRendererProcessCount() is conservative.
189 191
190 return run_renderer_in_process() || 192 return run_renderer_in_process() ||
191 (renderer_process_count >= GetMaxRendererProcessCount()); 193 (renderer_process_count >= GetMaxRendererProcessCount());
192 } 194 }
193 195
194 // static 196 // static
195 RenderProcessHost* RenderProcessHost::GetExistingProcessHost(Profile* profile, 197 RenderProcessHost* RenderProcessHost::GetExistingProcessHost(
196 Type type) { 198 content::BrowserContext* browser_context, Type type) {
197 // First figure out which existing renderers we can use. 199 // First figure out which existing renderers we can use.
198 std::vector<RenderProcessHost*> suitable_renderers; 200 std::vector<RenderProcessHost*> suitable_renderers;
199 suitable_renderers.reserve(all_hosts.size()); 201 suitable_renderers.reserve(all_hosts.size());
200 202
201 iterator iter(AllHostsIterator()); 203 iterator iter(AllHostsIterator());
202 while (!iter.IsAtEnd()) { 204 while (!iter.IsAtEnd()) {
203 if (run_renderer_in_process() || 205 if (run_renderer_in_process() ||
204 IsSuitableHost(iter.GetCurrentValue(), profile, type)) 206 IsSuitableHost(iter.GetCurrentValue(), browser_context, type))
205 suitable_renderers.push_back(iter.GetCurrentValue()); 207 suitable_renderers.push_back(iter.GetCurrentValue());
206 208
207 iter.Advance(); 209 iter.Advance();
208 } 210 }
209 211
210 // Now pick a random suitable renderer, if we have any. 212 // Now pick a random suitable renderer, if we have any.
211 if (!suitable_renderers.empty()) { 213 if (!suitable_renderers.empty()) {
212 int suitable_count = static_cast<int>(suitable_renderers.size()); 214 int suitable_count = static_cast<int>(suitable_renderers.size());
213 int random_index = base::RandInt(0, suitable_count - 1); 215 int random_index = base::RandInt(0, suitable_count - 1);
214 return suitable_renderers[random_index]; 216 return suitable_renderers[random_index];
215 } 217 }
216 218
217 return NULL; 219 return NULL;
218 } 220 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host.h ('k') | content/browser/renderer_host/render_view_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698