|
27 | 27 | #include "base/threading/thread_restrictions.h" |
28 | 28 | #include "base/utf_string_conversions.h" |
29 | 29 | #include "base/values.h" |
| 30 | +#include "chrome/common/chrome_switches.h" |
30 | 31 | #include "content/nw/src/api/app/app.h" |
31 | 32 | #include "content/nw/src/browser/printing/print_job_manager.h" |
32 | 33 | #include "content/nw/src/browser/shell_devtools_delegate.h" |
|
41 | 42 | #include "net/proxy/proxy_resolver_v8.h" |
42 | 43 | #include "ui/base/resource/resource_bundle.h" |
43 | 44 |
|
| 45 | +#if !defined(OS_WIN) |
| 46 | +#include <sys/resource.h> |
| 47 | +#endif |
| 48 | + |
44 | 49 | #if defined(TOOLKIT_GTK) |
45 | 50 | #include "content/nw/src/browser/printing/print_dialog_gtk.h" |
46 | 51 | #endif |
47 | 52 |
|
48 | 53 | namespace { |
49 | 54 |
|
| 55 | +#if !defined(OS_WIN) |
| 56 | +// Sets the file descriptor soft limit to |max_descriptors| or the OS hard |
| 57 | +// limit, whichever is lower. |
| 58 | +void SetFileDescriptorLimit(unsigned int max_descriptors) { |
| 59 | + struct rlimit limits; |
| 60 | + if (getrlimit(RLIMIT_NOFILE, &limits) == 0) { |
| 61 | + unsigned int new_limit = max_descriptors; |
| 62 | + if (limits.rlim_max > 0 && limits.rlim_max < max_descriptors) { |
| 63 | + new_limit = limits.rlim_max; |
| 64 | + } |
| 65 | + limits.rlim_cur = new_limit; |
| 66 | + if (setrlimit(RLIMIT_NOFILE, &limits) != 0) { |
| 67 | + PLOG(INFO) << "Failed to set file descriptor limit"; |
| 68 | + } |
| 69 | + } else { |
| 70 | + PLOG(INFO) << "Failed to get file descriptor limit"; |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +#endif |
| 75 | + |
50 | 76 | base::StringPiece PlatformResourceProvider(int key) { |
51 | 77 | if (key == IDR_DIR_HEADER_HTML) { |
52 | 78 | base::StringPiece html_data = |
@@ -203,4 +229,26 @@ printing::PrintJobManager* ShellBrowserMainParts::print_job_manager() { |
203 | 229 | return print_job_manager_.get(); |
204 | 230 | } |
205 | 231 |
|
| 232 | +void ShellBrowserMainParts::PreEarlyInitialization() { |
| 233 | +#if !defined(OS_WIN) |
| 234 | + // see chrome_browser_main_posix.cc |
| 235 | + CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 236 | + const std::string fd_limit_string = |
| 237 | + command_line.GetSwitchValueASCII(switches::kFileDescriptorLimit); |
| 238 | + int fd_limit = 0; |
| 239 | + if (!fd_limit_string.empty()) { |
| 240 | + base::StringToInt(fd_limit_string, &fd_limit); |
| 241 | + } |
| 242 | +#if defined(OS_MACOSX) |
| 243 | + // We use quite a few file descriptors for our IPC, and the default limit on |
| 244 | + // the Mac is low (256), so bump it up if there is no explicit override. |
| 245 | + if (fd_limit == 0) { |
| 246 | + fd_limit = 1024; |
| 247 | + } |
| 248 | +#endif // OS_MACOSX |
| 249 | + if (fd_limit > 0) |
| 250 | + SetFileDescriptorLimit(fd_limit); |
| 251 | +#endif // !OS_WIN |
| 252 | +} |
| 253 | + |
206 | 254 | } // namespace content |
0 commit comments