profile/dirserviceprovider/src/nsProfileLock.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef __nsProfileLock_h___
michael@0 7 #define __nsProfileLock_h___
michael@0 8
michael@0 9 #include "nsIFile.h"
michael@0 10
michael@0 11 class nsIProfileUnlocker;
michael@0 12
michael@0 13 #if defined (XP_WIN)
michael@0 14 #include <windows.h>
michael@0 15 #endif
michael@0 16
michael@0 17 #if defined (XP_UNIX)
michael@0 18 #include <signal.h>
michael@0 19 #include "prclist.h"
michael@0 20 #endif
michael@0 21
michael@0 22 class nsProfileLock
michael@0 23 #if defined (XP_UNIX)
michael@0 24 : public PRCList
michael@0 25 #endif
michael@0 26 {
michael@0 27 public:
michael@0 28 nsProfileLock();
michael@0 29 nsProfileLock(nsProfileLock& src);
michael@0 30
michael@0 31 ~nsProfileLock();
michael@0 32
michael@0 33 nsProfileLock& operator=(nsProfileLock& rhs);
michael@0 34
michael@0 35 /**
michael@0 36 * Attempt to lock a profile directory.
michael@0 37 *
michael@0 38 * @param aProfileDir [in] The profile directory to lock.
michael@0 39 * @param aUnlocker [out] Optional. This is only returned when locking
michael@0 40 * fails with NS_ERROR_FILE_ACCESS_DENIED, and may not
michael@0 41 * be returned at all.
michael@0 42 * @throws NS_ERROR_FILE_ACCESS_DENIED if the profile is locked.
michael@0 43 */
michael@0 44 nsresult Lock(nsIFile* aProfileDir, nsIProfileUnlocker* *aUnlocker);
michael@0 45
michael@0 46 /**
michael@0 47 * Unlock a profile directory. If you're unlocking the directory because
michael@0 48 * the application is in the process of shutting down because of a fatal
michael@0 49 * signal, set aFatalSignal to true.
michael@0 50 */
michael@0 51 nsresult Unlock(bool aFatalSignal = false);
michael@0 52
michael@0 53 /**
michael@0 54 * Get the modification time of a replaced profile lock, otherwise 0.
michael@0 55 */
michael@0 56 nsresult GetReplacedLockTime(PRTime* aResult);
michael@0 57
michael@0 58 private:
michael@0 59 bool mHaveLock;
michael@0 60 PRTime mReplacedLockTime;
michael@0 61
michael@0 62 #if defined (XP_WIN)
michael@0 63 HANDLE mLockFileHandle;
michael@0 64 #elif defined (XP_UNIX)
michael@0 65
michael@0 66 struct RemovePidLockFilesExiting {
michael@0 67 RemovePidLockFilesExiting() {}
michael@0 68 ~RemovePidLockFilesExiting() {
michael@0 69 RemovePidLockFiles(false);
michael@0 70 }
michael@0 71 };
michael@0 72
michael@0 73 static void RemovePidLockFiles(bool aFatalSignal);
michael@0 74 static void FatalSignalHandler(int signo
michael@0 75 #ifdef SA_SIGINFO
michael@0 76 , siginfo_t *info, void *context
michael@0 77 #endif
michael@0 78 );
michael@0 79 static PRCList mPidLockList;
michael@0 80
michael@0 81 nsresult LockWithFcntl(nsIFile *aLockFile);
michael@0 82
michael@0 83 /**
michael@0 84 * @param aHaveFcntlLock if true, we've already acquired an fcntl lock so this
michael@0 85 * lock is merely an "obsolete" lock to keep out old Firefoxes
michael@0 86 */
michael@0 87 nsresult LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock);
michael@0 88
michael@0 89 char* mPidLockFileName;
michael@0 90 int mLockFileDesc;
michael@0 91 #endif
michael@0 92
michael@0 93 };
michael@0 94
michael@0 95 #endif /* __nsProfileLock_h___ */

mercurial