void GetPathToBinary(FilePath& exePath)
{
#if defined(OS_WIN)
  exePath = FilePath::FromWStringHack(CommandLine::ForCurrentProcess()->program());
  exePath = exePath.DirName();
  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);
#elif defined(OS_POSIX)
  if (ShouldHaveDirectoryService()) {
    nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
    NS_ASSERTION(directoryService, "Expected XPCOM to be available");
    if (directoryService) {
      nsCOMPtr<nsIFile> greDir;
      nsresult rv = directoryService->Get(NS_GRE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(greDir));
      if (NS_SUCCEEDED(rv)) {
        nsCString path;
        greDir->GetNativePath(path);
        exePath = FilePath(path.get());
#ifdef MOZ_WIDGET_COCOA
        // We need to use an App Bundle on OS X so that we can hide
        // the dock icon. See Bug 557225.
        exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_BUNDLE);
#endif
      }
    }
  }

  if (exePath.empty()) {
    exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
    exePath = exePath.DirName();
  }

  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);
#endif
}
示例#2
0
//static
void
GeckoChildProcessHost::GetPathToBinary(FilePath& exePath)
{
  if (ShouldHaveDirectoryService()) {
    MOZ_ASSERT(gGREPath);
#ifdef OS_WIN
    exePath = FilePath(char16ptr_t(gGREPath));
#else
    nsCString path;
    NS_CopyUnicodeToNative(nsDependentString(gGREPath), path);
    exePath = FilePath(path.get());
#endif
#ifdef MOZ_WIDGET_COCOA
    // We need to use an App Bundle on OS X so that we can hide
    // the dock icon. See Bug 557225.
    exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_BUNDLE);
#endif
  }

  if (exePath.empty()) {
#ifdef OS_WIN
    exePath = FilePath::FromWStringHack(CommandLine::ForCurrentProcess()->program());
#else
    exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
#endif
    exePath = exePath.DirName();
  }

  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);
}
示例#3
0
文件: Root.cpp 项目: cnxsoft/xibo4arm
void handleINT(int sig) {
    FilePath homedirpath;
    PathService::Get(chrome::DIR_USER_DATA,&homedirpath);
    FilePath child = homedirpath.AppendASCII("SingletonLock");
    unlink(child.value().c_str());
    exit(-sig);
}
//static
void
GeckoChildProcessHost::GetPathToBinary(FilePath& exePath)
{
  if (ShouldHaveDirectoryService()) {
    MOZ_ASSERT(gGREBinPath);
#ifdef OS_WIN
    exePath = FilePath(char16ptr_t(gGREBinPath));
#elif MOZ_WIDGET_COCOA
    nsCOMPtr<nsIFile> childProcPath;
    NS_NewLocalFile(nsDependentString(gGREBinPath), false,
                    getter_AddRefs(childProcPath));
    // We need to use an App Bundle on OS X so that we can hide
    // the dock icon. See Bug 557225.
    childProcPath->AppendNative(NS_LITERAL_CSTRING("plugin-container.app"));
    childProcPath->AppendNative(NS_LITERAL_CSTRING("Contents"));
    childProcPath->AppendNative(NS_LITERAL_CSTRING("MacOS"));
    nsCString tempCPath;
    childProcPath->GetNativePath(tempCPath);
    exePath = FilePath(tempCPath.get());
#else
    nsCString path;
    NS_CopyUnicodeToNative(nsDependentString(gGREBinPath), path);
    exePath = FilePath(path.get());
#endif
  }

  if (exePath.empty()) {
#ifdef OS_WIN
    exePath = FilePath::FromWStringHack(CommandLine::ForCurrentProcess()->program());
#else
    exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
#endif
    exePath = exePath.DirName();
  }

#ifdef MOZ_WIDGET_ANDROID
  exePath = exePath.AppendASCII("lib");

  // We must use the PIE binary on 5.0 and higher
  const char* processName = mozilla::AndroidBridge::Bridge()->GetAPIVersion() >= 21 ?
    MOZ_CHILD_PROCESS_NAME_PIE : MOZ_CHILD_PROCESS_NAME;

  exePath = exePath.AppendASCII(processName);
#else
  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);
#endif
}
void ChromiumProfileImporter::ReadProfiles(vector<ChromeProfileInfo> *cp,
                                           FilePath profileDirectory) {
  FilePath profileFileName = profileDirectory.AppendASCII("Local State");
  if (!PathExists(profileFileName))
    return;

  string input;
  ReadFileToString(profileFileName, &input);

  JSONReader reader;
  scoped_ptr<Value> root(reader.ReadToValue(input));

  DictionaryValue* dict = NULL;
  if (!root->GetAsDictionary(&dict)) {
    return;
  }

  const Value* roots;
  if (!dict->Get("profile", &roots)) {
    return;
  }

  const DictionaryValue* roots_d_value =
    static_cast<const DictionaryValue*>(roots);

  const Value* vInfoCache;
  const DictionaryValue* vDictValue;
  if (roots_d_value->Get("info_cache", &vInfoCache)) {

    vInfoCache->GetAsDictionary(&vDictValue);
    for (DictionaryValue::Iterator it(*vDictValue); !it.IsAtEnd(); it.Advance()){
      const Value* child_copy = &it.value();
      string profileName = it.key();

      const DictionaryValue* roots_sd_value =
        static_cast<const DictionaryValue*>(&it.value());

      ChromeProfileInfo prof;
      const Value* namVal;
      if (roots_sd_value->Get("name", &namVal)) {
        string16 displayName;
        namVal->GetAsString(&displayName);
        prof.profileDisplayName = displayName;
      } else {
        prof.profileDisplayName = base::UTF8ToUTF16(profileName);
      }
      prof.profileName = profileName;
      cp->push_back(prof);
    }

  }
}
//static
void
GeckoChildProcessHost::GetPathToBinary(FilePath& exePath, GeckoProcessType processType)
{
  if (sRunSelfAsContentProc &&
      processType == GeckoProcessType_Content) {
#if defined(OS_WIN)
    wchar_t exePathBuf[MAXPATHLEN];
    if (!::GetModuleFileNameW(nullptr, exePathBuf, MAXPATHLEN)) {
      MOZ_CRASH("GetModuleFileNameW failed (FIXME)");
    }
    exePath = FilePath::FromWStringHack(exePathBuf);
#elif defined(OS_POSIX)
    exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
#else
#  error Sorry; target OS not supported yet.
#endif
    return;
  }

  if (ShouldHaveDirectoryService()) {
    MOZ_ASSERT(gGREBinPath);
#ifdef OS_WIN
    exePath = FilePath(char16ptr_t(gGREBinPath));
#elif MOZ_WIDGET_COCOA
    nsCOMPtr<nsIFile> childProcPath;
    NS_NewLocalFile(nsDependentString(gGREBinPath), false,
                    getter_AddRefs(childProcPath));

    // We need to use an App Bundle on OS X so that we can hide
    // the dock icon. See Bug 557225.
    childProcPath->AppendNative(NS_LITERAL_CSTRING("plugin-container.app"));
    childProcPath->AppendNative(NS_LITERAL_CSTRING("Contents"));
    childProcPath->AppendNative(NS_LITERAL_CSTRING("MacOS"));
    nsCString tempCPath;
    childProcPath->GetNativePath(tempCPath);
    exePath = FilePath(tempCPath.get());
#else
    nsCString path;
    NS_CopyUnicodeToNative(nsDependentString(gGREBinPath), path);
    exePath = FilePath(path.get());
#endif
  }

  if (exePath.empty()) {
#ifdef OS_WIN
    exePath = FilePath::FromWStringHack(CommandLine::ForCurrentProcess()->program());
#else
    exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
#endif
    exePath = exePath.DirName();
  }

#ifdef MOZ_WIDGET_ANDROID
  exePath = exePath.AppendASCII("lib");

  // We must use the PIE binary on 5.0 and higher
  const char* processName = mozilla::AndroidBridge::Bridge()->GetAPIVersion() >= 21 ?
    MOZ_CHILD_PROCESS_NAME_PIE : MOZ_CHILD_PROCESS_NAME;

  exePath = exePath.AppendASCII(processName);
#else
  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);
#endif
}
bool
GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts)
{
  // FIXME/cjones: make this work from non-IO threads, too

  // We rely on the fact that InitializeChannel() has already been processed
  // on the IO thread before this point is reached.
  if (!GetChannel()) {
    return false;
  }

  base::ProcessHandle process;

  // send the child the PID so that it can open a ProcessHandle back to us.
  // probably don't want to do this in the long run
  char pidstring[32];
  PR_snprintf(pidstring, sizeof(pidstring) - 1,
	      "%ld", base::Process::Current().pid());

  const char* const childProcessType =
      XRE_ChildProcessTypeToString(mProcessType);

//--------------------------------------------------
#if defined(OS_POSIX)
  // For POSIX, we have to be extremely anal about *not* using
  // std::wstring in code compiled with Mozilla's -fshort-wchar
  // configuration, because chromium is compiled with -fno-short-wchar
  // and passing wstrings from one config to the other is unsafe.  So
  // we split the logic here.

  FilePath exePath;
#ifdef OS_LINUX
  base::environment_map newEnvVars;
#endif

  nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
  nsCOMPtr<nsIFile> greDir;
  nsresult rv = directoryService->Get(NS_GRE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(greDir));
  if (NS_SUCCEEDED(rv)) {
    nsCString path;
    greDir->GetNativePath(path);
    exePath = FilePath(path.get());
#ifdef OS_LINUX
    newEnvVars["LD_LIBRARY_PATH"] = path.get();
#endif
  }
  else {
    exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
    exePath = exePath.DirName();
  }
  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);

  // remap the IPC socket fd to a well-known int, as the OS does for
  // STDOUT_FILENO, for example
  int srcChannelFd, dstChannelFd;
  channel().GetClientFileDescriptorMapping(&srcChannelFd, &dstChannelFd);
  mFileMap.push_back(std::pair<int,int>(srcChannelFd, dstChannelFd));

  // no need for kProcessChannelID, the child process inherits the
  // other end of the socketpair() from us

  std::vector<std::string> childArgv;

  childArgv.push_back(exePath.value());

  childArgv.insert(childArgv.end(), aExtraOpts.begin(), aExtraOpts.end());

  childArgv.push_back(pidstring);
  childArgv.push_back(childProcessType);

#if defined(MOZ_CRASHREPORTER)
  int childCrashFd, childCrashRemapFd;
  if (!CrashReporter::CreateNotificationPipeForChild(
        &childCrashFd, &childCrashRemapFd))
    return false;
  if (0 <= childCrashFd) {
    mFileMap.push_back(std::pair<int,int>(childCrashFd, childCrashRemapFd));
    // "true" == crash reporting enabled
    childArgv.push_back("true");
  }
  else {
    // "false" == crash reporting disabled
    childArgv.push_back("false");
  }
#endif

  base::LaunchApp(childArgv, mFileMap,
#ifdef OS_LINUX
                  newEnvVars,
#endif
                  false, &process);

//--------------------------------------------------
#elif defined(OS_WIN)

  FilePath exePath =
    FilePath::FromWStringHack(CommandLine::ForCurrentProcess()->program());
  exePath = exePath.DirName();

  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);

  CommandLine cmdLine(exePath.ToWStringHack());
  cmdLine.AppendSwitchWithValue(switches::kProcessChannelID, channel_id());

  for (std::vector<std::string>::iterator it = aExtraOpts.begin();
       it != aExtraOpts.end();
       ++it) {
      cmdLine.AppendLooseValue(UTF8ToWide(*it));
  }

  cmdLine.AppendLooseValue(UTF8ToWide(pidstring));
  cmdLine.AppendLooseValue(UTF8ToWide(childProcessType));
#if defined(MOZ_CRASHREPORTER)
  cmdLine.AppendLooseValue(
    UTF8ToWide(CrashReporter::GetChildNotificationPipe()));
#endif

  base::LaunchApp(cmdLine, false, false, &process);

#else
#  error Sorry
#endif

  if (!process) {
    return false;
  }
  SetHandle(process);

  return true;
}
示例#8
0
文件: Root.cpp 项目: cnxsoft/xibo4arm
bool Root::init(FileString homeDirectory, FileString subprocessDirectory, unsigned int extra_argc, const char* extra_argv[] ) {

    new base::AtExitManager();

    FilePath subprocess;

    // convert extra arguments in a more useful form
    std::vector< std::string > extra_args;
    if( extra_argc > 0 )
    {
        for( unsigned int arg_idx = 0; arg_idx < extra_argc; ++arg_idx )
        {
            const char* raw_arg = extra_argv[ arg_idx ];
            assert( raw_arg );
            extra_args.push_back( raw_arg );
        }
    }


    {
// From <base/command_line.h>:
  // Initialize the current process CommandLine singleton.  On Windows,
  // ignores its arguments (we instead parse GetCommandLineW()
  // directly) because we don't trust the CRT's parsing of the command
  // line, but it still must be called to set up the command line.
// This means that on windows, we have to call ::Init with whatever we feel
// like (since this is the only way to create the static CommandLine instance),
// and then we have manually call ParseFromString.
// (InitFromArgv does not exist on OS_WIN!)
#if defined(OS_WIN)
    FilePath module_dir;
    if (subprocessDirectory.size()) {
        module_dir = FilePath(subprocessDirectory.get<FilePath::StringType>());
    } else {
        PathService::Get(base::DIR_MODULE, &module_dir);
    }
#ifdef _DEBUG
    subprocess = module_dir.Append(L"berkelium_d.exe");
#else
    subprocess = module_dir.Append(L"berkelium.exe");
#endif

	std::wstring subprocess_str = L"berkelium --enable-webgl --browser-subprocess-path=";
	subprocess_str += L"\"";
	subprocess_str += subprocess.value();
	subprocess_str += L"\"";

    // add extra arguments if any
    if( !extra_args.empty() )
    {
        for( unsigned int arg_idx = 0, arg_count = extra_args.size(); arg_idx < arg_count; ++arg_idx )
        {
            const std::string& str_arg = extra_args[ arg_idx ];
            std::wstring wstr_arg( str_arg.begin(), str_arg.end() );

            subprocess_str += L" " + wstr_arg;
        }
    }

    //std::wcout << "Berkelium subprocess_str : " << subprocess_str;

    CommandLine::Init(0, NULL);
    CommandLine::ForCurrentProcess()->ParseFromString(subprocess_str);
#elif defined(OS_MACOSX)
    FilePath app_contents;
    PathService::Get(base::FILE_EXE, &app_contents);
    FilePath module_dir;
    if (subprocessDirectory.size()) {
        module_dir = FilePath(subprocessDirectory.get<FilePath::StringType>());
    } else {
        module_dir = app_contents.DirName();
    }
    subprocess = module_dir.Append("berkelium");
    std::string subprocess_str = "--browser-subprocess-path=";
    subprocess_str += subprocess.value();

    std::vector<const char*> argv;
    argv.push_back( "berkelium" );
    argv.push_back( subprocess_str.c_str() );
    argv.push_back( "--enable-webgl" );

    for( std::vector<std::string>::iterator it = extra_args.begin(); it != extra_args.end(); ++it )
    {
        argv.push_back( it->c_str() );
    }

    //for( std::vector<const char*>::iterator it = argv.begin(); it != argv.end(); ++it )
    //    std::cout << "Berkelium arg : " << *it;

    CommandLine::Init( argv.size(), &argv[0] );
#elif defined(OS_POSIX)
    FilePath module_file;
    PathService::Get(base::FILE_EXE, &module_file);
    FilePath module_dir;
    if (subprocessDirectory.size()) {
        module_dir = FilePath(subprocessDirectory.get<FilePath::StringType>());
    } else {
        module_dir = module_file.DirName();
    }
    subprocess = module_dir.Append("berkelium");
    std::string subprocess_str = "--browser-subprocess-path=";
    subprocess_str += subprocess.value();
    std::vector<const char*> argv;
    argv.push_back( "berkelium" );
    argv.push_back( subprocess_str.c_str() );
    argv.push_back( "--enable-webgl" );

    for( std::vector<std::string>::iterator it = extra_args.begin(); it != extra_args.end(); ++it )
    {
        argv.push_back( it->c_str() );
    }
    //for( std::vector<const char*>::iterator it = argv.begin(); it != argv.end(); ++it )
    //    std::cout << "Berkelium arg : " << *it;

    CommandLine::Init( argv.size(), &argv[0]) ;
#endif
    }

    PathService::Override(base::FILE_EXE, subprocess);

#if !defined(OS_WIN)
/// Temporary SingletonLock fix:
// Do not do this for child processes--they should only be initialized.
// Children should never delete the lock.
    if (signal(SIGINT, handleINT) == SIG_IGN) {
        signal(SIGINT, SIG_IGN);
    }
    if (signal(SIGHUP, handleINT) == SIG_IGN) {
        signal(SIGHUP, SIG_IGN);
    }
    if (signal(SIGTERM, handleINT) == SIG_IGN) {
        signal(SIGTERM, SIG_IGN);
    }
#endif

    chrome::RegisterPathProvider();
    ui::RegisterPathProvider();
    FilePath homedirpath;

    if (homeDirectory.data() && homeDirectory.length()) {
        FilePath homeDirectoryPath(homeDirectory.get<FilePath::StringType>());
        PathService::Override(chrome::DIR_USER_DATA, homeDirectoryPath);
        PathService::Override(chrome::DIR_LOGS, homeDirectoryPath);
#if defined(OS_POSIX)
        PathService::Override(base::DIR_CACHE, homeDirectoryPath);
#endif
    } else {
        mTempProfileDir.reset(new ScopedTempDir());
        if (mTempProfileDir->CreateUniqueTempDir()) {
            PathService::Override(chrome::DIR_USER_DATA, mTempProfileDir->path());
            PathService::Override(chrome::DIR_LOGS, mTempProfileDir->path());
#if defined(OS_POSIX)
            PathService::Override(base::DIR_CACHE, mTempProfileDir->path());
#endif
        }
    }
    PathService::Get(chrome::DIR_USER_DATA,&homedirpath);
    bool SINGLE_PROCESS=false;
#if defined(OS_MACOSX)
    base::mac::SetOverrideAppBundlePath(chrome::GetFrameworkBundlePath());
    if (SINGLE_PROCESS) {
        InitWebCoreSystemInterface();
        //CGColorSpaceCreateDeviceRGB();
    }
#endif  // OS_MACOSX
    if (SINGLE_PROCESS) {
        RenderProcessHost::set_run_renderer_in_process(true);
    }
    mMessageLoop.reset(new MessageLoop(MessageLoop::TYPE_UI));
    mSysMon.reset(new ui::SystemMonitor);
    mTimerMgr.reset(new HighResolutionTimerManager);
    mUIThread.reset(new BrowserThread(BrowserThread::UI, mMessageLoop.get()));
    mErrorHandler = 0;

#if defined(OS_LINUX)
    if (!g_thread_supported ()) // the client application might have already setup glib
	{
		g_thread_init(NULL);
		// Glib type system initialization. Needed at least for gconf,
		// used in net/proxy/proxy_config_service_linux.cc. Most likely
		// this is superfluous as gtk_init() ought to do this. It's
		// definitely harmless, so retained as a reminder of this
		// requirement for gconf.
		g_type_init();
		// gtk_init() can change |argc| and |argv|.
		char argv0data[] = "[Berkelium]";
		char *argv0 = argv0data;
		char **argv = &argv0;
		int argc = 1;
		gtk_init(&argc, &argv);
    }
    SetUpGLibLogHandler();
#endif

    mProcessSingleton.reset(new ProcessSingleton(homedirpath));
    BrowserProcessImpl *browser_process;
    browser_process=new BrowserProcessImpl(*CommandLine::ForCurrentProcess());
    browser_process->local_state()->RegisterStringPref(prefs::kApplicationLocale, "");
    browser_process->local_state()->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false);
    assert(g_browser_process == browser_process);

#ifdef OS_WIN
    logging::InitLogging(
        L"chrome.log",
        logging::LOG_NONE,
        logging::DONT_LOCK_LOG_FILE,
        logging::DELETE_OLD_LOG_FILE,
        logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
        );
#else
    logging::InitLogging(
        "chrome.log",
        logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
        logging::DONT_LOCK_LOG_FILE,
        logging::DELETE_OLD_LOG_FILE,
        logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
        );
#endif
    logging::InitChromeLogging(
        *CommandLine::ForCurrentProcess(),
        logging::DELETE_OLD_LOG_FILE);
    //APPEND_TO_OLD_LOG_FILE

  chrome::RegisterChromeSchemes(); // Required for "chrome-extension://" in InitExtensions
#if defined(OS_LINUX)
    const char* sandbox_binary = NULL;
    struct stat st;

    // In Chromium branded builds, developers can set an environment variable to
    // use the development sandbox. See
    // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
    if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid())
      sandbox_binary = getenv("CHROME_DEVEL_SANDBOX");

    std::string sandbox_cmd;
    if (sandbox_binary && !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoSandbox))
      sandbox_cmd = sandbox_binary;

    // Tickle the sandbox host and zygote host so they fork now.
    RenderSandboxHostLinux* shost = RenderSandboxHostLinux::GetInstance();
    shost->Init(sandbox_cmd);
    ZygoteHost* zhost = ZygoteHost::GetInstance();
    zhost->Init(sandbox_cmd);

    // We want to be sure to init NSPR on the main thread.
    base::EnsureNSPRInit();
#endif  // defined(OS_LINUX)

  SandboxInitWrapper sandbox_wrapper;
#if defined(OS_WIN)
  // Get the interface pointer to the BrokerServices or TargetServices,
  // depending who we are.
  sandbox::SandboxInterfaceInfo sandbox_info = {0};
  sandbox_info.broker_services = sandbox::BrokerServicesBase::GetInstance();
  sandbox::InitBrokerServices(sandbox_info.broker_services);
  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoSandbox)) {
    bool use_winsta = !CommandLine::ForCurrentProcess()->HasSwitch(
        switches::kDisableAltWinstation);
    // Precreate the desktop and window station used by the renderers.
    sandbox::TargetPolicy* policy = sandbox_info.broker_services->CreatePolicy();
    sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
    CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
    policy->Release();
  }
  sandbox_wrapper.SetServices(&sandbox_info);
#endif
  sandbox_wrapper.InitializeSandbox(*CommandLine::ForCurrentProcess(), "");

  bool icu_result = icu_util::Initialize();
  CHECK(icu_result);

    mRenderViewHostFactory.reset(new MemoryRenderViewHostFactory);

//    mNotificationService=new NotificationService();
//    ChildProcess* coreProcess=new ChildProcess;
//    coreProcess->set_main_thread(new ChildThread);
    g_browser_process->SetApplicationLocale("en-US");
    ResourceBundle::InitSharedInstance("en-US");// FIXME: lookup locale
    // We only load the theme dll in the browser process.
    net::CookieMonster::EnableFileScheme();

    browser_process->profile_manager();
    browser_process->db_thread();
    browser_process->file_thread();
    browser_process->process_launcher_thread();
    browser_process->cache_thread();
    browser_process->io_thread();

    // Initialize histogram synchronizer system. This is a singleton and is used
    // for posting tasks via NewRunnableMethod. Its deleted when it goes out of
    // scope. Even though NewRunnableMethod does AddRef and Release, the object
    // will not be deleted after the Task is executed.
    mHistogramSynchronizer= (new HistogramSynchronizer());

    browser::RegisterLocalState(g_browser_process->local_state());

    ProfileManager* profile_manager = browser_process->profile_manager();
    homedirpath = homedirpath.Append(profile_manager->GetCurrentProfileDir());
    {
        //std::cout << "Profile path: " << homedirpath.value() << std::endl;
        FilePath prefs_path (ProfileManager::GetProfilePrefsPath(homedirpath));
        FILE *fp = file_util::OpenFile(prefs_path, "a");
        file_util::CloseFile(fp);
        FilePath history_path (homedirpath);
        history_path = history_path.Append(chrome::kHistoryFilename);
        //std::cout << "  Profile exists: " << ProfileManager::IsProfile(homedirpath) << std::endl;
    }
    mProf = profile_manager->GetProfile(homedirpath, false);
    if (!mProf) {
        mProcessSingleton.reset();
        return false;
    }
    mProf->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, false);
    mProf->GetPrefs()->RegisterStringPref(prefs::kSafeBrowsingClientKey, "");
    mProf->GetPrefs()->RegisterStringPref(prefs::kSafeBrowsingWrappedKey, "");
    mProf->InitExtensions();

    PrefService* user_prefs = mProf->GetPrefs();
    DCHECK(user_prefs);

//    browser_process->local_state()->SetString(prefs::kApplicationLocale,std::wstring());
    mProcessSingleton->Create();

    mDNSPrefetch.reset(new chrome_browser_net::PredictorInit(
      user_prefs,
      browser_process->local_state(),
      CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePreconnect)));

    BrowserURLHandler::InitURLHandlers();

    // From chrome/browser/browser_main.cc
  // Register our global network handler for chrome:// and
  // chrome-extension:// URLs.
  ChromeURLDataManagerBackend::Register();
/*
  RegisterExtensionProtocols();
  RegisterMetadataURLRequestHandler();
  RegisterBlobURLRequestJobFactory();
  RegisterFileSystemURLRequestJobFactory();
*/


    {
        FilePath plugindata = homedirpath.AppendASCII("plugin_");
        if (!file_util::CreateDirectory(plugindata)) {
            return false;
        }
        PluginService::GetInstance()->SetChromePluginDataDir(plugindata);
    }
    PluginService::GetInstance()->LoadChromePlugins(
        g_browser_process->resource_dispatcher_host());

    mDefaultRequestContext=mProf->GetRequestContext();

    if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kRemoteDebuggingPort)) {
        std::string debugging_port_str =
            CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kRemoteDebuggingPort);
        int64 debugging_port = -1;
        bool has_debugging_port = base::StringToInt64(debugging_port_str, &debugging_port);
        if (has_debugging_port && debugging_port > 0 && debugging_port < 65535) {
            devtools_http_handler_ =
                Berkelium::DevToolsHttpProtocolHandler::Start(
                    "127.0.0.1",
                    static_cast<int>(debugging_port),
                    ""
                );
        }
    }

    return true;
}