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

Side by Side Diff: content/app/content_main.cc

Issue 8387039: Move content_restriction.h and main_function_params.h to content/public/common, and put them in t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | « chrome/service/service_main.cc ('k') | content/browser/browser_main.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) 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/app/content_main.h" 5 #include "content/app/content_main.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/debugger.h" 9 #include "base/debug/debugger.h"
10 #include "base/i18n/icu_util.h" 10 #include "base/i18n/icu_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/stats_table.h" 13 #include "base/metrics/stats_table.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "content/browser/browser_main.h" 17 #include "content/browser/browser_main.h"
18 #include "content/common/main_function_params.h"
19 #include "content/common/set_process_title.h" 18 #include "content/common/set_process_title.h"
20 #include "content/public/app/content_main_delegate.h" 19 #include "content/public/app/content_main_delegate.h"
21 #include "content/public/app/startup_helper_win.h" 20 #include "content/public/app/startup_helper_win.h"
22 #include "content/public/common/content_client.h" 21 #include "content/public/common/content_client.h"
23 #include "content/public/common/content_constants.h" 22 #include "content/public/common/content_constants.h"
24 #include "content/public/common/content_paths.h" 23 #include "content/public/common/content_paths.h"
25 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
25 #include "content/public/common/main_function_params.h"
26 #include "content/public/common/sandbox_init.h" 26 #include "content/public/common/sandbox_init.h"
27 #include "crypto/nss_util.h" 27 #include "crypto/nss_util.h"
28 #include "ipc/ipc_switches.h" 28 #include "ipc/ipc_switches.h"
29 #include "ui/base/ui_base_switches.h" 29 #include "ui/base/ui_base_switches.h"
30 #include "ui/base/ui_base_paths.h" 30 #include "ui/base/ui_base_paths.h"
31 #include "webkit/glue/webkit_glue.h" 31 #include "webkit/glue/webkit_glue.h"
32 32
33 #if defined(OS_WIN) 33 #if defined(OS_WIN)
34 #include <atlbase.h> 34 #include <atlbase.h>
35 #include <atlapp.h> 35 #include <atlapp.h>
(...skipping 16 matching lines...) Expand all
52 #endif 52 #endif
53 53
54 #endif // OS_POSIX 54 #endif // OS_POSIX
55 55
56 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) 56 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
57 extern "C" { 57 extern "C" {
58 int tc_set_new_mode(int mode); 58 int tc_set_new_mode(int mode);
59 } 59 }
60 #endif 60 #endif
61 61
62 extern int GpuMain(const MainFunctionParams&); 62 extern int GpuMain(const content::MainFunctionParams&);
63 extern int PluginMain(const MainFunctionParams&); 63 extern int PluginMain(const content::MainFunctionParams&);
64 extern int PpapiPluginMain(const MainFunctionParams&); 64 extern int PpapiPluginMain(const content::MainFunctionParams&);
65 extern int PpapiBrokerMain(const MainFunctionParams&); 65 extern int PpapiBrokerMain(const content::MainFunctionParams&);
66 extern int RendererMain(const MainFunctionParams&); 66 extern int RendererMain(const content::MainFunctionParams&);
67 extern int WorkerMain(const MainFunctionParams&); 67 extern int WorkerMain(const content::MainFunctionParams&);
68 extern int UtilityMain(const MainFunctionParams&); 68 extern int UtilityMain(const content::MainFunctionParams&);
69 #if defined(OS_POSIX) && !defined(OS_MACOSX) 69 #if defined(OS_POSIX) && !defined(OS_MACOSX)
70 extern int ZygoteMain(const MainFunctionParams&, 70 extern int ZygoteMain(const content::MainFunctionParams&,
71 content::ZygoteForkDelegate* forkdelegate); 71 content::ZygoteForkDelegate* forkdelegate);
72 #endif 72 #endif
73 73
74 namespace { 74 namespace {
75 75
76 #if defined(OS_WIN) 76 #if defined(OS_WIN)
77 77
78 static CAppModule _Module; 78 static CAppModule _Module;
79 79
80 #elif defined(OS_MACOSX) 80 #elif defined(OS_MACOSX)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 base::StatsTable* stats_table = new base::StatsTable(statsfile, 169 base::StatsTable* stats_table = new base::StatsTable(statsfile,
170 content::kStatsMaxThreads, content::kStatsMaxCounters); 170 content::kStatsMaxThreads, content::kStatsMaxCounters);
171 base::StatsTable::set_current(stats_table); 171 base::StatsTable::set_current(stats_table);
172 } 172 }
173 } 173 }
174 174
175 // We dispatch to a process-type-specific FooMain() based on a command-line 175 // We dispatch to a process-type-specific FooMain() based on a command-line
176 // flag. This struct is used to build a table of (flag, main function) pairs. 176 // flag. This struct is used to build a table of (flag, main function) pairs.
177 struct MainFunction { 177 struct MainFunction {
178 const char* name; 178 const char* name;
179 int (*function)(const MainFunctionParams&); 179 int (*function)(const content::MainFunctionParams&);
180 }; 180 };
181 181
182 #if defined(OS_POSIX) && !defined(OS_MACOSX) 182 #if defined(OS_POSIX) && !defined(OS_MACOSX)
183 // On platforms that use the zygote, we have a special subset of 183 // On platforms that use the zygote, we have a special subset of
184 // subprocesses that are launched via the zygote. This function 184 // subprocesses that are launched via the zygote. This function
185 // fills in some process-launching bits around ZygoteMain(). 185 // fills in some process-launching bits around ZygoteMain().
186 // Returns the exit code of the subprocess. 186 // Returns the exit code of the subprocess.
187 int RunZygote(const MainFunctionParams& main_function_params, 187 int RunZygote(const content::MainFunctionParams& main_function_params,
188 content::ContentMainDelegate* delegate) { 188 content::ContentMainDelegate* delegate) {
189 static const MainFunction kMainFunctions[] = { 189 static const MainFunction kMainFunctions[] = {
190 { switches::kRendererProcess, RendererMain }, 190 { switches::kRendererProcess, RendererMain },
191 { switches::kWorkerProcess, WorkerMain }, 191 { switches::kWorkerProcess, WorkerMain },
192 { switches::kPpapiPluginProcess, PpapiPluginMain }, 192 { switches::kPpapiPluginProcess, PpapiPluginMain },
193 }; 193 };
194 194
195 scoped_ptr<content::ZygoteForkDelegate> zygote_fork_delegate; 195 scoped_ptr<content::ZygoteForkDelegate> zygote_fork_delegate;
196 if (delegate) zygote_fork_delegate.reset(delegate->ZygoteStarting()); 196 if (delegate) zygote_fork_delegate.reset(delegate->ZygoteStarting());
197 197
(...skipping 14 matching lines...) Expand all
212 std::string ua = content::GetContentClient()->GetUserAgent(&custom); 212 std::string ua = content::GetContentClient()->GetUserAgent(&custom);
213 if (custom) webkit_glue::SetUserAgent(ua, custom); 213 if (custom) webkit_glue::SetUserAgent(ua, custom);
214 214
215 // The StatsTable must be initialized in each process; we already 215 // The StatsTable must be initialized in each process; we already
216 // initialized for the browser process, now we need to initialize 216 // initialized for the browser process, now we need to initialize
217 // within the new processes as well. 217 // within the new processes as well.
218 pid_t browser_pid = base::GetParentProcessId( 218 pid_t browser_pid = base::GetParentProcessId(
219 base::GetParentProcessId(base::GetCurrentProcId())); 219 base::GetParentProcessId(base::GetCurrentProcId()));
220 InitializeStatsTable(browser_pid, command_line); 220 InitializeStatsTable(browser_pid, command_line);
221 221
222 MainFunctionParams main_params(command_line); 222 content::MainFunctionParams main_params(command_line);
223 223
224 // Get the new process type from the new command line. 224 // Get the new process type from the new command line.
225 std::string process_type = 225 std::string process_type =
226 command_line.GetSwitchValueASCII(switches::kProcessType); 226 command_line.GetSwitchValueASCII(switches::kProcessType);
227 227
228 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { 228 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) {
229 if (process_type == kMainFunctions[i].name) 229 if (process_type == kMainFunctions[i].name)
230 return kMainFunctions[i].function(main_params); 230 return kMainFunctions[i].function(main_params);
231 } 231 }
232 232
233 if (delegate) 233 if (delegate)
234 return delegate->RunProcess(process_type, main_params); 234 return delegate->RunProcess(process_type, main_params);
235 235
236 NOTREACHED() << "Unknown zygote process type: " << process_type; 236 NOTREACHED() << "Unknown zygote process type: " << process_type;
237 return 1; 237 return 1;
238 } 238 }
239 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) 239 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
240 240
241 // Run the FooMain() for a given process type. 241 // Run the FooMain() for a given process type.
242 // If |process_type| is empty, runs BrowserMain(). 242 // If |process_type| is empty, runs BrowserMain().
243 // Returns the exit code for this process. 243 // Returns the exit code for this process.
244 int RunNamedProcessTypeMain(const std::string& process_type, 244 int RunNamedProcessTypeMain(
245 const MainFunctionParams& main_function_params, 245 const std::string& process_type,
246 content::ContentMainDelegate* delegate) { 246 const content::MainFunctionParams& main_function_params,
247 content::ContentMainDelegate* delegate) {
247 static const MainFunction kMainFunctions[] = { 248 static const MainFunction kMainFunctions[] = {
248 { "", BrowserMain }, 249 { "", BrowserMain },
249 { switches::kRendererProcess, RendererMain }, 250 { switches::kRendererProcess, RendererMain },
250 { switches::kPluginProcess, PluginMain }, 251 { switches::kPluginProcess, PluginMain },
251 { switches::kWorkerProcess, WorkerMain }, 252 { switches::kWorkerProcess, WorkerMain },
252 { switches::kPpapiPluginProcess, PpapiPluginMain }, 253 { switches::kPpapiPluginProcess, PpapiPluginMain },
253 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, 254 { switches::kPpapiBrokerProcess, PpapiBrokerMain },
254 { switches::kUtilityProcess, UtilityMain }, 255 { switches::kUtilityProcess, UtilityMain },
255 { switches::kGpuProcess, GpuMain }, 256 { switches::kGpuProcess, GpuMain },
256 }; 257 };
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 CHECK(content::InitializeSandbox()); 429 CHECK(content::InitializeSandbox());
429 } 430 }
430 #endif 431 #endif
431 432
432 if (delegate) delegate->SandboxInitialized(process_type); 433 if (delegate) delegate->SandboxInitialized(process_type);
433 434
434 #if defined(OS_POSIX) 435 #if defined(OS_POSIX)
435 SetProcessTitleFromCommandLine(argv); 436 SetProcessTitleFromCommandLine(argv);
436 #endif 437 #endif
437 438
438 MainFunctionParams main_params(command_line); 439 content::MainFunctionParams main_params(command_line);
439 #if defined(OS_WIN) 440 #if defined(OS_WIN)
440 main_params.sandbox_info = sandbox_info; 441 main_params.sandbox_info = sandbox_info;
441 #elif defined(OS_MACOSX) 442 #elif defined(OS_MACOSX)
442 main_params.autorelease_pool = &autorelease_pool; 443 main_params.autorelease_pool = &autorelease_pool;
443 #endif 444 #endif
444 445
445 exit_code = RunNamedProcessTypeMain(process_type, main_params, delegate); 446 exit_code = RunNamedProcessTypeMain(process_type, main_params, delegate);
446 447
447 if (delegate) delegate->ProcessExiting(process_type); 448 if (delegate) delegate->ProcessExiting(process_type);
448 449
449 #if defined(OS_WIN) 450 #if defined(OS_WIN)
450 #ifdef _CRTDBG_MAP_ALLOC 451 #ifdef _CRTDBG_MAP_ALLOC
451 _CrtDumpMemoryLeaks(); 452 _CrtDumpMemoryLeaks();
452 #endif // _CRTDBG_MAP_ALLOC 453 #endif // _CRTDBG_MAP_ALLOC
453 454
454 _Module.Term(); 455 _Module.Term();
455 #endif // OS_WIN 456 #endif // OS_WIN
456 457
457 return exit_code; 458 return exit_code;
458 } 459 }
459 460
460 } // namespace content 461 } // namespace content
OLDNEW
« no previous file with comments | « chrome/service/service_main.cc ('k') | content/browser/browser_main.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698