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

Side by Side Diff: chrome/browser/browser_main.cc

Issue 125151: Add a switch for changing the fd limit on Mac/Linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | « no previous file | chrome/common/chrome_switches.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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
54 #include "grit/net_resources.h" 54 #include "grit/net_resources.h"
55 #include "net/base/cookie_monster.h" 55 #include "net/base/cookie_monster.h"
56 #include "net/base/net_module.h" 56 #include "net/base/net_module.h"
57 #include "net/http/http_network_session.h" 57 #include "net/http/http_network_session.h"
58 58
59 #if defined(OS_POSIX) 59 #if defined(OS_POSIX)
60 // TODO(port): get rid of this include. It's used just to provide declarations 60 // TODO(port): get rid of this include. It's used just to provide declarations
61 // and stub definitions for classes we encouter during the porting effort. 61 // and stub definitions for classes we encouter during the porting effort.
62 #include "chrome/common/temp_scaffolding_stubs.h" 62 #include "chrome/common/temp_scaffolding_stubs.h"
63 #include <errno.h>
63 #include <signal.h> 64 #include <signal.h>
65 #include <sys/resource.h>
64 #endif 66 #endif
65 67
66 #if defined(OS_LINUX) 68 #if defined(OS_LINUX)
67 #include "chrome/app/breakpad_linux.h" 69 #include "chrome/app/breakpad_linux.h"
68 #endif 70 #endif
69 71
70 // TODO(port): several win-only methods have been pulled out of this, but 72 // TODO(port): several win-only methods have been pulled out of this, but
71 // BrowserMain() as a whole needs to be broken apart so that it's usable by 73 // BrowserMain() as a whole needs to be broken apart so that it's usable by
72 // other platforms. For now, it's just a stub. This is a serious work in 74 // other platforms. For now, it's just a stub. This is a serious work in
73 // progress and should not be taken as an indication of a real refactoring. 75 // progress and should not be taken as an indication of a real refactoring.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 MessageLoopForUI::current()->Run(browser_process->accelerator_handler()); 192 MessageLoopForUI::current()->Run(browser_process->accelerator_handler());
191 #elif defined(OS_POSIX) 193 #elif defined(OS_POSIX)
192 MessageLoopForUI::current()->Run(); 194 MessageLoopForUI::current()->Run();
193 #endif 195 #endif
194 } 196 }
195 197
196 #if defined(OS_POSIX) 198 #if defined(OS_POSIX)
197 // See comment below, where sigaction is called. 199 // See comment below, where sigaction is called.
198 void SIGCHLDHandler(int signal) { 200 void SIGCHLDHandler(int signal) {
199 } 201 }
202
203 // Sets the file descriptor soft limit to |max_descriptors| or the OS hard
204 // limit, whichever is lower.
205 void SetFileDescriptorLimit(unsigned int max_descriptors) {
206 struct rlimit limits;
207 if (getrlimit(RLIMIT_NOFILE, &limits) == 0) {
208 unsigned int new_limit = max_descriptors;
209 if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) {
210 new_limit = limits.rlim_max;
211 }
212 limits.rlim_cur = new_limit;
213 if (setrlimit(RLIMIT_NOFILE, &limits) != 0) {
214 LOG(INFO) << "Failed to set file descriptor limit: " << strerror(errno);
215 }
216 } else {
217 LOG(INFO) << "Failed to get file descriptor limit: " << strerror(errno);
218 }
219 }
200 #endif 220 #endif
201 221
202 #if defined(OS_WIN) 222 #if defined(OS_WIN)
203 void AddFirstRunNewTabs(BrowserInit* browser_init, 223 void AddFirstRunNewTabs(BrowserInit* browser_init,
204 const std::vector<std::wstring>& new_tabs) { 224 const std::vector<std::wstring>& new_tabs) {
205 std::vector<std::wstring>::const_iterator it = new_tabs.begin(); 225 std::vector<std::wstring>::const_iterator it = new_tabs.begin();
206 while (it != new_tabs.end()) { 226 while (it != new_tabs.end()) {
207 GURL url(*it); 227 GURL url(*it);
208 if (url.is_valid()) 228 if (url.is_valid())
209 browser_init->AddFirstRunTab(url); 229 browser_init->AddFirstRunTab(url);
(...skipping 28 matching lines...) Expand all
238 tracked_objects::AutoTracking tracking_objects; 258 tracked_objects::AutoTracking tracking_objects;
239 #endif 259 #endif
240 260
241 #if defined(OS_POSIX) 261 #if defined(OS_POSIX)
242 // We need to accept SIGCHLD, even though our handler is a no-op because 262 // We need to accept SIGCHLD, even though our handler is a no-op because
243 // otherwise we cannot wait on children. (According to POSIX 2001.) 263 // otherwise we cannot wait on children. (According to POSIX 2001.)
244 struct sigaction action; 264 struct sigaction action;
245 memset(&action, 0, sizeof(action)); 265 memset(&action, 0, sizeof(action));
246 action.sa_handler = SIGCHLDHandler; 266 action.sa_handler = SIGCHLDHandler;
247 CHECK(sigaction(SIGCHLD, &action, NULL) == 0); 267 CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
248 #endif 268
269 const std::wstring fd_limit_string =
270 parsed_command_line.GetSwitchValue(switches::kFileDescriptorLimit);
271 int fd_limit = 0;
272 if (!fd_limit_string.empty()) {
273 StringToInt(WideToUTF16Hack(fd_limit_string), &fd_limit);
274 }
275 #if defined(OS_MACOSX)
276 // We use quite a few file descriptors for our IPC, and the default limit on
277 // the Mac is low (256), so bump it up if there is no explicit override.
278 if (fd_limit == 0) {
279 fd_limit = 1024;
280 }
281 #endif // OS_MACOSX
282 if (fd_limit > 0) {
283 SetFileDescriptorLimit(fd_limit);
284 }
285 #endif // OS_POSIX
249 286
250 // Do platform-specific things (such as finishing initializing Cocoa) 287 // Do platform-specific things (such as finishing initializing Cocoa)
251 // prior to instantiating the message loop. This could be turned into a 288 // prior to instantiating the message loop. This could be turned into a
252 // broadcast notification. 289 // broadcast notification.
253 Platform::WillInitializeMainMessageLoop(parsed_command_line); 290 Platform::WillInitializeMainMessageLoop(parsed_command_line);
254 291
255 MessageLoop main_message_loop(MessageLoop::TYPE_UI); 292 MessageLoop main_message_loop(MessageLoop::TYPE_UI);
256 293
257 // Initialize the SystemMonitor 294 // Initialize the SystemMonitor
258 base::SystemMonitor::Start(); 295 base::SystemMonitor::Start();
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 if (metrics) 803 if (metrics)
767 metrics->Stop(); 804 metrics->Stop();
768 805
769 // browser_shutdown takes care of deleting browser_process, so we need to 806 // browser_shutdown takes care of deleting browser_process, so we need to
770 // release it. 807 // release it.
771 browser_process.release(); 808 browser_process.release();
772 browser_shutdown::Shutdown(); 809 browser_shutdown::Shutdown();
773 810
774 return result_code; 811 return result_code;
775 } 812 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698