/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
class PathUtils final { public: /** * Initialize the given nsIFile with the given path. * * This is equivalent to calling nsIFile::InitWithPath() with the caveat that * on Windows debug or during Windows CI tests, we will crash if the path * contains a forward slash. * * @param aFile The file to initialize. * @param aPath The path to initialize the file with. * * @return The result of calling nsIFile::InitWithPath.
*/ static nsresult InitFileWithPath(nsIFile* aFile, const nsAString& aPath);
/** * Join a sequence of path components and return an nsIFile with the resulting * path. * * @param aComponents A sequence of path components. The first component must * be an absolute path. * @param aErr The error result, if any. * * @return An nsIFile with the resulting path, if there were no errors. * Otherwise, nullptr is returned.
*/ static already_AddRefed<nsIFile> Join(const Span<const nsString>& aComponents,
ErrorResult& aErr);
/** * A cache of commonly used directories
*/ class PathUtils::DirectoryCache final { public: /** * A directory that can be requested via |GetDirectorySync| or * |GetDirectoryAsync|.
*/ enumclass Directory { /** * The user's profile directory.
*/
Profile, /** * The user's local profile directory.
*/
LocalProfile, /** * The OS temporary directory.
*/
Temp, /** * The libxul path.
*/
XulLibrary, /** * The number of Directory entries.
*/
Count,
};
/** * Ensure the cache is instantiated and schedule its destructor to run at * shutdown. * * If the cache is already instantiated, this is a no-op. * * @param aCache The cache to ensure is instantiated.
*/ static DirectoryCache& Ensure(Maybe<DirectoryCache>& aCache);
/** * Request the path of a specific directory. * * If the directory has not been requested before, this may require a trip to * the main thread to retrieve its path. * * @param aGlobalObject The JavaScript global. * @param aErr The error result. * @param aRequestedDir The directory for which the path is to be retrieved. * * @return A promise that resolves to the path of the requested directory.
*/
already_AddRefed<Promise> GetDirectoryAsync(const GlobalObject& aGlobalObject,
ErrorResult& aErr, const Directory aRequestedDir);
private: using PopulateDirectoriesPromise = MozPromise<Ok, nsresult, false>;
/** * Populate the directory cache entry for the requested directory. * * @param aRequestedDir The directory cache entry that was requested via * |GetDirectory|. * * @return If the requested directory has not been populated, this returns a * promise that resolves when the population is complete. * * If the requested directory has already been populated, it returns * nullptr instead.
*/
already_AddRefed<PopulateDirectoriesPromise> PopulateDirectories( const Directory aRequestedDir);
/** * Initialize the requested directory cache entry. * * If |Directory::Temp| is requested, all cache entries will be populated. * Otherwise, only the profile and local profile cache entries will be * populated. The profile and local profile cache entries have no additional * overhead for populating them, but the temp directory requires creating a * directory on the main thread if it has not already happened. * * Must be called on the main thread. * * @param aRequestedDir The requested directory. * * @return The result of initializing directories.
*/
nsresult PopulateDirectoriesImpl(const Directory aRequestedDir);
/** * Resolve the internal PopulateDirectoriesPromise corresponding to * |aRequestedDir| with the given result. * * This will allow all pending queries for the requested directory to resolve * or be rejected. * * @param aRv The return value from PopulateDirectoriesImpl. * @param aRequestedDir The requested directory cache entry. This is used to * determine which internal MozPromiseHolder we are * resolving.
*/ void ResolvePopulateDirectoriesPromise(nsresult aRv, const Directory aRequestedDir);
/** * Resolve the given JS promise with the path of the requested directory * * Can only be called once the cache entry for the requested directory is * populated. * * @param aPromise The JS promise to resolve. * @param aRequestedDir The requested directory cache entry.
*/ void ResolveWithDirectory(Promise* aPromise, const Directory aRequestedDir);
template <typename T> using DirectoryArray =
EnumeratedArray<Directory, T, size_t(Directory::Count)>;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.