Bug 1885602 - Part 3: Add MenuHeader for the menu redesign r=android-reviewers,007
[gecko.git] / toolkit / xre / nsXREDirProvider.h
blobe25fccda223ffd15009b5477a53e6f280dc5ae45
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef _nsXREDirProvider_h__
7 #define _nsXREDirProvider_h__
9 #include "nsIDirectoryService.h"
10 #include "nsIProfileMigrator.h"
11 #include "nsIFile.h"
12 #include "nsIXREDirProvider.h"
14 #include "nsCOMPtr.h"
15 #include "nsCOMArray.h"
16 #include "mozilla/Attributes.h"
17 #ifdef MOZ_BACKGROUNDTASKS
18 # include "mozilla/BackgroundTasks.h"
19 #endif
21 // {5573967d-f6cf-4c63-8e0e-9ac06e04d62b}
22 #define NS_XREDIRPROVIDER_CID \
23 { \
24 0x5573967d, 0xf6cf, 0x4c63, { \
25 0x8e, 0x0e, 0x9a, 0xc0, 0x6e, 0x04, 0xd6, 0x2b \
26 } \
28 #define NS_XREDIRPROVIDER_CONTRACTID "@mozilla.org/xre/directory-provider;1"
30 class nsXREDirProvider final : public nsIDirectoryServiceProvider2,
31 public nsIXREDirProvider,
32 public nsIProfileStartup {
33 public:
34 // we use a custom isupports implementation (no refcount)
35 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
36 NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
37 NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
39 NS_DECL_NSIDIRECTORYSERVICEPROVIDER
40 NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
41 NS_DECL_NSIXREDIRPROVIDER
42 NS_DECL_NSIPROFILESTARTUP
44 nsXREDirProvider();
46 nsresult Initialize(nsIFile* aXULAppDir, nsIFile* aGREDir);
47 ~nsXREDirProvider();
49 static already_AddRefed<nsXREDirProvider> GetSingleton();
51 nsresult GetUserProfilesRootDir(nsIFile** aResult);
52 nsresult GetUserProfilesLocalDir(nsIFile** aResult);
53 #ifdef MOZ_BACKGROUNDTASKS
54 // A special location for non-ephemeral background tasks profiles,
55 // distinct from user profiles.
56 nsresult GetBackgroundTasksProfilesRootDir(nsIFile** aResult);
57 #endif
59 nsresult GetLegacyInstallHash(nsAString& aPathHash);
61 nsresult SetProfile(nsIFile* aProfileDir, nsIFile* aProfileLocalDir);
63 void InitializeUserPrefs();
64 void FinishInitializingUserPrefs();
66 void DoShutdown();
68 static nsresult GetUserAppDataDirectory(nsIFile** aFile) {
69 return GetUserDataDirectory(aFile, false);
71 static nsresult GetUserLocalDataDirectory(nsIFile** aFile) {
72 return GetUserDataDirectory(aFile, true);
75 static nsresult GetUserDataDirectory(nsIFile** aFile, bool aLocal);
77 /* make sure you clone it, if you need to do stuff to it */
78 nsIFile* GetGREDir() { return mGREDir; }
79 nsIFile* GetGREBinDir() { return mGREBinDir; }
80 nsIFile* GetAppDir() {
81 if (mXULAppDir) return mXULAppDir;
82 return mGREDir;
85 /**
86 * Get the directory under which update directory is created.
87 * This method may be called before XPCOM is started. aResult
88 * is a clone, it may be modified.
90 * If aGetOldLocation is true, this function will return the location of
91 * the update directory before it was moved from the user profile directory
92 * to a per-installation directory. This functionality is only meant to be
93 * used for migration of the update directory to the new location. It is only
94 * valid to request the old update location on Windows, since that is the only
95 * platform on which the update directory was migrated.
97 nsresult GetUpdateRootDir(nsIFile** aResult, bool aGetOldLocation = false);
99 /**
100 * Get the profile startup directory.
101 * This method may be called before XPCOM is started. aResult
102 * is a clone, it may be modified.
104 nsresult GetProfileStartupDir(nsIFile** aResult);
107 * Get the profile directory. Only call this method
108 * when XPCOM is initialized! aResult is a clone, it may be modified.
110 nsresult GetProfileDir(nsIFile** aResult);
112 private:
113 nsresult GetFilesInternal(const char* aProperty,
114 nsISimpleEnumerator** aResult);
115 static nsresult GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal);
116 static nsresult GetSysUserExtensionsDirectory(nsIFile** aFile);
117 #if defined(XP_UNIX) || defined(XP_MACOSX)
118 static nsresult GetSystemExtensionsDirectory(nsIFile** aFile);
119 #endif
120 static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
122 // Determine the profile path within the UAppData directory. This is different
123 // on every major platform.
124 static nsresult AppendProfilePath(nsIFile* aFile, bool aLocal);
126 static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
128 // Internal helper that splits a path into components using the '/' and '\\'
129 // delimiters.
130 static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
132 static nsresult SetUserDataProfileDirectory(nsCOMPtr<nsIFile>& aFile,
133 bool aLocal);
135 #if defined(MOZ_CONTENT_TEMP_DIR)
136 // Load the temp directory for sandboxed content processes
137 nsresult LoadContentProcessTempDir();
138 #endif
140 void Append(nsIFile* aDirectory);
142 // On OSX, mGREDir points to .app/Contents/Resources
143 nsCOMPtr<nsIFile> mGREDir;
144 // On OSX, mGREBinDir points to .app/Contents/MacOS
145 nsCOMPtr<nsIFile> mGREBinDir;
146 // On OSX, mXULAppDir points to .app/Contents/Resources/browser
147 nsCOMPtr<nsIFile> mXULAppDir;
148 nsCOMPtr<nsIFile> mProfileDir;
149 nsCOMPtr<nsIFile> mProfileLocalDir;
150 bool mAppStarted = false;
151 bool mPrefsInitialized = false;
152 #if defined(MOZ_CONTENT_TEMP_DIR)
153 nsCOMPtr<nsIFile> mContentTempDir;
154 nsCOMPtr<nsIFile> mContentProcessSandboxTempDir;
155 #endif
158 #endif