mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-08 12:22:34 +00:00
55dc7cb4db
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: https://phabricator.services.mozilla.com/D16116 --HG-- extra : moz-landing-system : lando
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
/* -*- Mode: C++; tab-width: 8; 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "prenv.h"
|
|
|
|
namespace mozilla {
|
|
|
|
// Load the path of a file saved with SaveFileToEnv
|
|
already_AddRefed<nsIFile> GetFileFromEnv(const char* name) {
|
|
nsresult rv;
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
#ifdef XP_WIN
|
|
WCHAR path[_MAX_PATH];
|
|
if (!GetEnvironmentVariableW(NS_ConvertASCIItoUTF16(name).get(), path,
|
|
_MAX_PATH))
|
|
return nullptr;
|
|
|
|
rv = NS_NewLocalFile(nsDependentString(path), true, getter_AddRefs(file));
|
|
if (NS_FAILED(rv)) return nullptr;
|
|
|
|
return file.forget();
|
|
#else
|
|
const char* arg = PR_GetEnv(name);
|
|
if (!arg || !*arg) {
|
|
return nullptr;
|
|
}
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(arg), true,
|
|
getter_AddRefs(file));
|
|
if (NS_FAILED(rv)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return file.forget();
|
|
#endif
|
|
}
|
|
|
|
} // namespace mozilla
|