2019-01-14 20:27:34 +03:00
|
|
|
|
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef nsToolkitProfileService_h
|
|
|
|
#define nsToolkitProfileService_h
|
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2019-01-14 20:27:34 +03:00
|
|
|
#include "nsIToolkitProfileService.h"
|
|
|
|
#include "nsIToolkitProfile.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsSimpleEnumerator.h"
|
|
|
|
#include "nsProfileLock.h"
|
2019-01-26 03:02:28 +03:00
|
|
|
#include "nsINIParser.h"
|
2019-01-14 20:27:34 +03:00
|
|
|
|
2019-03-28 00:41:04 +03:00
|
|
|
class nsToolkitProfile final
|
|
|
|
: public nsIToolkitProfile,
|
|
|
|
public mozilla::LinkedListElement<RefPtr<nsToolkitProfile>> {
|
2019-01-14 20:27:34 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITOOLKITPROFILE
|
|
|
|
|
|
|
|
friend class nsToolkitProfileService;
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsToolkitProfile() = default;
|
|
|
|
|
|
|
|
nsToolkitProfile(const nsACString& aName, nsIFile* aRootDir,
|
2019-03-28 00:41:04 +03:00
|
|
|
nsIFile* aLocalDir, bool aFromDB);
|
2019-01-14 20:27:34 +03:00
|
|
|
|
|
|
|
nsresult RemoveInternal(bool aRemoveFiles, bool aInBackground);
|
|
|
|
|
|
|
|
friend class nsToolkitProfileLock;
|
|
|
|
|
|
|
|
nsCString mName;
|
|
|
|
nsCOMPtr<nsIFile> mRootDir;
|
|
|
|
nsCOMPtr<nsIFile> mLocalDir;
|
|
|
|
nsIProfileLock* mLock;
|
2019-03-28 00:41:04 +03:00
|
|
|
uint32_t mIndex;
|
|
|
|
nsCString mSection;
|
2019-01-14 20:27:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsToolkitProfileLock final : public nsIProfileLock {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPROFILELOCK
|
|
|
|
|
|
|
|
nsresult Init(nsToolkitProfile* aProfile, nsIProfileUnlocker** aUnlocker);
|
|
|
|
nsresult Init(nsIFile* aDirectory, nsIFile* aLocalDirectory,
|
|
|
|
nsIProfileUnlocker** aUnlocker);
|
|
|
|
|
|
|
|
nsToolkitProfileLock() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsToolkitProfileLock();
|
|
|
|
|
|
|
|
RefPtr<nsToolkitProfile> mProfile;
|
|
|
|
nsCOMPtr<nsIFile> mDirectory;
|
|
|
|
nsCOMPtr<nsIFile> mLocalDirectory;
|
|
|
|
|
|
|
|
nsProfileLock mLock;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsToolkitProfileFactory final : public nsIFactory {
|
|
|
|
~nsToolkitProfileFactory() = default;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFACTORY
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsToolkitProfileService final : public nsIToolkitProfileService {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITOOLKITPROFILESERVICE
|
|
|
|
|
|
|
|
nsresult SelectStartupProfile(int* aArgc, char* aArgv[], bool aIsResetting,
|
|
|
|
nsIFile** aRootDir, nsIFile** aLocalDir,
|
2019-03-14 22:55:31 +03:00
|
|
|
nsIToolkitProfile** aProfile, bool* aDidCreate,
|
|
|
|
bool* aWasDefaultSelection);
|
2018-12-28 20:44:47 +03:00
|
|
|
nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
|
2019-01-26 03:02:28 +03:00
|
|
|
nsresult ApplyResetProfile(nsIToolkitProfile* aOldProfile);
|
2019-02-06 02:14:08 +03:00
|
|
|
void CompleteStartup();
|
2019-01-14 20:27:34 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class nsToolkitProfile;
|
|
|
|
friend class nsToolkitProfileFactory;
|
2019-02-12 23:14:33 +03:00
|
|
|
friend nsresult NS_NewToolkitProfileService(nsToolkitProfileService**);
|
2019-01-14 20:27:34 +03:00
|
|
|
|
|
|
|
nsToolkitProfileService();
|
|
|
|
~nsToolkitProfileService();
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
nsresult CreateTimesInternal(nsIFile* profileDir);
|
|
|
|
void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
|
|
|
|
nsIToolkitProfile** aResult);
|
|
|
|
|
2019-01-26 03:02:28 +03:00
|
|
|
nsresult GetProfileDescriptor(nsIToolkitProfile* aProfile,
|
|
|
|
nsACString& aDescriptor, bool* aIsRelative);
|
|
|
|
bool IsProfileForCurrentInstall(nsIToolkitProfile* aProfile);
|
|
|
|
void ClearProfileFromOtherInstalls(nsIToolkitProfile* aProfile);
|
2019-03-05 23:51:44 +03:00
|
|
|
nsresult MaybeMakeDefaultDedicatedProfile(nsIToolkitProfile* aProfile,
|
|
|
|
bool* aResult);
|
2019-01-26 03:02:28 +03:00
|
|
|
bool IsSnapEnvironment();
|
2019-06-20 16:47:42 +03:00
|
|
|
bool UseLegacyProfiles();
|
2019-02-27 22:24:04 +03:00
|
|
|
nsresult CreateDefaultProfile(nsIToolkitProfile** aResult);
|
2019-03-28 00:41:04 +03:00
|
|
|
void SetNormalDefault(nsIToolkitProfile* aProfile);
|
2019-01-26 03:02:28 +03:00
|
|
|
|
|
|
|
// Returns the known install hashes from the installs database. Modifying the
|
|
|
|
// installs database is safe while iterating the returned array.
|
|
|
|
nsTArray<nsCString> GetKnownInstalls();
|
|
|
|
|
2018-12-28 20:44:47 +03:00
|
|
|
// Tracks whether SelectStartupProfile has been called.
|
2019-01-14 20:27:34 +03:00
|
|
|
bool mStartupProfileSelected;
|
2019-03-28 00:41:04 +03:00
|
|
|
// The profiles loaded from profiles.ini.
|
|
|
|
mozilla::LinkedList<RefPtr<nsToolkitProfile>> mProfiles;
|
2018-12-28 20:44:47 +03:00
|
|
|
// The profile selected for use at startup, if it exists in profiles.ini.
|
|
|
|
nsCOMPtr<nsIToolkitProfile> mCurrent;
|
2019-01-26 03:02:28 +03:00
|
|
|
// The profile selected for this install in installs.ini.
|
|
|
|
nsCOMPtr<nsIToolkitProfile> mDedicatedProfile;
|
2018-12-28 20:44:47 +03:00
|
|
|
// The default profile used by non-dev-edition builds.
|
|
|
|
nsCOMPtr<nsIToolkitProfile> mNormalDefault;
|
|
|
|
// The profile used if mUseDevEditionProfile is true (the default on
|
|
|
|
// dev-edition builds).
|
|
|
|
nsCOMPtr<nsIToolkitProfile> mDevEditionDefault;
|
|
|
|
// The directory that holds profiles.ini and profile directories.
|
2019-01-14 20:27:34 +03:00
|
|
|
nsCOMPtr<nsIFile> mAppData;
|
2018-12-28 20:44:47 +03:00
|
|
|
// The directory that holds the cache files for profiles.
|
2019-01-14 20:27:34 +03:00
|
|
|
nsCOMPtr<nsIFile> mTempData;
|
2018-12-28 20:44:47 +03:00
|
|
|
// The location of profiles.ini.
|
2019-03-28 00:41:04 +03:00
|
|
|
nsCOMPtr<nsIFile> mProfileDBFile;
|
2019-01-26 03:02:28 +03:00
|
|
|
// The location of installs.ini.
|
2019-03-28 00:41:04 +03:00
|
|
|
nsCOMPtr<nsIFile> mInstallDBFile;
|
|
|
|
// The data loaded from profiles.ini.
|
|
|
|
nsINIParser mProfileDB;
|
|
|
|
// The section in the profiles db for the current install.
|
|
|
|
nsCString mInstallSection;
|
2019-06-12 20:48:09 +03:00
|
|
|
// A legacy install section which may have been generated against an
|
|
|
|
// installation directory with an incorrect case (see bug 1555319). It is only
|
|
|
|
// really held here so that it can be overridden by tests.
|
|
|
|
nsCString mLegacyInstallSection;
|
2018-12-28 20:44:47 +03:00
|
|
|
// Whether to start with the selected profile by default.
|
2019-01-14 20:27:34 +03:00
|
|
|
bool mStartWithLast;
|
2018-12-28 20:44:47 +03:00
|
|
|
// True if during startup it appeared that this is the first run.
|
2019-01-14 20:27:34 +03:00
|
|
|
bool mIsFirstRun;
|
2018-12-28 20:44:47 +03:00
|
|
|
// True if the default profile is the separate dev-edition-profile.
|
|
|
|
bool mUseDevEditionProfile;
|
2019-01-26 03:02:28 +03:00
|
|
|
// True if this install should use a dedicated default profile.
|
|
|
|
const bool mUseDedicatedProfile;
|
2019-01-26 01:05:39 +03:00
|
|
|
nsString mStartupReason;
|
2019-02-06 02:14:08 +03:00
|
|
|
bool mMaybeLockProfile;
|
2019-04-09 21:38:17 +03:00
|
|
|
// Holds the current application update channel. This is only really held
|
|
|
|
// so it can be overriden in tests.
|
|
|
|
nsCString mUpdateChannel;
|
2019-03-05 23:51:44 +03:00
|
|
|
// Keep track of some attributes of the databases so we can tell if another
|
|
|
|
// process has changed them.
|
|
|
|
bool mProfileDBExists;
|
|
|
|
int64_t mProfileDBFileSize;
|
|
|
|
PRTime mProfileDBModifiedTime;
|
2019-04-09 21:38:17 +03:00
|
|
|
|
2019-01-14 20:27:34 +03:00
|
|
|
static nsToolkitProfileService* gService;
|
|
|
|
|
|
|
|
class ProfileEnumerator final : public nsSimpleEnumerator {
|
|
|
|
public:
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
|
|
|
|
const nsID& DefaultInterface() override {
|
|
|
|
return NS_GET_IID(nsIToolkitProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit ProfileEnumerator(nsToolkitProfile* first) { mCurrent = first; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<nsToolkitProfile> mCurrent;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|