gecko-dev/toolkit/profile/nsToolkitProfileService.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

185 строки
6.2 KiB
C
Исходник Обычный вид История

/* -*- 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
#include "nsIToolkitProfileService.h"
#include "nsIToolkitProfile.h"
#include "nsIFactory.h"
#include "nsSimpleEnumerator.h"
#include "nsProfileLock.h"
#include "nsINIParser.h"
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
2019-03-28 00:41:04 +03:00
class nsToolkitProfile final
: public nsIToolkitProfile,
public mozilla::LinkedListElement<RefPtr<nsToolkitProfile>> {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITOOLKITPROFILE
friend class nsToolkitProfileService;
private:
~nsToolkitProfile() = default;
nsToolkitProfile(const nsACString& aName, nsIFile* aRootDir,
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
2019-03-28 00:41:04 +03:00
nsIFile* aLocalDir, bool aFromDB);
nsresult RemoveInternal(bool aRemoveFiles, bool aInBackground);
friend class nsToolkitProfileLock;
nsCString mName;
nsCOMPtr<nsIFile> mRootDir;
nsCOMPtr<nsIFile> mLocalDir;
nsIProfileLock* mLock;
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
2019-03-28 00:41:04 +03:00
uint32_t mIndex;
nsCString mSection;
};
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,
nsIToolkitProfile** aProfile, bool* aDidCreate,
bool* aWasDefaultSelection);
nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
nsresult ApplyResetProfile(nsIToolkitProfile* aOldProfile);
void CompleteStartup();
private:
friend class nsToolkitProfile;
friend class nsToolkitProfileFactory;
friend nsresult NS_NewToolkitProfileService(nsToolkitProfileService**);
nsToolkitProfileService();
~nsToolkitProfileService();
nsresult Init();
nsresult CreateTimesInternal(nsIFile* profileDir);
void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
nsIToolkitProfile** aResult);
nsresult GetProfileDescriptor(nsIToolkitProfile* aProfile,
nsACString& aDescriptor, bool* aIsRelative);
bool IsProfileForCurrentInstall(nsIToolkitProfile* aProfile);
void ClearProfileFromOtherInstalls(nsIToolkitProfile* aProfile);
nsresult MaybeMakeDefaultDedicatedProfile(nsIToolkitProfile* aProfile,
bool* aResult);
bool IsSnapEnvironment();
bool UseLegacyProfiles();
nsresult CreateDefaultProfile(nsIToolkitProfile** aResult);
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
2019-03-28 00:41:04 +03:00
void SetNormalDefault(nsIToolkitProfile* aProfile);
// Returns the known install hashes from the installs database. Modifying the
// installs database is safe while iterating the returned array.
nsTArray<nsCString> GetKnownInstalls();
// Tracks whether SelectStartupProfile has been called.
bool mStartupProfileSelected;
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
2019-03-28 00:41:04 +03:00
// The profiles loaded from profiles.ini.
mozilla::LinkedList<RefPtr<nsToolkitProfile>> mProfiles;
// The profile selected for use at startup, if it exists in profiles.ini.
nsCOMPtr<nsIToolkitProfile> mCurrent;
// The profile selected for this install in installs.ini.
nsCOMPtr<nsIToolkitProfile> mDedicatedProfile;
// 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.
nsCOMPtr<nsIFile> mAppData;
// The directory that holds the cache files for profiles.
nsCOMPtr<nsIFile> mTempData;
// The location of profiles.ini.
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
2019-03-28 00:41:04 +03:00
nsCOMPtr<nsIFile> mProfileDBFile;
// The location of installs.ini.
Bug 1527704: Store install information in profiles.ini and use installs.ini as a backup in case an earlier Firefox throws it away. r=froydnj Originally we stored the new information about installation defaults in installs.ini since older versions of Firefox would throw away any new data in profiles.ini any time they made changes to the profiles. That does however mean we have to load two files on startup. This changes things so that we save all the data in profiles.ini as well as a version tag and still save the install data into installs.ini. An older version will throw away the install data and version tag from profiles.ini but leave installs.ini alone. On startup if the version tag is gone from profiles.ini then we reload the install data from installs.ini and put it back into profiles.ini. At some point in the future where we don't care about supporting older versions of Firefox we can just drop installs.ini entirely. A lot of the changes here involve moving to loading profiles.ini into an in-memory ini, keeping it up to date and flushing it to disk. This means that we no longer throw away any information in the ini file that this version does not understand allowing the possibility of adding new data to this file in the future. Differential Revision: https://phabricator.services.mozilla.com/D22576 --HG-- extra : rebase_source : d00edf1ceb200a73a60bb1a90afabcdf95b01acf extra : intermediate-source : e1c9790cd3bee060da99ffe37026721e36bc46c3 extra : source : d4feb17faf013134f5eac8b5e19b714c56410973
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;
// 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;
// Whether to start with the selected profile by default.
bool mStartWithLast;
// True if during startup it appeared that this is the first run.
bool mIsFirstRun;
// True if the default profile is the separate dev-edition-profile.
bool mUseDevEditionProfile;
// True if this install should use a dedicated default profile.
const bool mUseDedicatedProfile;
// True if during startup no dedicated profile was already selected, an old
// default profile existed but was rejected so a new profile was created.
bool mCreatedAlternateProfile;
nsString mStartupReason;
bool mMaybeLockProfile;
// Holds the current application update channel. This is only really held
// so it can be overriden in tests.
nsCString mUpdateChannel;
// 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;
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