This source file includes following definitions.
- LoadMemoryProfiler
 
- HasDeprecatedArguments
 
- SuppressWindowsErrorDialogs
 
- AdjustLinuxOOMScore
 
- EnableHeapProfiler
 
- SubprocessNeedsResourceBundle
 
- HandleVersionSwitches
 
- HandleHelpSwitches
 
- SIGTERMProfilingShutdown
 
- SetUpProfilingShutdownHandler
 
- InitializeUserDataDir
 
- BasicStartupComplete
 
- InitMacCrashReporter
 
- PreSandboxStartup
 
- SandboxInitialized
 
- RunProcess
 
- ProcessExiting
 
- ProcessRegistersWithSystemProcess
 
- ShouldSendMachPort
 
- DelaySandboxInitialization
 
- ZygoteStarting
 
- ZygoteForked
 
- CreateContentBrowserClient
 
- CreateContentPluginClient
 
- CreateContentRendererClient
 
- CreateContentUtilityClient
 
#include "chrome/app/chrome_main_delegate.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/i18n/rtl.h"
#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/statistics_recorder.h"
#include "base/metrics/stats_counters.h"
#include "base/path_service.h"
#include "base/process/memory.h"
#include "base/process/process_handle.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/defaults.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/profiling.h"
#include "chrome/common/switch_utils.h"
#include "chrome/common/url_constants.h"
#include "chrome/plugin/chrome_content_plugin_client.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/utility/chrome_content_utility_client.h"
#include "components/nacl/common/nacl_switches.h"
#include "components/startup_metric_utils/startup_metric_utils.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_paths.h"
#include "ui/base/ui_base_switches.h"
#if defined(OS_WIN)
#include <atlbase.h>
#include <malloc.h>
#include <algorithm>
#include "base/strings/string_util.h"
#include "chrome/common/child_process_logging.h"
#include "sandbox/win/src/sandbox.h"
#include "tools/memory_watcher/memory_watcher.h"
#include "ui/base/resource/resource_bundle_win.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#include "base/mac/os_crash_dumps.h"
#include "chrome/app/chrome_main_mac.h"
#include "chrome/browser/mac/relauncher.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/mac/cfbundle_blocker.h"
#include "chrome/common/mac/objc_zombie.h"
#include "components/breakpad/app/breakpad_mac.h"
#include "grit/chromium_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#endif
#if defined(OS_POSIX)
#include <locale.h>
#include <signal.h>
#include "chrome/app/chrome_breakpad_client.h"
#include "components/breakpad/app/breakpad_client.h"
#endif
#if !defined(DISABLE_NACL) && defined(OS_LINUX)
#include "components/nacl/common/nacl_paths.h"
#include "components/nacl/zygote/nacl_fork_delegate_linux.h"
#endif
#if defined(OS_CHROMEOS)
#include "base/sys_info.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/chromeos_switches.h"
#endif
#if defined(OS_ANDROID)
#include "chrome/common/descriptors_android.h"
#else
#include "chrome/browser/diagnostics/diagnostics_controller.h"
#include "chrome/browser/diagnostics/diagnostics_writer.h"
#endif
#if defined(USE_X11)
#include <stdlib.h>
#include <string.h>
#include "ui/base/x/x11_util.h"
#endif
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include "components/breakpad/app/breakpad_linux.h"
#endif
#if defined(OS_LINUX)
#include "base/environment.h"
#endif
#if defined(OS_MACOSX) || defined(OS_WIN)
#include "chrome/browser/policy/policy_path_parser.h"
#endif
#if !defined(CHROME_MULTIPLE_DLL_CHILD)
base::LazyInstance<chrome::ChromeContentBrowserClient>
    g_chrome_content_browser_client = LAZY_INSTANCE_INITIALIZER;
#endif
#if !defined(CHROME_MULTIPLE_DLL_BROWSER)
base::LazyInstance<ChromeContentRendererClient>
    g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<chrome::ChromeContentUtilityClient>
    g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<chrome::ChromeContentPluginClient>
    g_chrome_content_plugin_client = LAZY_INSTANCE_INITIALIZER;
#endif
#if defined(OS_POSIX)
base::LazyInstance<chrome::ChromeBreakpadClient>::Leaky
    g_chrome_breakpad_client = LAZY_INSTANCE_INITIALIZER;
#endif
extern int NaClMain(const content::MainFunctionParams&);
extern int ServiceProcessMain(const content::MainFunctionParams&);
namespace {
#if defined(OS_WIN)
const wchar_t kProfilingDll[] = L"memory_watcher.dll";
bool LoadMemoryProfiler() {
  HMODULE prof_module = LoadLibrary(kProfilingDll);
  return prof_module != NULL;
}
bool HasDeprecatedArguments(const std::wstring& command_line) {
  const wchar_t kChromeHtml[] = L"chromehtml:";
  std::wstring command_line_lower = command_line;
  
  StringToLowerASCII(&command_line_lower);
  std::wstring::size_type pos = command_line_lower.find(kChromeHtml);
  return (pos != std::wstring::npos);
}
void SuppressWindowsErrorDialogs() {
  UINT new_flags = SEM_FAILCRITICALERRORS |
                   SEM_NOOPENFILEERRORBOX;
  
  UINT existing_flags = SetErrorMode(new_flags);
  SetErrorMode(existing_flags | new_flags);
}
#endif  
#if defined(OS_LINUX)
static void AdjustLinuxOOMScore(const std::string& process_type) {
  
  const int kZygoteScore = 0;
  
  
  
  const int kScoreBump = 100;
  
  
  const int kRendererScore = chrome::kLowestRendererOomScore;
  
  
  const int kMiscScore = kRendererScore - kScoreBump;
  
  const int kPluginScore = kMiscScore - kScoreBump;
  int score = -1;
  DCHECK(kMiscScore > 0);
  DCHECK(kPluginScore > 0);
  if (process_type == switches::kPluginProcess ||
      process_type == switches::kPpapiPluginProcess) {
    score = kPluginScore;
  } else if (process_type == switches::kPpapiBrokerProcess) {
    
    score = kPluginScore + kScoreBump;
  } else if (process_type == switches::kUtilityProcess ||
             process_type == switches::kWorkerProcess ||
             process_type == switches::kGpuProcess ||
             process_type == switches::kServiceProcess) {
    score = kMiscScore;
#ifndef DISABLE_NACL
  } else if (process_type == switches::kNaClLoaderProcess ||
             process_type == switches::kNaClLoaderNonSfiProcess) {
    score = kPluginScore;
#endif
  } else if (process_type == switches::kZygoteProcess ||
             process_type.empty()) {
    
    
    score = kZygoteScore;
  } else if (process_type == switches::kRendererProcess) {
    LOG(WARNING) << "process type 'renderer' "
                 << "should be created through the zygote.";
    
    
    
    score = kRendererScore;
  } else {
    NOTREACHED() << "Unknown process type";
  }
  if (score > -1)
    base::AdjustOOMScore(base::GetCurrentProcId(), score);
}
#endif  
void EnableHeapProfiler(const CommandLine& command_line) {
#if defined(OS_WIN)
  if (command_line.HasSwitch(switches::kMemoryProfiling))
    if (!LoadMemoryProfiler())
      exit(-1);
#endif
}
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
  return
#if defined(OS_WIN) || defined(OS_MACOSX)
      
      
      process_type == switches::kPluginProcess ||
      
      process_type == switches::kWorkerProcess ||
#endif
#if defined(OS_POSIX) && !defined(OS_MACOSX)
      
      process_type == switches::kZygoteProcess ||
#endif
#if defined(OS_MACOSX)
      
      
      process_type == switches::kNaClLoaderProcess ||
      process_type == switches::kPpapiPluginProcess ||
      process_type == switches::kPpapiBrokerProcess ||
      process_type == switches::kGpuProcess ||
#endif
      process_type == switches::kRendererProcess ||
      process_type == switches::kUtilityProcess;
}
#if defined(OS_POSIX)
bool HandleVersionSwitches(const CommandLine& command_line) {
  const chrome::VersionInfo version_info;
#if !defined(OS_MACOSX)
  if (command_line.HasSwitch(switches::kProductVersion)) {
    printf("%s\n", version_info.Version().c_str());
    return true;
  }
#endif
  if (command_line.HasSwitch(switches::kVersion)) {
    printf("%s %s %s\n",
           version_info.Name().c_str(),
           version_info.Version().c_str(),
           chrome::VersionInfo::GetVersionStringModifier().c_str());
    return true;
  }
  return false;
}
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
void HandleHelpSwitches(const CommandLine& command_line) {
  if (command_line.HasSwitch(switches::kHelp) ||
      command_line.HasSwitch(switches::kHelpShort)) {
    base::FilePath binary(command_line.argv()[0]);
    execlp("man", "man", binary.BaseName().value().c_str(), NULL);
    PLOG(FATAL) << "execlp failed";
  }
}
#endif
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
void SIGTERMProfilingShutdown(int signal) {
  Profiling::Stop();
  struct sigaction sigact;
  memset(&sigact, 0, sizeof(sigact));
  sigact.sa_handler = SIG_DFL;
  CHECK(sigaction(SIGTERM, &sigact, NULL) == 0);
  raise(signal);
}
void SetUpProfilingShutdownHandler() {
  struct sigaction sigact;
  sigact.sa_handler = SIGTERMProfilingShutdown;
  sigact.sa_flags = SA_RESETHAND;
  sigemptyset(&sigact.sa_mask);
  CHECK(sigaction(SIGTERM, &sigact, NULL) == 0);
}
#endif  
#endif  
struct MainFunction {
  const char* name;
  int (*function)(const content::MainFunctionParams&);
};
void InitializeUserDataDir() {
  CommandLine* command_line = CommandLine::ForCurrentProcess();
  base::FilePath user_data_dir =
      command_line->GetSwitchValuePath(switches::kUserDataDir);
  std::string process_type =
      command_line->GetSwitchValueASCII(switches::kProcessType);
#if defined(OS_LINUX)
  
  
  
  if (user_data_dir.empty()) {
    std::string user_data_dir_string;
    scoped_ptr<base::Environment> environment(base::Environment::Create());
    if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) &&
        IsStringUTF8(user_data_dir_string)) {
      user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string);
    }
  }
#endif
#if defined(OS_MACOSX) || defined(OS_WIN)
  policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
#endif
  const bool specified_directory_was_invalid = !user_data_dir.empty() &&
      !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
          user_data_dir, true);
  
  if (specified_directory_was_invalid)
    chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
  
  if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
    
    
    
    if (!specified_directory_was_invalid) {
      
      
      
      if (user_data_dir.empty())
        chrome::GetDefaultUserDataDirectory(&user_data_dir);
      chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
    }
    
    
    CHECK(process_type.empty()) << "Unable to get the user data directory "
                                << "for process type: " << process_type;
  }
  
  
  if (specified_directory_was_invalid)
    command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
}
}  
ChromeMainDelegate::ChromeMainDelegate() {
#if defined(OS_ANDROID)
#else
  startup_metric_utils::RecordMainEntryPointTime();
#endif
}
ChromeMainDelegate::~ChromeMainDelegate() {
}
bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) {
#if defined(OS_CHROMEOS)
  chromeos::BootTimesLoader::Get()->SaveChromeMainStats();
#endif
  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
#if defined(OS_MACOSX)
  
  
  const bool is_browser = !command_line.HasSwitch(switches::kProcessType);
  ObjcEvilDoers::ZombieEnable(true, is_browser ? 10000 : 1000);
  SetUpBundleOverrides();
  chrome::common::mac::EnableCFBundleBlocker();
#endif
  Profiling::ProcessStarted();
#if defined(OS_POSIX)
  if (HandleVersionSwitches(command_line)) {
    *exit_code = 0;
    return true;  
  }
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
  
  HandleHelpSwitches(command_line);
#endif
#endif  
#if defined(OS_WIN)
  
  if (HasDeprecatedArguments(command_line.GetCommandLineString())) {
    *exit_code = 1;
    return true;
  }
#endif
  chrome::RegisterPathProvider();
#if defined(OS_CHROMEOS)
  chromeos::RegisterPathProvider();
#endif
#if !defined(DISABLE_NACL) && defined(OS_LINUX)
  nacl::RegisterPathProvider();
#endif
#if !defined(OS_ANDROID) && !defined(CHROME_MULTIPLE_DLL_CHILD)
  
  
  if (command_line.HasSwitch(switches::kDiagnostics)) {
    diagnostics::DiagnosticsWriter::FormatType format =
        diagnostics::DiagnosticsWriter::HUMAN;
    if (command_line.HasSwitch(switches::kDiagnosticsFormat)) {
      std::string format_str =
          command_line.GetSwitchValueASCII(switches::kDiagnosticsFormat);
      if (format_str == "machine") {
        format = diagnostics::DiagnosticsWriter::MACHINE;
      } else if (format_str == "log") {
        format = diagnostics::DiagnosticsWriter::LOG;
      } else {
        DCHECK_EQ("human", format_str);
      }
    }
    diagnostics::DiagnosticsWriter writer(format);
    *exit_code = diagnostics::DiagnosticsController::GetInstance()->Run(
        command_line, &writer);
    diagnostics::DiagnosticsController::GetInstance()->ClearResults();
    return true;
  }
#endif
#if defined(OS_CHROMEOS)
  
  
  
  
  if (command_line.HasSwitch(chromeos::switches::kLoginUser) ||
      command_line.HasSwitch(switches::kDiagnosticsRecovery)) {
    
    
    base::StatisticsRecorder::Initialize();
    CommandLine interim_command_line(command_line.GetProgram());
    const char* kSwitchNames[] = {switches::kUserDataDir, };
    interim_command_line.CopySwitchesFrom(
        command_line, kSwitchNames, arraysize(kSwitchNames));
    interim_command_line.AppendSwitch(switches::kDiagnostics);
    interim_command_line.AppendSwitch(switches::kDiagnosticsRecovery);
    diagnostics::DiagnosticsWriter::FormatType format =
        diagnostics::DiagnosticsWriter::LOG;
    if (command_line.HasSwitch(switches::kDiagnosticsFormat)) {
      std::string format_str =
          command_line.GetSwitchValueASCII(switches::kDiagnosticsFormat);
      if (format_str == "machine") {
        format = diagnostics::DiagnosticsWriter::MACHINE;
      } else if (format_str == "human") {
        format = diagnostics::DiagnosticsWriter::HUMAN;
      } else {
        DCHECK_EQ("log", format_str);
      }
    }
    diagnostics::DiagnosticsWriter writer(format);
    int diagnostics_exit_code =
        diagnostics::DiagnosticsController::GetInstance()->Run(command_line,
                                                               &writer);
    if (diagnostics_exit_code) {
      
      *exit_code = diagnostics_exit_code;
      return true;
    }
    
    int recovery_exit_code =
        diagnostics::DiagnosticsController::GetInstance()->RunRecovery(
            command_line, &writer);
    if (recovery_exit_code) {
      
      *exit_code = recovery_exit_code;
      return true;
    }
  } else {  
    diagnostics::DiagnosticsController::GetInstance()->RecordRegularStartup();
  }
#endif
  content::SetContentClient(&chrome_content_client_);
  return false;
}
#if defined(OS_MACOSX)
void ChromeMainDelegate::InitMacCrashReporter(
    const base::CommandLine& command_line,
    const std::string& process_type) {
  
  
  
  
  breakpad::InitCrashReporter(process_type);
#if defined(NDEBUG)
  bool is_debug_build = false;
#else
  bool is_debug_build = true;
#endif
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  if (!command_line.HasSwitch(switches::kDisableBreakpad)) {
    bool disable_apple_crash_reporter = is_debug_build ||
        base::mac::IsBackgroundOnlyProcess();
    if (!breakpad::IsCrashReporterEnabled() && disable_apple_crash_reporter) {
      base::mac::DisableOSCrashDumps();
    }
  }
  
  
  
  
  
  
  
  
  
  if (base::mac::IsBackgroundOnlyProcess()) {
    CHECK(command_line.HasSwitch(switches::kProcessType) &&
          !process_type.empty())
        << "Helper application requires --type.";
    
    base::FilePath executable;
    if (PathService::Get(base::FILE_EXE, &executable) &&
        executable.value().size() >= 3) {
      std::string last_three =
          executable.value().substr(executable.value().size() - 3);
      if (last_three == " EH") {
        CHECK(process_type == switches::kPluginProcess ||
              process_type == switches::kUtilityProcess)
            << "Executable-heap process requires --type="
            << switches::kPluginProcess << " or "
            << switches::kUtilityProcess << ", saw " << process_type;
      } else if (last_three == " NP") {
        CHECK_EQ(switches::kNaClLoaderProcess, process_type)
            << "Non-PIE process requires --type="
            << switches::kNaClLoaderProcess << ", saw " << process_type;
      } else {
        CHECK(process_type != switches::kPluginProcess &&
              process_type != switches::kNaClLoaderProcess)
            << "Non-executable-heap PIE process is intolerant of --type="
            << switches::kPluginProcess << " and "
            << switches::kNaClLoaderProcess << ", saw " << process_type;
      }
    }
  } else {
    CHECK(!command_line.HasSwitch(switches::kProcessType) &&
          process_type.empty())
        << "Main application forbids --type, saw " << process_type;
  }
  if (breakpad::IsCrashReporterEnabled())
    breakpad::InitCrashProcessInfo(process_type);
}
#endif  
void ChromeMainDelegate::PreSandboxStartup() {
  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
  std::string process_type =
      command_line.GetSwitchValueASCII(switches::kProcessType);
#if defined(OS_POSIX)
  breakpad::SetBreakpadClient(g_chrome_breakpad_client.Pointer());
#endif
#if defined(OS_MACOSX)
  
  
  PathService::Override(content::CHILD_PROCESS_EXE,
                        chrome::GetVersionedDirectory().
                        Append(chrome::kHelperProcessExecutablePath));
  InitMacCrashReporter(command_line, process_type);
#endif
#if defined(OS_WIN)
  child_process_logging::Init();
#endif
  
  if (chrome::ProcessNeedsProfileDir(process_type))
    InitializeUserDataDir();
  stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init"));
  startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
                       (*stats_counter_timer_));
  
  EnableHeapProfiler(command_line);
  
  if (command_line.HasSwitch(switches::kMessageLoopHistogrammer))
    base::MessageLoop::EnableHistogrammer(true);
#if !defined(OS_ANDROID)
  
  logging::OldFileDeletionState file_state =
      logging::APPEND_TO_OLD_LOG_FILE;
  if (process_type.empty()) {
    file_state = logging::DELETE_OLD_LOG_FILE;
  }
  logging::InitChromeLogging(command_line, file_state);
#endif
#if defined(OS_WIN)
  
  ui::SetResourcesDataDLL(_AtlBaseModule.GetResourceInstance());
#endif
  if (SubprocessNeedsResourceBundle(process_type)) {
    
    
    
#if defined(DISABLE_NACL)
    DCHECK(command_line.HasSwitch(switches::kLang) ||
           process_type == switches::kZygoteProcess ||
           process_type == switches::kGpuProcess ||
           process_type == switches::kPpapiBrokerProcess ||
           process_type == switches::kPpapiPluginProcess);
#else
    DCHECK(command_line.HasSwitch(switches::kLang) ||
           process_type == switches::kZygoteProcess ||
           process_type == switches::kGpuProcess ||
           process_type == switches::kNaClLoaderProcess ||
           process_type == switches::kPpapiBrokerProcess ||
           process_type == switches::kPpapiPluginProcess);
#endif
    
    
    
    
    
    const std::string locale =
        command_line.GetSwitchValueASCII(switches::kLang);
#if defined(OS_ANDROID)
    
    
    
    int locale_pak_fd = base::GlobalDescriptors::GetInstance()->MaybeGet(
        kAndroidLocalePakDescriptor);
    CHECK(locale_pak_fd != -1);
    ResourceBundle::InitSharedInstanceWithPakFile(base::File(locale_pak_fd),
                                                  false);
    int extra_pak_keys[] = {
      kAndroidChrome100PercentPakDescriptor,
      kAndroidUIResourcesPakDescriptor,
    };
    for (size_t i = 0; i < arraysize(extra_pak_keys); ++i) {
      int pak_fd =
          base::GlobalDescriptors::GetInstance()->MaybeGet(extra_pak_keys[i]);
      CHECK(pak_fd != -1);
      ResourceBundle::GetSharedInstance().AddDataPackFromFile(
          base::File(pak_fd), ui::SCALE_FACTOR_100P);
    }
    base::i18n::SetICUDefaultLocale(locale);
    const std::string loaded_locale = locale;
#else
    const std::string loaded_locale =
        ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
    base::FilePath resources_pack_path;
    PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
    ResourceBundle::GetSharedInstance().AddDataPackFromPath(
        resources_pack_path, ui::SCALE_FACTOR_NONE);
#endif
    CHECK(!loaded_locale.empty()) << "Locale could not be found for " <<
        locale;
#if !defined(CHROME_MULTIPLE_DLL_BROWSER)
    if (process_type == switches::kUtilityProcess ||
        process_type == switches::kZygoteProcess) {
      chrome::ChromeContentUtilityClient::PreSandboxStartup();
    }
#endif
  }
#if defined(OS_POSIX) && !defined(OS_MACOSX)
  
  if (process_type != switches::kZygoteProcess) {
#if defined(OS_ANDROID)
    if (process_type.empty())
      breakpad::InitCrashReporter(process_type);
    else
      breakpad::InitNonBrowserCrashReporterForAndroid(process_type);
#else  
    breakpad::InitCrashReporter(process_type);
#endif  
  }
#endif  
  
  
  crash_keys::SetSwitchesFromCommandLine(&command_line);
}
void ChromeMainDelegate::SandboxInitialized(const std::string& process_type) {
  startup_timer_->Stop();  
  
  
#if defined(OS_LINUX)
  AdjustLinuxOOMScore(process_type);
#endif
#if defined(OS_WIN)
  SuppressWindowsErrorDialogs();
#endif
}
int ChromeMainDelegate::RunProcess(
    const std::string& process_type,
    const content::MainFunctionParams& main_function_params) {
  
  
#if !defined(OS_ANDROID)
  static const MainFunction kMainFunctions[] = {
#if defined(ENABLE_FULL_PRINTING) && !defined(CHROME_MULTIPLE_DLL_CHILD)
    { switches::kServiceProcess,     ServiceProcessMain },
#endif
#if defined(OS_MACOSX)
    { switches::kRelauncherProcess,
      mac_relauncher::internal::RelauncherMain },
#endif
    
    
#if !defined(DISABLE_NACL) && !defined(CHROME_MULTIPLE_DLL_BROWSER) && \
    !defined(OS_LINUX)
    { switches::kNaClLoaderProcess,  NaClMain },
#else
    { "<invalid>", NULL },  
                            
#endif  
  };
  for (size_t i = 0; i < arraysize(kMainFunctions); ++i) {
    if (process_type == kMainFunctions[i].name)
      return kMainFunctions[i].function(main_function_params);
  }
#endif
  return -1;
}
void ChromeMainDelegate::ProcessExiting(const std::string& process_type) {
  if (SubprocessNeedsResourceBundle(process_type))
    ResourceBundle::CleanupSharedInstance();
#if !defined(OS_ANDROID)
  logging::CleanupChromeLogging();
#else
  
  logging::CloseLogFile();
#endif  
}
#if defined(OS_MACOSX)
bool ChromeMainDelegate::ProcessRegistersWithSystemProcess(
    const std::string& process_type) {
  return process_type == switches::kNaClLoaderProcess;
}
bool ChromeMainDelegate::ShouldSendMachPort(const std::string& process_type) {
  return process_type != switches::kRelauncherProcess &&
      process_type != switches::kServiceProcess;
}
bool ChromeMainDelegate::DelaySandboxInitialization(
    const std::string& process_type) {
  
  
  return process_type == switches::kNaClLoaderProcess ||
      process_type == switches::kRelauncherProcess;
}
#elif defined(OS_POSIX) && !defined(OS_ANDROID)
content::ZygoteForkDelegate* ChromeMainDelegate::ZygoteStarting() {
#if defined(DISABLE_NACL)
  return NULL;
#else
  return new NaClForkDelegate();
#endif
}
void ChromeMainDelegate::ZygoteForked() {
  Profiling::ProcessStarted();
  if (Profiling::BeingProfiled()) {
    base::debug::RestartProfilingAfterFork();
    SetUpProfilingShutdownHandler();
  }
  
  
  const CommandLine* command_line = CommandLine::ForCurrentProcess();
  std::string process_type =
      command_line->GetSwitchValueASCII(switches::kProcessType);
  breakpad::InitCrashReporter(process_type);
  
  crash_keys::SetSwitchesFromCommandLine(command_line);
}
#endif  
content::ContentBrowserClient*
ChromeMainDelegate::CreateContentBrowserClient() {
#if defined(CHROME_MULTIPLE_DLL_CHILD)
  return NULL;
#else
  return g_chrome_content_browser_client.Pointer();
#endif
}
content::ContentPluginClient* ChromeMainDelegate::CreateContentPluginClient() {
#if defined(CHROME_MULTIPLE_DLL_BROWSER)
  return NULL;
#else
  return g_chrome_content_plugin_client.Pointer();
#endif
}
content::ContentRendererClient*
ChromeMainDelegate::CreateContentRendererClient() {
#if defined(CHROME_MULTIPLE_DLL_BROWSER)
  return NULL;
#else
  return g_chrome_content_renderer_client.Pointer();
#endif
}
content::ContentUtilityClient*
ChromeMainDelegate::CreateContentUtilityClient() {
#if defined(CHROME_MULTIPLE_DLL_BROWSER)
  return NULL;
#else
  return g_chrome_content_utility_client.Pointer();
#endif
}