1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/profile/dirserviceprovider/src/nsProfileLock.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __nsProfileLock_h___ 1.10 +#define __nsProfileLock_h___ 1.11 + 1.12 +#include "nsIFile.h" 1.13 + 1.14 +class nsIProfileUnlocker; 1.15 + 1.16 +#if defined (XP_WIN) 1.17 +#include <windows.h> 1.18 +#endif 1.19 + 1.20 +#if defined (XP_UNIX) 1.21 +#include <signal.h> 1.22 +#include "prclist.h" 1.23 +#endif 1.24 + 1.25 +class nsProfileLock 1.26 +#if defined (XP_UNIX) 1.27 + : public PRCList 1.28 +#endif 1.29 +{ 1.30 +public: 1.31 + nsProfileLock(); 1.32 + nsProfileLock(nsProfileLock& src); 1.33 + 1.34 + ~nsProfileLock(); 1.35 + 1.36 + nsProfileLock& operator=(nsProfileLock& rhs); 1.37 + 1.38 + /** 1.39 + * Attempt to lock a profile directory. 1.40 + * 1.41 + * @param aProfileDir [in] The profile directory to lock. 1.42 + * @param aUnlocker [out] Optional. This is only returned when locking 1.43 + * fails with NS_ERROR_FILE_ACCESS_DENIED, and may not 1.44 + * be returned at all. 1.45 + * @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked. 1.46 + */ 1.47 + nsresult Lock(nsIFile* aProfileDir, nsIProfileUnlocker* *aUnlocker); 1.48 + 1.49 + /** 1.50 + * Unlock a profile directory. If you're unlocking the directory because 1.51 + * the application is in the process of shutting down because of a fatal 1.52 + * signal, set aFatalSignal to true. 1.53 + */ 1.54 + nsresult Unlock(bool aFatalSignal = false); 1.55 + 1.56 + /** 1.57 + * Get the modification time of a replaced profile lock, otherwise 0. 1.58 + */ 1.59 + nsresult GetReplacedLockTime(PRTime* aResult); 1.60 + 1.61 +private: 1.62 + bool mHaveLock; 1.63 + PRTime mReplacedLockTime; 1.64 + 1.65 +#if defined (XP_WIN) 1.66 + HANDLE mLockFileHandle; 1.67 +#elif defined (XP_UNIX) 1.68 + 1.69 + struct RemovePidLockFilesExiting { 1.70 + RemovePidLockFilesExiting() {} 1.71 + ~RemovePidLockFilesExiting() { 1.72 + RemovePidLockFiles(false); 1.73 + } 1.74 + }; 1.75 + 1.76 + static void RemovePidLockFiles(bool aFatalSignal); 1.77 + static void FatalSignalHandler(int signo 1.78 +#ifdef SA_SIGINFO 1.79 + , siginfo_t *info, void *context 1.80 +#endif 1.81 + ); 1.82 + static PRCList mPidLockList; 1.83 + 1.84 + nsresult LockWithFcntl(nsIFile *aLockFile); 1.85 + 1.86 + /** 1.87 + * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this 1.88 + * lock is merely an "obsolete" lock to keep out old Firefoxes 1.89 + */ 1.90 + nsresult LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock); 1.91 + 1.92 + char* mPidLockFileName; 1.93 + int mLockFileDesc; 1.94 +#endif 1.95 + 1.96 +}; 1.97 + 1.98 +#endif /* __nsProfileLock_h___ */