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

Side by Side Diff: chrome/app/chrome_dll_main.cc

Issue 2001009: Created a new process type called the service process to host background task... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 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/app/dummy_main_functions.cc » ('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) 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 // TODO(port): the ifdefs in here are a first step towards trying to determine 5 // TODO(port): the ifdefs in here are a first step towards trying to determine
6 // the correct abstraction for all the OS functionality required at this 6 // the correct abstraction for all the OS functionality required at this
7 // stage of process initialization. It should not be taken as a final 7 // stage of process initialization. It should not be taken as a final
8 // abstraction. 8 // abstraction.
9 9
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 extern int GpuMain(const MainFunctionParams&); 96 extern int GpuMain(const MainFunctionParams&);
97 extern int PluginMain(const MainFunctionParams&); 97 extern int PluginMain(const MainFunctionParams&);
98 extern int WorkerMain(const MainFunctionParams&); 98 extern int WorkerMain(const MainFunctionParams&);
99 extern int NaClMain(const MainFunctionParams&); 99 extern int NaClMain(const MainFunctionParams&);
100 extern int UtilityMain(const MainFunctionParams&); 100 extern int UtilityMain(const MainFunctionParams&);
101 extern int ProfileImportMain(const MainFunctionParams&); 101 extern int ProfileImportMain(const MainFunctionParams&);
102 extern int ZygoteMain(const MainFunctionParams&); 102 extern int ZygoteMain(const MainFunctionParams&);
103 #if defined(_WIN64) 103 #if defined(_WIN64)
104 extern int NaClBrokerMain(const MainFunctionParams&); 104 extern int NaClBrokerMain(const MainFunctionParams&);
105 #endif 105 #endif
106 extern int ServiceProcessMain(const MainFunctionParams&);
106 107
107 #if defined(OS_WIN) 108 #if defined(OS_WIN)
108 // TODO(erikkay): isn't this already defined somewhere? 109 // TODO(erikkay): isn't this already defined somewhere?
109 #define DLLEXPORT __declspec(dllexport) 110 #define DLLEXPORT __declspec(dllexport)
110 111
111 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. 112 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
112 extern "C" { 113 extern "C" {
113 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, 114 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
114 sandbox::SandboxInterfaceInfo* sandbox_info, 115 sandbox::SandboxInterfaceInfo* sandbox_info,
115 TCHAR* command_line); 116 TCHAR* command_line);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 257
257 static void AdjustLinuxOOMScore(const std::string& process_type) { 258 static void AdjustLinuxOOMScore(const std::string& process_type) {
258 const int kMiscScore = 7; 259 const int kMiscScore = 7;
259 const int kPluginScore = 10; 260 const int kPluginScore = 10;
260 int score = -1; 261 int score = -1;
261 262
262 if (process_type == switches::kPluginProcess) { 263 if (process_type == switches::kPluginProcess) {
263 score = kPluginScore; 264 score = kPluginScore;
264 } else if (process_type == switches::kUtilityProcess || 265 } else if (process_type == switches::kUtilityProcess ||
265 process_type == switches::kWorkerProcess || 266 process_type == switches::kWorkerProcess ||
266 process_type == switches::kGpuProcess) { 267 process_type == switches::kGpuProcess ||
268 process_type == switches::kServiceProcess) {
267 score = kMiscScore; 269 score = kMiscScore;
268 } else if (process_type == switches::kProfileImportProcess) { 270 } else if (process_type == switches::kProfileImportProcess) {
269 NOTIMPLEMENTED(); 271 NOTIMPLEMENTED();
270 #ifndef DISABLE_NACL 272 #ifndef DISABLE_NACL
271 } else if (process_type == switches::kNaClLoaderProcess) { 273 } else if (process_type == switches::kNaClLoaderProcess) {
272 score = kPluginScore; 274 score = kPluginScore;
273 #endif 275 #endif
274 } else if (process_type == switches::kZygoteProcess || 276 } else if (process_type == switches::kZygoteProcess ||
275 process_type.empty()) { 277 process_type.empty()) {
276 // Pass - browser / zygote process stays at 0. 278 // Pass - browser / zygote process stays at 0.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 #endif 362 #endif
361 #if defined(OS_POSIX) && !defined(OS_MACOSX) 363 #if defined(OS_POSIX) && !defined(OS_MACOSX)
362 // The zygote process opens the resources for the renderers. 364 // The zygote process opens the resources for the renderers.
363 process_type == switches::kZygoteProcess || 365 process_type == switches::kZygoteProcess ||
364 #endif 366 #endif
365 process_type == switches::kRendererProcess || 367 process_type == switches::kRendererProcess ||
366 process_type == switches::kExtensionProcess || 368 process_type == switches::kExtensionProcess ||
367 process_type == switches::kUtilityProcess; 369 process_type == switches::kUtilityProcess;
368 } 370 }
369 371
372 // Returns true if this process is a child of the browser process.
373 bool SubprocessIsBrowserChild(const std::string& process_type) {
374 if (process_type.empty() || process_type == switches::kServiceProcess) {
375 return false;
376 }
377 return true;
378 }
379
370 #if defined(OS_MACOSX) 380 #if defined(OS_MACOSX)
371 // Update the name shown in Activity Monitor so users are less likely to ask 381 // Update the name shown in Activity Monitor so users are less likely to ask
372 // why Chrome has so many processes. 382 // why Chrome has so many processes.
373 void SetMacProcessName(const std::string& process_type) { 383 void SetMacProcessName(const std::string& process_type) {
374 // Don't worry about the browser process, its gets the stock name. 384 // Don't worry about the browser process, its gets the stock name.
375 int name_id = 0; 385 int name_id = 0;
376 if (process_type == switches::kRendererProcess) { 386 if (process_type == switches::kRendererProcess) {
377 name_id = IDS_RENDERER_APP_NAME; 387 name_id = IDS_RENDERER_APP_NAME;
378 } else if (process_type == switches::kPluginProcess) { 388 } else if (process_type == switches::kPluginProcess) {
379 name_id = IDS_PLUGIN_APP_NAME; 389 name_id = IDS_PLUGIN_APP_NAME;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 if (parsed_command_line.HasSwitch(switches::kEnableNaCl)) { 516 if (parsed_command_line.HasSwitch(switches::kEnableNaCl)) {
507 // NaCl currently requires two flags to run 517 // NaCl currently requires two flags to run
508 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); 518 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
509 singleton_command_line->AppendSwitch(switches::kInternalNaCl); 519 singleton_command_line->AppendSwitch(switches::kInternalNaCl);
510 singleton_command_line->AppendSwitch(switches::kEnableGPUPlugin); 520 singleton_command_line->AppendSwitch(switches::kEnableGPUPlugin);
511 } 521 }
512 522
513 base::ProcessId browser_pid; 523 base::ProcessId browser_pid;
514 if (process_type.empty()) { 524 if (process_type.empty()) {
515 browser_pid = base::GetCurrentProcId(); 525 browser_pid = base::GetCurrentProcId();
516 } else { 526 } else if (SubprocessIsBrowserChild(process_type)) {
517 #if defined(OS_WIN) 527 #if defined(OS_WIN)
518 std::wstring channel_name = 528 std::wstring channel_name =
519 parsed_command_line.GetSwitchValue(switches::kProcessChannelID); 529 parsed_command_line.GetSwitchValue(switches::kProcessChannelID);
520 530
521 browser_pid = 531 browser_pid =
522 static_cast<base::ProcessId>(StringToInt(WideToASCII(channel_name))); 532 static_cast<base::ProcessId>(StringToInt(WideToASCII(channel_name)));
523 DCHECK_NE(browser_pid, 0); 533 DCHECK_NE(browser_pid, 0);
524 #else 534 #else
525 browser_pid = base::GetCurrentProcId(); 535 browser_pid = base::GetCurrentProcId();
526 #endif 536 #endif
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 #endif 783 #endif
774 } else { 784 } else {
775 NOTREACHED() << "Unknown process type"; 785 NOTREACHED() << "Unknown process type";
776 } 786 }
777 } else { 787 } else {
778 rv = 0; 788 rv = 0;
779 } 789 }
780 #else 790 #else
781 NOTIMPLEMENTED(); 791 NOTIMPLEMENTED();
782 #endif 792 #endif
793 } else if (process_type == switches::kServiceProcess) {
794 rv = ServiceProcessMain(main_params);
783 } else if (process_type.empty()) { 795 } else if (process_type.empty()) {
784 #if defined(OS_LINUX) 796 #if defined(OS_LINUX)
785 const char* sandbox_binary = NULL; 797 const char* sandbox_binary = NULL;
786 struct stat st; 798 struct stat st;
787 799
788 // In Chromium branded builds, developers can set an environment variable to 800 // In Chromium branded builds, developers can set an environment variable to
789 // use the development sandbox. See 801 // use the development sandbox. See
790 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment 802 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
791 if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) 803 if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid())
792 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); 804 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 853
842 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) 854 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD)
843 // TODO(mark): See the TODO(mark) above at InitCrashReporter. 855 // TODO(mark): See the TODO(mark) above at InitCrashReporter.
844 DestructCrashReporter(); 856 DestructCrashReporter();
845 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD 857 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD
846 858
847 TRACE_EVENT_END("chrome.main", NULL, ""); 859 TRACE_EVENT_END("chrome.main", NULL, "");
848 860
849 return rv; 861 return rv;
850 } 862 }
OLDNEW
« no previous file with comments | « no previous file | chrome/app/dummy_main_functions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698