Bug 1835241 - Part 6: Use the same parameter names at definition and declaration...
[gecko.git] / toolkit / profile / nsToolkitProfileService.h
blobdea1af012440eca0bd4e95bdf6c47e135c421e43
2 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef nsToolkitProfileService_h
9 #define nsToolkitProfileService_h
11 #include "mozilla/Components.h"
12 #include "mozilla/LinkedList.h"
13 #include "nsIToolkitProfileService.h"
14 #include "nsIToolkitProfile.h"
15 #include "nsIFactory.h"
16 #include "nsSimpleEnumerator.h"
17 #include "nsProfileLock.h"
18 #include "nsINIParser.h"
20 class nsToolkitProfile final
21 : public nsIToolkitProfile,
22 public mozilla::LinkedListElement<RefPtr<nsToolkitProfile>> {
23 public:
24 NS_DECL_ISUPPORTS
25 NS_DECL_NSITOOLKITPROFILE
27 friend class nsToolkitProfileService;
29 private:
30 ~nsToolkitProfile() = default;
32 nsToolkitProfile(const nsACString& aName, nsIFile* aRootDir,
33 nsIFile* aLocalDir, bool aFromDB);
35 nsresult RemoveInternal(bool aRemoveFiles, bool aInBackground);
37 friend class nsToolkitProfileLock;
39 nsCString mName;
40 nsCOMPtr<nsIFile> mRootDir;
41 nsCOMPtr<nsIFile> mLocalDir;
42 nsIProfileLock* mLock;
43 uint32_t mIndex;
44 nsCString mSection;
47 class nsToolkitProfileLock final : public nsIProfileLock {
48 public:
49 NS_DECL_ISUPPORTS
50 NS_DECL_NSIPROFILELOCK
52 nsresult Init(nsToolkitProfile* aProfile, nsIProfileUnlocker** aUnlocker);
53 nsresult Init(nsIFile* aDirectory, nsIFile* aLocalDirectory,
54 nsIProfileUnlocker** aUnlocker);
56 nsToolkitProfileLock() = default;
58 private:
59 ~nsToolkitProfileLock();
61 RefPtr<nsToolkitProfile> mProfile;
62 nsCOMPtr<nsIFile> mDirectory;
63 nsCOMPtr<nsIFile> mLocalDirectory;
65 nsProfileLock mLock;
68 class nsToolkitProfileService final : public nsIToolkitProfileService {
69 public:
70 NS_DECL_ISUPPORTS
71 NS_DECL_NSITOOLKITPROFILESERVICE
73 nsresult SelectStartupProfile(int* aArgc, char* aArgv[], bool aIsResetting,
74 nsIFile** aRootDir, nsIFile** aLocalDir,
75 nsIToolkitProfile** aProfile, bool* aDidCreate,
76 bool* aWasDefaultSelection);
77 nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
78 nsresult ApplyResetProfile(nsIToolkitProfile* aOldProfile);
79 void CompleteStartup();
81 private:
82 friend class nsToolkitProfile;
83 friend already_AddRefed<nsToolkitProfileService>
84 NS_GetToolkitProfileService();
86 nsToolkitProfileService();
87 ~nsToolkitProfileService();
89 nsresult Init();
91 nsresult CreateTimesInternal(nsIFile* profileDir);
92 void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
93 nsIToolkitProfile** aResult);
95 nsresult GetProfileDescriptor(nsIToolkitProfile* aProfile,
96 nsACString& aDescriptor, bool* aIsRelative);
97 bool IsProfileForCurrentInstall(nsIToolkitProfile* aProfile);
98 void ClearProfileFromOtherInstalls(nsIToolkitProfile* aProfile);
99 nsresult MaybeMakeDefaultDedicatedProfile(nsIToolkitProfile* aProfile,
100 bool* aResult);
101 bool IsSnapEnvironment();
102 bool UseLegacyProfiles();
103 nsresult CreateDefaultProfile(nsIToolkitProfile** aResult);
104 void SetNormalDefault(nsIToolkitProfile* aProfile);
106 // Returns the known install hashes from the installs database. Modifying the
107 // installs database is safe while iterating the returned array.
108 nsTArray<nsCString> GetKnownInstalls();
110 // Tracks whether SelectStartupProfile has been called.
111 bool mStartupProfileSelected;
112 // The profiles loaded from profiles.ini.
113 mozilla::LinkedList<RefPtr<nsToolkitProfile>> mProfiles;
114 // The profile selected for use at startup, if it exists in profiles.ini.
115 nsCOMPtr<nsIToolkitProfile> mCurrent;
116 // The profile selected for this install in installs.ini.
117 nsCOMPtr<nsIToolkitProfile> mDedicatedProfile;
118 // The default profile used by non-dev-edition builds.
119 nsCOMPtr<nsIToolkitProfile> mNormalDefault;
120 // The profile used if mUseDevEditionProfile is true (the default on
121 // dev-edition builds).
122 nsCOMPtr<nsIToolkitProfile> mDevEditionDefault;
123 // The directory that holds profiles.ini and profile directories.
124 nsCOMPtr<nsIFile> mAppData;
125 // The directory that holds the cache files for profiles.
126 nsCOMPtr<nsIFile> mTempData;
127 // The location of profiles.ini.
128 nsCOMPtr<nsIFile> mProfileDBFile;
129 // The location of installs.ini.
130 nsCOMPtr<nsIFile> mInstallDBFile;
131 // The data loaded from profiles.ini.
132 nsINIParser mProfileDB;
133 // The section in the profiles db for the current install.
134 nsCString mInstallSection;
135 // A legacy install section which may have been generated against an
136 // installation directory with an incorrect case (see bug 1555319). It is only
137 // really held here so that it can be overridden by tests.
138 nsCString mLegacyInstallSection;
139 // Whether to start with the selected profile by default.
140 bool mStartWithLast;
141 // True if during startup it appeared that this is the first run.
142 bool mIsFirstRun;
143 // True if the default profile is the separate dev-edition-profile.
144 bool mUseDevEditionProfile;
145 // True if this install should use a dedicated default profile.
146 const bool mUseDedicatedProfile;
147 nsString mStartupReason;
148 bool mMaybeLockProfile;
149 // Holds the current application update channel. This is only really held
150 // so it can be overriden in tests.
151 nsCString mUpdateChannel;
152 // Keep track of some attributes of the databases so we can tell if another
153 // process has changed them.
154 bool mProfileDBExists;
155 int64_t mProfileDBFileSize;
156 PRTime mProfileDBModifiedTime;
158 static nsToolkitProfileService* gService;
160 class ProfileEnumerator final : public nsSimpleEnumerator {
161 public:
162 NS_DECL_NSISIMPLEENUMERATOR
164 const nsID& DefaultInterface() override {
165 return NS_GET_IID(nsIToolkitProfile);
168 explicit ProfileEnumerator(nsToolkitProfile* first) { mCurrent = first; }
170 private:
171 RefPtr<nsToolkitProfile> mCurrent;
175 already_AddRefed<nsToolkitProfileService> NS_GetToolkitProfileService();
177 #endif