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

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

Issue 8113035: Remove RenderProcessHost::is_extension_process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 2 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 | « chrome/app/breakpad_linux.cc ('k') | chrome/browser/chrome_content_browser_client.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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/lazy_instance.h" 6 #include "base/lazy_instance.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/stats_counters.h" 9 #include "base/metrics/stats_counters.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/common/chrome_version_info.h" 23 #include "chrome/common/chrome_version_info.h"
24 #include "chrome/common/logging_chrome.h" 24 #include "chrome/common/logging_chrome.h"
25 #include "chrome/common/profiling.h" 25 #include "chrome/common/profiling.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/plugin/chrome_content_plugin_client.h" 27 #include "chrome/plugin/chrome_content_plugin_client.h"
28 #include "chrome/renderer/chrome_content_renderer_client.h" 28 #include "chrome/renderer/chrome_content_renderer_client.h"
29 #include "chrome/utility/chrome_content_utility_client.h" 29 #include "chrome/utility/chrome_content_utility_client.h"
30 #include "content/app/content_main.h" 30 #include "content/app/content_main.h"
31 #include "content/app/content_main_delegate.h" 31 #include "content/app/content_main_delegate.h"
32 #include "content/browser/renderer_host/render_process_host.h" 32 #include "content/browser/renderer_host/render_process_host.h"
33 #include "content/renderer/renderer_main.h"
34 #include "content/common/content_client.h" 33 #include "content/common/content_client.h"
35 #include "content/common/content_counters.h" 34 #include "content/common/content_counters.h"
36 #include "content/common/content_paths.h" 35 #include "content/common/content_paths.h"
37 #include "content/common/content_switches.h" 36 #include "content/common/content_switches.h"
38 #include "media/base/media.h" 37 #include "media/base/media.h"
39 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/base/ui_base_switches.h" 39 #include "ui/base/ui_base_switches.h"
41 40
42 #if defined(OS_WIN) 41 #if defined(OS_WIN)
43 #include <algorithm> 42 #include <algorithm>
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 score = kMiscScore; 226 score = kMiscScore;
228 #ifndef DISABLE_NACL 227 #ifndef DISABLE_NACL
229 } else if (process_type == switches::kNaClLoaderProcess) { 228 } else if (process_type == switches::kNaClLoaderProcess) {
230 score = kPluginScore; 229 score = kPluginScore;
231 #endif 230 #endif
232 } else if (process_type == switches::kZygoteProcess || 231 } else if (process_type == switches::kZygoteProcess ||
233 process_type.empty()) { 232 process_type.empty()) {
234 // For zygotes and unlabeled process types, we want to still make 233 // For zygotes and unlabeled process types, we want to still make
235 // them killable by the OOM killer. 234 // them killable by the OOM killer.
236 score = kZygoteScore; 235 score = kZygoteScore;
237 } else if (process_type == switches::kExtensionProcess || 236 } else if (process_type == switches::kRendererProcess) {
238 process_type == switches::kRendererProcess) { 237 LOG(WARNING) << "process type 'renderer' "
239 LOG(WARNING) << "process type '" << process_type << "' "
240 << "should be created through the zygote."; 238 << "should be created through the zygote.";
241 // When debugging, these process types can end up being run 239 // When debugging, this process type can end up being run directly, but
242 // directly, but this isn't the typical path for assigning the OOM 240 // this isn't the typical path for assigning the OOM score for it. Still,
243 // score for them. Still, we want to assign a score that is 241 // we want to assign a score that is somewhat representative for debugging.
244 // somewhat representative for debugging.
245 score = kRendererScore; 242 score = kRendererScore;
246 } else { 243 } else {
247 NOTREACHED() << "Unknown process type"; 244 NOTREACHED() << "Unknown process type";
248 } 245 }
249 if (score > -1) 246 if (score > -1)
250 base::AdjustOOMScore(base::GetCurrentProcId(), score); 247 base::AdjustOOMScore(base::GetCurrentProcId(), score);
251 } 248 }
252 #endif // defined(OS_LINUX) 249 #endif // defined(OS_LINUX)
253 250
254 // Enable the heap profiler if the appropriate command-line switch is 251 // Enable the heap profiler if the appropriate command-line switch is
(...skipping 11 matching lines...) Expand all
266 &g_chrome_content_renderer_client.Get()); 263 &g_chrome_content_renderer_client.Get());
267 } 264 }
268 265
269 void InitializeChromeContentClient(const std::string& process_type) { 266 void InitializeChromeContentClient(const std::string& process_type) {
270 if (process_type.empty()) { 267 if (process_type.empty()) {
271 content::GetContentClient()->set_browser( 268 content::GetContentClient()->set_browser(
272 &g_chrome_content_browser_client.Get()); 269 &g_chrome_content_browser_client.Get());
273 } else if (process_type == switches::kPluginProcess) { 270 } else if (process_type == switches::kPluginProcess) {
274 content::GetContentClient()->set_plugin( 271 content::GetContentClient()->set_plugin(
275 &g_chrome_content_plugin_client.Get()); 272 &g_chrome_content_plugin_client.Get());
276 } else if (process_type == switches::kRendererProcess || 273 } else if (process_type == switches::kRendererProcess) {
277 process_type == switches::kExtensionProcess) {
278 InitializeChromeContentRendererClient(); 274 InitializeChromeContentRendererClient();
279 } else if (process_type == switches::kUtilityProcess) { 275 } else if (process_type == switches::kUtilityProcess) {
280 content::GetContentClient()->set_utility( 276 content::GetContentClient()->set_utility(
281 &g_chrome_content_utility_client.Get()); 277 &g_chrome_content_utility_client.Get());
282 } 278 }
283 } 279 }
284 280
285 // Returns true if this subprocess type needs the ResourceBundle initialized 281 // Returns true if this subprocess type needs the ResourceBundle initialized
286 // and resources loaded. 282 // and resources loaded.
287 bool SubprocessNeedsResourceBundle(const std::string& process_type) { 283 bool SubprocessNeedsResourceBundle(const std::string& process_type) {
288 return 284 return
289 #if defined(OS_WIN) || defined(OS_MACOSX) 285 #if defined(OS_WIN) || defined(OS_MACOSX)
290 // Windows needs resources for the default/null plugin. 286 // Windows needs resources for the default/null plugin.
291 // Mac needs them for the plugin process name. 287 // Mac needs them for the plugin process name.
292 process_type == switches::kPluginProcess || 288 process_type == switches::kPluginProcess ||
293 #endif 289 #endif
294 #if defined(OS_POSIX) && !defined(OS_MACOSX) 290 #if defined(OS_POSIX) && !defined(OS_MACOSX)
295 // The zygote process opens the resources for the renderers. 291 // The zygote process opens the resources for the renderers.
296 process_type == switches::kZygoteProcess || 292 process_type == switches::kZygoteProcess ||
297 #endif 293 #endif
298 #if defined(OS_MACOSX) 294 #if defined(OS_MACOSX)
299 // Mac needs them to for scrollbar related images. 295 // Mac needs them to for scrollbar related images.
300 process_type == switches::kWorkerProcess || 296 process_type == switches::kWorkerProcess ||
301 #endif 297 #endif
302 process_type == switches::kRendererProcess || 298 process_type == switches::kRendererProcess ||
303 process_type == switches::kExtensionProcess ||
304 process_type == switches::kUtilityProcess; 299 process_type == switches::kUtilityProcess;
305 } 300 }
306 301
307 #if defined(OS_MACOSX) 302 #if defined(OS_MACOSX)
308 // Update the name shown in Activity Monitor so users are less likely to ask 303 // Update the name shown in Activity Monitor so users are less likely to ask
309 // why Chrome has so many processes. 304 // why Chrome has so many processes.
310 void SetMacProcessName(const std::string& process_type) { 305 void SetMacProcessName(const CommandLine& command_line) {
306 std::string process_type =
307 command_line.GetSwitchValueASCII(switches::kProcessType);
311 // Don't worry about the browser process, its gets the stock name. 308 // Don't worry about the browser process, its gets the stock name.
312 int name_id = 0; 309 int name_id = 0;
313 if (process_type == switches::kRendererProcess) { 310 if (command_line.HasSwitch(switches::kExtensionProcess)) {
311 name_id = IDS_WORKER_APP_NAME;
312 } else if (process_type == switches::kRendererProcess) {
314 name_id = IDS_RENDERER_APP_NAME; 313 name_id = IDS_RENDERER_APP_NAME;
315 } else if (process_type == switches::kPluginProcess || 314 } else if (process_type == switches::kPluginProcess ||
316 process_type == switches::kPpapiPluginProcess) { 315 process_type == switches::kPpapiPluginProcess) {
317 name_id = IDS_PLUGIN_APP_NAME; 316 name_id = IDS_PLUGIN_APP_NAME;
318 } else if (process_type == switches::kExtensionProcess) {
319 name_id = IDS_WORKER_APP_NAME;
320 } else if (process_type == switches::kUtilityProcess) { 317 } else if (process_type == switches::kUtilityProcess) {
321 name_id = IDS_UTILITY_APP_NAME; 318 name_id = IDS_UTILITY_APP_NAME;
322 } 319 }
323 if (name_id) { 320 if (name_id) {
324 NSString* app_name = l10n_util::GetNSString(name_id); 321 NSString* app_name = l10n_util::GetNSString(name_id);
325 base::mac::SetProcessName(base::mac::NSToCFCast(app_name)); 322 base::mac::SetProcessName(base::mac::NSToCFCast(app_name));
326 } 323 }
327 } 324 }
328 325
329 #endif // defined(OS_MACOSX) 326 #endif // defined(OS_MACOSX)
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 const std::string locale = 601 const std::string locale =
605 command_line.GetSwitchValueASCII(switches::kLang); 602 command_line.GetSwitchValueASCII(switches::kLang);
606 const std::string loaded_locale = 603 const std::string loaded_locale =
607 ResourceBundle::InitSharedInstance(locale); 604 ResourceBundle::InitSharedInstance(locale);
608 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << 605 CHECK(!loaded_locale.empty()) << "Locale could not be found for " <<
609 locale; 606 locale;
610 607
611 #if defined(OS_MACOSX) 608 #if defined(OS_MACOSX)
612 // Update the process name (need resources to get the strings, so 609 // Update the process name (need resources to get the strings, so
613 // only do this when ResourcesBundle has been initialized). 610 // only do this when ResourcesBundle has been initialized).
614 SetMacProcessName(process_type); 611 SetMacProcessName(command_line);
615 #endif // defined(OS_MACOSX) 612 #endif // defined(OS_MACOSX)
616 } 613 }
617 614
618 #if defined(USE_LINUX_BREAKPAD) 615 #if defined(USE_LINUX_BREAKPAD)
619 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain 616 // Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain
620 // sets this up for the browser process in a different manner. Zygotes 617 // sets this up for the browser process in a different manner. Zygotes
621 // need to call InitCrashReporter() in RunZygote(). 618 // need to call InitCrashReporter() in RunZygote().
622 if (!process_type.empty() && process_type != switches::kZygoteProcess) 619 if (!process_type.empty() && process_type != switches::kZygoteProcess)
623 InitCrashReporter(); 620 InitCrashReporter();
624 #endif 621 #endif
(...skipping 14 matching lines...) Expand all
639 // AdjustLinuxOOMScore function too. 636 // AdjustLinuxOOMScore function too.
640 #if defined(OS_LINUX) 637 #if defined(OS_LINUX)
641 AdjustLinuxOOMScore(process_type); 638 AdjustLinuxOOMScore(process_type);
642 #endif 639 #endif
643 } 640 }
644 641
645 virtual int RunProcess( 642 virtual int RunProcess(
646 const std::string& process_type, 643 const std::string& process_type,
647 const MainFunctionParams& main_function_params) OVERRIDE { 644 const MainFunctionParams& main_function_params) OVERRIDE {
648 static const MainFunction kMainFunctions[] = { 645 static const MainFunction kMainFunctions[] = {
649 // An extension process is just a renderer process. We use a different
650 // command line argument to differentiate crash reports.
651 { switches::kExtensionProcess, RendererMain },
652 { switches::kServiceProcess, ServiceProcessMain }, 646 { switches::kServiceProcess, ServiceProcessMain },
653 #if defined(OS_MACOSX) 647 #if defined(OS_MACOSX)
654 { switches::kRelauncherProcess, 648 { switches::kRelauncherProcess,
655 mac_relauncher::internal::RelauncherMain }, 649 mac_relauncher::internal::RelauncherMain },
656 #endif 650 #endif
657 #if !defined(DISABLE_NACL) 651 #if !defined(DISABLE_NACL)
658 { switches::kNaClLoaderProcess, NaClMain }, 652 { switches::kNaClLoaderProcess, NaClMain },
659 #endif // DISABLE_NACL 653 #endif // DISABLE_NACL
660 }; 654 };
661 655
662 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { 656 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) {
663 if (process_type == kMainFunctions[i].name) 657 if (process_type == kMainFunctions[i].name)
664 return kMainFunctions[i].function(main_function_params); 658 return kMainFunctions[i].function(main_function_params);
665 } 659 }
666 660
667 NOTREACHED() << "Unknown process type: " << process_type; 661 NOTREACHED() << "Unknown process type: " << process_type;
668 return 1; 662 return 1;
669 } 663 }
670 664
671 virtual void ProcessExiting(const std::string& process_type) OVERRIDE { 665 virtual void ProcessExiting(const std::string& process_type) OVERRIDE {
672 if (SubprocessNeedsResourceBundle(process_type)) 666 if (SubprocessNeedsResourceBundle(process_type))
673 ResourceBundle::CleanupSharedInstance(); 667 ResourceBundle::CleanupSharedInstance();
674 668
675 logging::CleanupChromeLogging(); 669 logging::CleanupChromeLogging();
676 } 670 }
677 671
678 #if defined(OS_MACOSX) 672 #if defined(OS_MACOSX)
679 virtual bool ProcessRegistersWithSystemProcess( 673 virtual bool ProcessRegistersWithSystemProcess(
680 const std::string& process_type) OVERRIDE { 674 const std::string& process_type) OVERRIDE {
681 return process_type == switches::kNaClLoaderProcess || 675 return process_type == switches::kNaClLoaderProcess;
682 process_type == switches::kExtensionProcess;
683 } 676 }
684 677
685 virtual bool ShouldSendMachPort(const std::string& process_type) OVERRIDE { 678 virtual bool ShouldSendMachPort(const std::string& process_type) OVERRIDE {
686 return process_type != switches::kRelauncherProcess && 679 return process_type != switches::kRelauncherProcess &&
687 process_type != switches::kServiceProcess; 680 process_type != switches::kServiceProcess;
688 } 681 }
689 682
690 virtual bool DelaySandboxInitialization( 683 virtual bool DelaySandboxInitialization(
691 const std::string& process_type) OVERRIDE { 684 const std::string& process_type) OVERRIDE {
692 // Extensions are really renderers.
693 // NaClLoader does this in NaClMainPlatformDelegate::EnableSandbox(). 685 // NaClLoader does this in NaClMainPlatformDelegate::EnableSandbox().
694 // No sandbox needed for relauncher. 686 // No sandbox needed for relauncher.
695 return process_type == switches::kExtensionProcess || 687 return process_type == switches::kNaClLoaderProcess ||
696 process_type == switches::kNaClLoaderProcess ||
697 process_type == switches::kRelauncherProcess; 688 process_type == switches::kRelauncherProcess;
698 } 689 }
699 #elif defined(OS_POSIX) 690 #elif defined(OS_POSIX)
700 virtual ZygoteForkDelegate* ZygoteStarting() OVERRIDE { 691 virtual ZygoteForkDelegate* ZygoteStarting() OVERRIDE {
701 // Each Renderer we spawn will re-attempt initialization of the media 692 // Each Renderer we spawn will re-attempt initialization of the media
702 // libraries, at which point failure will be detected and handled, so 693 // libraries, at which point failure will be detected and handled, so
703 // we do not need to cope with initialization failures here. 694 // we do not need to cope with initialization failures here.
704 FilePath media_path; 695 FilePath media_path;
705 if (PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path)) 696 if (PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path))
706 media::InitializeMediaLibrary(media_path); 697 media::InitializeMediaLibrary(media_path);
(...skipping 30 matching lines...) Expand all
737 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, 728 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance,
738 sandbox::SandboxInterfaceInfo* sandbox_info) { 729 sandbox::SandboxInterfaceInfo* sandbox_info) {
739 ChromeMainDelegate chrome_main_delegate; 730 ChromeMainDelegate chrome_main_delegate;
740 return content::ContentMain(instance, sandbox_info, &chrome_main_delegate); 731 return content::ContentMain(instance, sandbox_info, &chrome_main_delegate);
741 #elif defined(OS_POSIX) 732 #elif defined(OS_POSIX)
742 int ChromeMain(int argc, const char** argv) { 733 int ChromeMain(int argc, const char** argv) {
743 ChromeMainDelegate chrome_main_delegate; 734 ChromeMainDelegate chrome_main_delegate;
744 return content::ContentMain(argc, argv, &chrome_main_delegate); 735 return content::ContentMain(argc, argv, &chrome_main_delegate);
745 #endif 736 #endif
746 } 737 }
OLDNEW
« no previous file with comments | « chrome/app/breakpad_linux.cc ('k') | chrome/browser/chrome_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698