OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/common/url_schemes.h" | 28 #include "content/common/url_schemes.h" |
29 #include "content/public/app/content_main_delegate.h" | 29 #include "content/public/app/content_main_delegate.h" |
30 #include "content/public/app/startup_helper_win.h" | 30 #include "content/public/app/startup_helper_win.h" |
31 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
32 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
33 #include "content/public/common/content_constants.h" | 33 #include "content/public/common/content_constants.h" |
34 #include "content/public/common/content_paths.h" | 34 #include "content/public/common/content_paths.h" |
35 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/main_function_params.h" | 36 #include "content/public/common/main_function_params.h" |
37 #include "content/public/common/sandbox_init.h" | 37 #include "content/public/common/sandbox_init.h" |
38 #include "content/public/plugin/content_plugin_client.h" | |
39 #include "content/public/renderer/content_renderer_client.h" | |
40 #include "content/public/utility/content_utility_client.h" | |
41 #include "crypto/nss_util.h" | 38 #include "crypto/nss_util.h" |
42 #include "ipc/ipc_switches.h" | 39 #include "ipc/ipc_switches.h" |
43 #include "media/base/media.h" | 40 #include "media/base/media.h" |
44 #include "sandbox/win/src/sandbox_types.h" | 41 #include "sandbox/win/src/sandbox_types.h" |
45 #include "ui/base/ui_base_switches.h" | 42 #include "ui/base/ui_base_switches.h" |
46 #include "ui/base/ui_base_paths.h" | 43 #include "ui/base/ui_base_paths.h" |
47 #include "ui/base/win/dpi.h" | 44 #include "ui/base/win/dpi.h" |
48 #include "webkit/user_agent/user_agent.h" | 45 #include "webkit/user_agent/user_agent.h" |
49 | 46 |
50 #if defined(USE_TCMALLOC) | 47 #if defined(USE_TCMALLOC) |
51 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | 48 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
52 #if defined(TYPE_PROFILING) | 49 #if defined(TYPE_PROFILING) |
53 #include "base/allocator/type_profiler.h" | 50 #include "base/allocator/type_profiler.h" |
54 #include "base/allocator/type_profiler_tcmalloc.h" | 51 #include "base/allocator/type_profiler_tcmalloc.h" |
55 #endif | 52 #endif |
56 #endif | 53 #endif |
57 | 54 |
| 55 #if !defined(OS_IOS) |
| 56 #include "content/public/plugin/content_plugin_client.h" |
| 57 #include "content/public/renderer/content_renderer_client.h" |
| 58 #include "content/public/utility/content_utility_client.h" |
| 59 #endif |
| 60 |
58 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
59 #include <cstring> | 62 #include <cstring> |
60 #include <atlbase.h> | 63 #include <atlbase.h> |
61 #include <atlapp.h> | 64 #include <atlapp.h> |
62 #include <malloc.h> | 65 #include <malloc.h> |
63 #elif defined(OS_MACOSX) | 66 #elif defined(OS_MACOSX) |
64 #include "base/mac/scoped_nsautorelease_pool.h" | 67 #include "base/mac/scoped_nsautorelease_pool.h" |
65 #if !defined(OS_IOS) | 68 #if !defined(OS_IOS) |
66 #include "base/mach_ipc_mac.h" | 69 #include "base/mach_ipc_mac.h" |
67 #include "base/system_monitor/system_monitor.h" | 70 #include "base/system_monitor/system_monitor.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 NOTREACHED(); | 154 NOTREACHED(); |
152 } | 155 } |
153 } | 156 } |
154 #endif // defined(OS_WIN) | 157 #endif // defined(OS_WIN) |
155 } // namespace | 158 } // namespace |
156 | 159 |
157 namespace content { | 160 namespace content { |
158 | 161 |
159 base::LazyInstance<ContentBrowserClient> | 162 base::LazyInstance<ContentBrowserClient> |
160 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; | 163 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; |
| 164 #if !defined(OS_IOS) |
161 base::LazyInstance<ContentPluginClient> | 165 base::LazyInstance<ContentPluginClient> |
162 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; | 166 g_empty_content_plugin_client = LAZY_INSTANCE_INITIALIZER; |
163 base::LazyInstance<ContentRendererClient> | 167 base::LazyInstance<ContentRendererClient> |
164 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 168 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
165 base::LazyInstance<ContentUtilityClient> | 169 base::LazyInstance<ContentUtilityClient> |
166 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 170 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
| 171 #endif // !OS_IOS |
167 | 172 |
168 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
169 | 174 |
170 static CAppModule _Module; | 175 static CAppModule _Module; |
171 | 176 |
172 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 177 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
173 | 178 |
174 // Completes the Mach IPC handshake by sending this process' task port to the | 179 // Completes the Mach IPC handshake by sending this process' task port to the |
175 // parent process. The parent is listening on the Mach port given by | 180 // parent process. The parent is listening on the Mach port given by |
176 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory | 181 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory |
(...skipping 12 matching lines...) Expand all Loading... |
189 base::MachPortSender child_sender(mach_port_name.c_str()); | 194 base::MachPortSender child_sender(mach_port_name.c_str()); |
190 kern_return_t err = child_sender.SendMessage(child_message, kTimeoutMs); | 195 kern_return_t err = child_sender.SendMessage(child_message, kTimeoutMs); |
191 if (err != KERN_SUCCESS) { | 196 if (err != KERN_SUCCESS) { |
192 LOG(ERROR) << StringPrintf("child SendMessage() failed: 0x%x %s", err, | 197 LOG(ERROR) << StringPrintf("child SendMessage() failed: 0x%x %s", err, |
193 mach_error_string(err)); | 198 mach_error_string(err)); |
194 } | 199 } |
195 } | 200 } |
196 | 201 |
197 #endif // defined(OS_WIN) | 202 #endif // defined(OS_WIN) |
198 | 203 |
199 #if defined(OS_POSIX) | 204 #if defined(OS_POSIX) && !defined(OS_IOS) |
200 | 205 |
201 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. | 206 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. |
202 void SetupSignalHandlers() { | 207 void SetupSignalHandlers() { |
203 // Sanitise our signal handling state. Signals that were ignored by our | 208 // Sanitise our signal handling state. Signals that were ignored by our |
204 // parent will also be ignored by us. We also inherit our parent's sigmask. | 209 // parent will also be ignored by us. We also inherit our parent's sigmask. |
205 sigset_t empty_signal_set; | 210 sigset_t empty_signal_set; |
206 CHECK(0 == sigemptyset(&empty_signal_set)); | 211 CHECK(0 == sigemptyset(&empty_signal_set)); |
207 CHECK(0 == sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); | 212 CHECK(0 == sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); |
208 | 213 |
209 struct sigaction sigact; | 214 struct sigaction sigact; |
210 memset(&sigact, 0, sizeof(sigact)); | 215 memset(&sigact, 0, sizeof(sigact)); |
211 sigact.sa_handler = SIG_DFL; | 216 sigact.sa_handler = SIG_DFL; |
212 static const int signals_to_reset[] = | 217 static const int signals_to_reset[] = |
213 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, | 218 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, |
214 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. | 219 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. |
215 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { | 220 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { |
216 CHECK(0 == sigaction(signals_to_reset[i], &sigact, NULL)); | 221 CHECK(0 == sigaction(signals_to_reset[i], &sigact, NULL)); |
217 } | 222 } |
218 | 223 |
219 // Always ignore SIGPIPE. We check the return value of write(). | 224 // Always ignore SIGPIPE. We check the return value of write(). |
220 CHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR); | 225 CHECK(signal(SIGPIPE, SIG_IGN) != SIG_ERR); |
221 } | 226 } |
222 | 227 |
223 #endif // OS_POSIX | 228 #endif // OS_POSIX && !OS_IOS |
224 | 229 |
225 void CommonSubprocessInit(const std::string& process_type) { | 230 void CommonSubprocessInit(const std::string& process_type) { |
226 #if defined(OS_WIN) | 231 #if defined(OS_WIN) |
227 // HACK: Let Windows know that we have started. This is needed to suppress | 232 // HACK: Let Windows know that we have started. This is needed to suppress |
228 // the IDC_APPSTARTING cursor from being displayed for a prolonged period | 233 // the IDC_APPSTARTING cursor from being displayed for a prolonged period |
229 // while a subprocess is starting. | 234 // while a subprocess is starting. |
230 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); | 235 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); |
231 MSG msg; | 236 MSG msg; |
232 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); | 237 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); |
233 #endif | 238 #endif |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 static void Set(const std::string& process_type, | 306 static void Set(const std::string& process_type, |
302 ContentMainDelegate* delegate) { | 307 ContentMainDelegate* delegate) { |
303 ContentClient* content_client = GetContentClient(); | 308 ContentClient* content_client = GetContentClient(); |
304 if (process_type.empty()) { | 309 if (process_type.empty()) { |
305 if (delegate) | 310 if (delegate) |
306 content_client->browser_ = delegate->CreateContentBrowserClient(); | 311 content_client->browser_ = delegate->CreateContentBrowserClient(); |
307 if (!content_client->browser_) | 312 if (!content_client->browser_) |
308 content_client->browser_ = &g_empty_content_browser_client.Get(); | 313 content_client->browser_ = &g_empty_content_browser_client.Get(); |
309 } | 314 } |
310 | 315 |
| 316 #if !defined(OS_IOS) |
311 if (process_type == switches::kPluginProcess || | 317 if (process_type == switches::kPluginProcess || |
312 process_type == switches::kPpapiPluginProcess) { | 318 process_type == switches::kPpapiPluginProcess) { |
313 if (delegate) | 319 if (delegate) |
314 content_client->plugin_ = delegate->CreateContentPluginClient(); | 320 content_client->plugin_ = delegate->CreateContentPluginClient(); |
315 if (!content_client->plugin_) | 321 if (!content_client->plugin_) |
316 content_client->plugin_ = &g_empty_content_plugin_client.Get(); | 322 content_client->plugin_ = &g_empty_content_plugin_client.Get(); |
317 } else if (process_type == switches::kRendererProcess || | 323 } else if (process_type == switches::kRendererProcess || |
318 CommandLine::ForCurrentProcess()->HasSwitch( | 324 CommandLine::ForCurrentProcess()->HasSwitch( |
319 switches::kSingleProcess)) { | 325 switches::kSingleProcess)) { |
320 if (delegate) | 326 if (delegate) |
321 content_client->renderer_ = delegate->CreateContentRendererClient(); | 327 content_client->renderer_ = delegate->CreateContentRendererClient(); |
322 if (!content_client->renderer_) | 328 if (!content_client->renderer_) |
323 content_client->renderer_ = &g_empty_content_renderer_client.Get(); | 329 content_client->renderer_ = &g_empty_content_renderer_client.Get(); |
324 } else if (process_type == switches::kUtilityProcess) { | 330 } else if (process_type == switches::kUtilityProcess) { |
325 if (delegate) | 331 if (delegate) |
326 content_client->utility_ = delegate->CreateContentUtilityClient(); | 332 content_client->utility_ = delegate->CreateContentUtilityClient(); |
327 if (!content_client->utility_) | 333 if (!content_client->utility_) |
328 content_client->utility_ = &g_empty_content_utility_client.Get(); | 334 content_client->utility_ = &g_empty_content_utility_client.Get(); |
329 } | 335 } |
| 336 #endif // !OS_IOS |
330 } | 337 } |
331 }; | 338 }; |
332 | 339 |
333 // We dispatch to a process-type-specific FooMain() based on a command-line | 340 // We dispatch to a process-type-specific FooMain() based on a command-line |
334 // flag. This struct is used to build a table of (flag, main function) pairs. | 341 // flag. This struct is used to build a table of (flag, main function) pairs. |
335 struct MainFunction { | 342 struct MainFunction { |
336 const char* name; | 343 const char* name; |
337 int (*function)(const MainFunctionParams&); | 344 int (*function)(const MainFunctionParams&); |
338 }; | 345 }; |
339 | 346 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 799 |
793 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 800 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
794 }; | 801 }; |
795 | 802 |
796 // static | 803 // static |
797 ContentMainRunner* ContentMainRunner::Create() { | 804 ContentMainRunner* ContentMainRunner::Create() { |
798 return new ContentMainRunnerImpl(); | 805 return new ContentMainRunnerImpl(); |
799 } | 806 } |
800 | 807 |
801 } // namespace content | 808 } // namespace content |
OLD | NEW |