michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Interfaces Needed michael@0: #include "nsIDirectoryService.h" michael@0: #include "nsIFile.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsDirectoryServiceUtils.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: #include "nsString.h" michael@0: #else michael@0: #include "nsEmbedString.h" michael@0: #endif michael@0: michael@0: // Forward Declarations michael@0: class nsProfileLock; michael@0: michael@0: // -------------------------------------------------------------------------------------- michael@0: // nsProfileDirServiceProvider - The nsIDirectoryServiceProvider implementation used for michael@0: // profile-relative file locations. michael@0: // -------------------------------------------------------------------------------------- michael@0: michael@0: class nsProfileDirServiceProvider: public nsIDirectoryServiceProvider michael@0: { michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDIRECTORYSERVICEPROVIDER michael@0: michael@0: friend nsresult NS_NewProfileDirServiceProvider(bool, nsProfileDirServiceProvider**); michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * SetProfileDir michael@0: * michael@0: * @param aProfileDir The directory containing the profile files. michael@0: * It does not need to exist before calling this michael@0: * method. If it does not, it will be created and michael@0: * defaults will be copied to it. michael@0: * @param aLocalProfileDir michael@0: * Directory for local profile data, e.g. Cache. michael@0: * If null, aProfileDir will be used for this purpose. michael@0: */ michael@0: michael@0: virtual nsresult SetProfileDir(nsIFile* aProfileDir, michael@0: nsIFile* aLocalProfileDir = nullptr); michael@0: michael@0: /** michael@0: * Register michael@0: * michael@0: * Convenience method to register the provider with directory service. michael@0: * The service holds strong references to registered providers so consumers michael@0: * don't need to hold a reference to this object after calling Register(). michael@0: */ michael@0: michael@0: virtual nsresult Register(); michael@0: michael@0: /** michael@0: * Shutdown michael@0: * michael@0: * This method must be called before shutting down XPCOM if this object michael@0: * was created with aNotifyObservers == true. If this object was michael@0: * created with aNotifyObservers == false, this method is a no-op. michael@0: */ michael@0: michael@0: virtual nsresult Shutdown(); michael@0: michael@0: protected: michael@0: nsProfileDirServiceProvider(bool aNotifyObservers = true); michael@0: virtual ~nsProfileDirServiceProvider(); michael@0: michael@0: nsresult Initialize(); michael@0: nsresult InitProfileDir(nsIFile* profileDir); michael@0: nsresult InitNonSharedProfileDir(); michael@0: nsresult EnsureProfileFileExists(nsIFile *aFile, nsIFile *destDir); michael@0: nsresult UndefineFileLocations(); michael@0: michael@0: protected: michael@0: michael@0: nsCOMPtr mProfileDir; michael@0: nsCOMPtr mLocalProfileDir; michael@0: nsProfileLock* mProfileDirLock; michael@0: bool mNotifyObservers; michael@0: michael@0: bool mSharingEnabled; michael@0: #ifndef MOZILLA_INTERNAL_API michael@0: nsEmbedString mNonSharedDirName; michael@0: #else michael@0: nsString mNonSharedDirName; michael@0: #endif michael@0: nsCOMPtr mNonSharedProfileDir; michael@0: }; michael@0: michael@0: michael@0: // -------------------------------------------------------------------------------------- michael@0: michael@0: /** michael@0: * Global method to create an instance of nsProfileDirServiceProvider michael@0: * michael@0: * @param aNotifyObservers If true, will send out profile startup michael@0: * notifications when the profile directory is set. michael@0: * See notifications.txt michael@0: */ michael@0: michael@0: nsresult NS_NewProfileDirServiceProvider(bool aNotifyObservers, michael@0: nsProfileDirServiceProvider** aProvider); michael@0: