mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Bug 1757849 - Add PathUtils.osTempDir r=emcminn
Differential Revision: https://phabricator.services.mozilla.com/D140146
This commit is contained in:
parent
965cc08896
commit
35916358ca
@ -120,6 +120,12 @@ partial namespace PathUtils {
|
||||
*/
|
||||
[Throws, BinaryName="TempDirSync"]
|
||||
readonly attribute DOMString tempDir;
|
||||
|
||||
/**
|
||||
* The OS temporary directory.
|
||||
*/
|
||||
[Throws, BinaryName="OSTempDirSync"]
|
||||
readonly attribute DOMString osTempDir;
|
||||
};
|
||||
|
||||
[Exposed=Worker]
|
||||
@ -141,4 +147,10 @@ partial namespace PathUtils {
|
||||
*/
|
||||
[Throws, BinaryName="GetTempDirAsync"]
|
||||
Promise<DOMString> getTempDir();
|
||||
|
||||
/**
|
||||
* The OS temporary directory.
|
||||
*/
|
||||
[Throws, BinaryName="GetOSTempDirAsync"]
|
||||
Promise<DOMString> getOSTempDir();
|
||||
};
|
||||
|
@ -374,6 +374,15 @@ void PathUtils::GetTempDirSync(const GlobalObject&, nsString& aResult,
|
||||
.GetDirectorySync(aResult, aErr, DirectoryCache::Directory::Temp);
|
||||
}
|
||||
|
||||
void PathUtils::GetOSTempDirSync(const GlobalObject&, nsString& aResult,
|
||||
ErrorResult& aErr) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
auto guard = sDirCache.Lock();
|
||||
DirectoryCache::Ensure(guard.ref())
|
||||
.GetDirectorySync(aResult, aErr, DirectoryCache::Directory::OSTemp);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> PathUtils::GetProfileDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr) {
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
@ -402,6 +411,15 @@ already_AddRefed<Promise> PathUtils::GetTempDirAsync(
|
||||
.GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::Temp);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> PathUtils::GetOSTempDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr) {
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
auto guard = sDirCache.Lock();
|
||||
return DirectoryCache::Ensure(guard.ref())
|
||||
.GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::OSTemp);
|
||||
}
|
||||
|
||||
PathUtils::DirectoryCache::DirectoryCache() {
|
||||
for (auto& dir : mDirectories) {
|
||||
dir.SetIsVoid(true);
|
||||
@ -491,9 +509,9 @@ PathUtils::DirectoryCache::PopulateDirectories(
|
||||
|
||||
// If we have already resolved the requested directory, we can return
|
||||
// immediately.
|
||||
// Otherwise, if we have already fired off a request to populate the entry, so
|
||||
// we can return the corresponding promise immediately. caller will queue a
|
||||
// Thenable onto that promise to resolve/reject the request.
|
||||
// Otherwise, if we have already fired off a request to populate the entry,
|
||||
// so we can return the corresponding promise immediately. caller will queue
|
||||
// a Thenable onto that promise to resolve/reject the request.
|
||||
if (!mDirectories[aRequestedDir].IsVoid()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -538,8 +556,8 @@ nsresult PathUtils::DirectoryCache::PopulateDirectoriesImpl(
|
||||
|
||||
if (!mDirectories[aRequestedDir].IsVoid()) {
|
||||
// In between when this promise was dispatched to the main thread and now,
|
||||
// the directory cache has had this entry populated (via the on-main-thread
|
||||
// sync method).
|
||||
// the directory cache has had this entry populated (via the
|
||||
// on-main-thread sync method).
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
@ -73,6 +74,8 @@ class PathUtils final {
|
||||
ErrorResult& aErr);
|
||||
static void GetTempDirSync(const GlobalObject&, nsString& aResult,
|
||||
ErrorResult& aErr);
|
||||
static void GetOSTempDirSync(const GlobalObject&, nsString& aResult,
|
||||
ErrorResult& aErr);
|
||||
|
||||
static already_AddRefed<Promise> GetProfileDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr);
|
||||
@ -80,6 +83,8 @@ class PathUtils final {
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr);
|
||||
static already_AddRefed<Promise> GetTempDirAsync(const GlobalObject& aGlobal,
|
||||
ErrorResult& aErr);
|
||||
static already_AddRefed<Promise> GetOSTempDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr);
|
||||
|
||||
private:
|
||||
class DirectoryCache;
|
||||
@ -110,6 +115,10 @@ class PathUtils::DirectoryCache final {
|
||||
* The temporary directory for the process.
|
||||
*/
|
||||
Temp,
|
||||
/**
|
||||
* The OS temporary directory.
|
||||
*/
|
||||
OSTemp,
|
||||
/**
|
||||
* The number of Directory entries.
|
||||
*/
|
||||
@ -222,6 +231,7 @@ class PathUtils::DirectoryCache final {
|
||||
NS_APP_USER_PROFILE_50_DIR,
|
||||
NS_APP_USER_PROFILE_LOCAL_50_DIR,
|
||||
NS_APP_CONTENT_PROCESS_TEMP_DIR,
|
||||
NS_OS_TEMP_DIR,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -33,5 +33,12 @@ self.onmessage = async function(message) {
|
||||
"PathUtils.getTempDir() in a worker should match PathUtils.tempDir on main thread"
|
||||
);
|
||||
|
||||
const osTempDir = await PathUtils.getOSTempDir();
|
||||
is(
|
||||
osTempDir,
|
||||
expected.osTempDir,
|
||||
"PathUtils.getOSTempDir() in a worker should match PathUtils.osTempDir on main thread"
|
||||
);
|
||||
|
||||
finish();
|
||||
};
|
||||
|
@ -478,6 +478,7 @@
|
||||
["profileDir", "ProfD"],
|
||||
["localProfileDir", "ProfLD"],
|
||||
["tempDir", AppConstants.MOZ_SANDBOX ? "ContentTmpD" : "TmpD"],
|
||||
["osTempDir", "TmpD"],
|
||||
];
|
||||
|
||||
for (const [attrName, dirConstant] of tests) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
profileDir: PathUtils.profileDir,
|
||||
localProfileDir: PathUtils.localProfileDir,
|
||||
tempDir: PathUtils.tempDir,
|
||||
osTempDir: PathUtils.osTempDir,
|
||||
});
|
||||
|
||||
info("test_pathtuils_worker.xhtml: Test running...");
|
||||
|
Loading…
x
Reference in New Issue
Block a user