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 __nsProfileLock_h___
7 #define __nsProfileLock_h___
11 class nsIProfileUnlocker
;
29 nsProfileLock(nsProfileLock
& src
);
33 nsProfileLock
& operator=(nsProfileLock
& rhs
);
36 * Attempt to lock a profile directory.
38 * @param aProfileDir [in] The profile directory to lock.
39 * @param aUnlocker [out] Optional. This is only returned when locking
40 * fails with NS_ERROR_FILE_ACCESS_DENIED, and may not
42 * @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked.
44 nsresult
Lock(nsIFile
* aProfileDir
, nsIProfileUnlocker
** aUnlocker
);
47 * Unlock a profile directory. If you're unlocking the directory because
48 * the application is in the process of shutting down because of a fatal
49 * signal, set aFatalSignal to true.
51 nsresult
Unlock(bool aFatalSignal
= false);
54 * Checks, if the given file has a name that matches potential lock file
55 * names. It does not check, if it actually is the currently active lock.
57 static bool IsMaybeLockFile(nsIFile
* aFile
);
60 * Clean up any left over files in the directory.
65 * Get the modification time of a replaced profile lock, otherwise 0.
67 nsresult
GetReplacedLockTime(PRTime
* aResult
);
71 PRTime mReplacedLockTime
;
72 nsCOMPtr
<nsIFile
> mLockFile
;
75 HANDLE mLockFileHandle
;
76 #elif defined(XP_UNIX)
78 struct RemovePidLockFilesExiting
{
79 RemovePidLockFilesExiting() = default;
80 ~RemovePidLockFilesExiting() { RemovePidLockFiles(false); }
83 static void RemovePidLockFiles(bool aFatalSignal
);
84 static void FatalSignalHandler(int signo
87 siginfo_t
* info
, void* context
90 static PRCList mPidLockList
;
92 nsresult
LockWithFcntl(nsIFile
* aLockFile
,
93 nsIProfileUnlocker
** aUnlocker
= nullptr);
96 * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this
97 * lock is merely an "obsolete" lock to keep out old Firefoxes
99 nsresult
LockWithSymlink(nsIFile
* aLockFile
, bool aHaveFcntlLock
);
101 char* mPidLockFileName
;
106 #endif /* __nsProfileLock_h___ */