author Dave Townsend <>
Mon, 14 Jan 2019 17:27:34 +0000
changeset 513743 394b490d3e2deb8c31c71214320ebfc16a8db008
parent 508163 6f3709b3878117466168c40affa7bca0b60cf75b
child 513966 4ebefe9136b5a52ce58b9b46e33e4edf0b23b3b7
permissions -rw-r--r--
Bug 1518587: Move startup profile selection to nsToolkitProfileService. r=froydnj Currently nsAppRunner is responsible for choosing or creating a profile to use at startup. It then has to create a reset profile if necessary and lock the selected profile directories. But these latter things are done in different places of the selection code and done in different ways, sometimes we delay while trying to get the lock, sometimes we don't. This patch moves the profile selection part of the code to its own function so that then we only have to have one place that does the profile reset and locking logic. It makes a lot of sense to have the selection code live in the profile service. It can use information from the database load to help make the choices and it also means that we can expose the profile selection code through xpcom allowing it to be easily automatically tested. It will also be more important for future patches for the dedicated profiles feature. Differential Revision:

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef nsAppRunner_h__
#define nsAppRunner_h__

#ifdef XP_WIN
#include <windows.h>
#include <limits.h>

#ifdef PATH_MAX
#elif defined(_MAX_PATH)
#elif defined(CCHMAXPATH)
#define MAXPATHLEN 1024

#include "nsStringFwd.h"
#include "nsXULAppAPI.h"

class nsINativeAppSupport;
class nsXREDirProvider;
class nsIToolkitProfileService;
class nsIFile;
class nsIProfileLock;
class nsIProfileUnlocker;
class nsIFactory;

extern nsXREDirProvider* gDirServiceProvider;

// NOTE: gAppData will be null in embedded contexts.
extern const mozilla::XREAppData* gAppData;
extern bool gSafeMode;

extern int gArgc;
extern char** gArgv;
extern int gRestartArgc;
extern char** gRestartArgv;
extern bool gRestartedByOS;
extern bool gLogConsoleErrors;
extern nsString gAbsoluteArgv0Path;

extern bool gIsGtest;

 * Create the nativeappsupport implementation.
 * @note XPCOMInit has not happened yet.
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport** aResult);
already_AddRefed<nsINativeAppSupport> NS_GetNativeAppSupport();

nsresult NS_NewToolkitProfileService(nsIToolkitProfileService** aResult);

nsresult NS_NewToolkitProfileFactory(nsIFactory** aResult);

 * Try to acquire exclusive access to the specified profile directory.
 * @param aPath
 *        The profile directory to lock.
 * @param aTempPath
 *        The corresponding profile temporary directory.
 * @param aUnlocker
 *        A callback interface used to attempt to unlock a profile that
 *        appears to be locked.
 * @param aResult
 *        The resulting profile lock object (or null if the profile could
 *        not be locked).
 * @return NS_ERROR_FILE_ACCESS_DENIED to indicate that the profile
 *         directory cannot be unlocked.
nsresult NS_LockProfilePath(nsIFile* aPath, nsIFile* aTempPath,
                            nsIProfileUnlocker** aUnlocker,
                            nsIProfileLock** aResult);

void WriteConsoleLog();

void OverrideDefaultLocaleIfNeeded();

 * Allow exit() calls to complete. This should be done from a proper Gecko
 * shutdown path. Otherwise we aim to catch improper shutdowns.
void MozExpectedExit();

#ifdef XP_WIN
void UseParentConsole();

BOOL WinLaunchChild(const wchar_t* exePath, int argc, char** argv,
                    HANDLE userToken = nullptr, HANDLE* hProcess = nullptr);


namespace mozilla {
namespace startup {
Result<nsCOMPtr<nsIFile>, nsresult> GetIncompleteStartupFile(nsIFile* aProfLD);

extern GeckoProcessType sChildProcessType;
}  // namespace startup

const char* PlatformBuildID();

}  // namespace mozilla

 * Set up platform specific error handling such as suppressing DLL load dialog
 * and the JIT debugger on Windows, and install unix signal handlers.
void SetupErrorHandling(const char* progname);

extern "C" {
void MOZ_EXPORT __sanitizer_set_report_path(const char* path);
void setASanReporterPath(nsIFile* aDir);

#endif  // nsAppRunner_h__