| 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 #include "chrome/browser/renderer_host/render_process_host.h" | 5 #include "chrome/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/child_process_security_policy.h" | 9 #include "chrome/browser/child_process_security_policy.h" |
| 10 #include "chrome/common/child_process_info.h" | 10 #include "chrome/common/child_process_info.h" |
| 11 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 12 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 size_t max_renderer_count_override = 0; |
| 17 |
| 16 size_t GetMaxRendererProcessCount() { | 18 size_t GetMaxRendererProcessCount() { |
| 19 if (max_renderer_count_override) |
| 20 return max_renderer_count_override; |
| 21 |
| 17 // Defines the maximum number of renderer processes according to the | 22 // Defines the maximum number of renderer processes according to the |
| 18 // amount of installed memory as reported by the OS. The table | 23 // amount of installed memory as reported by the OS. The table |
| 19 // values are calculated by assuming that you want the renderers to | 24 // values are calculated by assuming that you want the renderers to |
| 20 // use half of the installed ram and assuming that each tab uses | 25 // use half of the installed ram and assuming that each tab uses |
| 21 // ~40MB, however the curve is not linear but piecewise linear with | 26 // ~40MB, however the curve is not linear but piecewise linear with |
| 22 // interleaved slopes of 3 and 2. | 27 // interleaved slopes of 3 and 2. |
| 23 // If you modify this table you need to adjust browser\browser_uitest.cc | 28 // If you modify this table you need to adjust browser\browser_uitest.cc |
| 24 // to match the expected number of processes. | 29 // to match the expected number of processes. |
| 25 | 30 |
| 26 static const size_t kMaxRenderersByRamTier[] = { | 31 static const size_t kMaxRenderersByRamTier[] = { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 host_type = RenderProcessHost::TYPE_EXTENSION; | 72 host_type = RenderProcessHost::TYPE_EXTENSION; |
| 68 | 73 |
| 69 return host_type == type; | 74 return host_type == type; |
| 70 } | 75 } |
| 71 | 76 |
| 72 // the global list of all renderer processes | 77 // the global list of all renderer processes |
| 73 IDMap<RenderProcessHost> all_hosts; | 78 IDMap<RenderProcessHost> all_hosts; |
| 74 | 79 |
| 75 } // namespace | 80 } // namespace |
| 76 | 81 |
| 82 // static |
| 77 bool RenderProcessHost::run_renderer_in_process_ = false; | 83 bool RenderProcessHost::run_renderer_in_process_ = false; |
| 78 | 84 |
| 85 // static |
| 86 void RenderProcessHost::SetMaxRendererProcessCount(size_t count) { |
| 87 max_renderer_count_override = count; |
| 88 } |
| 89 |
| 79 RenderProcessHost::RenderProcessHost(Profile* profile) | 90 RenderProcessHost::RenderProcessHost(Profile* profile) |
| 80 : max_page_id_(-1), | 91 : max_page_id_(-1), |
| 81 fast_shutdown_started_(false), | 92 fast_shutdown_started_(false), |
| 82 id_(ChildProcessInfo::GenerateChildProcessUniqueId()), | 93 id_(ChildProcessInfo::GenerateChildProcessUniqueId()), |
| 83 profile_(profile), | 94 profile_(profile), |
| 84 sudden_termination_allowed_(true), | 95 sudden_termination_allowed_(true), |
| 85 ignore_input_events_(false) { | 96 ignore_input_events_(false) { |
| 86 all_hosts.AddWithID(this, id()); | 97 all_hosts.AddWithID(this, id()); |
| 87 all_hosts.set_check_on_null_data(true); | 98 all_hosts.set_check_on_null_data(true); |
| 88 // Initialize |child_process_activity_time_| to a reasonable value. | 99 // Initialize |child_process_activity_time_| to a reasonable value. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 188 |
| 178 // Now pick a random suitable renderer, if we have any. | 189 // Now pick a random suitable renderer, if we have any. |
| 179 if (!suitable_renderers.empty()) { | 190 if (!suitable_renderers.empty()) { |
| 180 int suitable_count = static_cast<int>(suitable_renderers.size()); | 191 int suitable_count = static_cast<int>(suitable_renderers.size()); |
| 181 int random_index = base::RandInt(0, suitable_count - 1); | 192 int random_index = base::RandInt(0, suitable_count - 1); |
| 182 return suitable_renderers[random_index]; | 193 return suitable_renderers[random_index]; |
| 183 } | 194 } |
| 184 | 195 |
| 185 return NULL; | 196 return NULL; |
| 186 } | 197 } |
| OLD | NEW |