Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsDeleteDir_h__ |
michael@0 | 8 | #define nsDeleteDir_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsCOMArray.h" |
michael@0 | 12 | #include "mozilla/Mutex.h" |
michael@0 | 13 | #include "mozilla/CondVar.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIFile; |
michael@0 | 16 | class nsIThread; |
michael@0 | 17 | class nsITimer; |
michael@0 | 18 | |
michael@0 | 19 | |
michael@0 | 20 | class nsDeleteDir { |
michael@0 | 21 | public: |
michael@0 | 22 | nsDeleteDir(); |
michael@0 | 23 | ~nsDeleteDir(); |
michael@0 | 24 | |
michael@0 | 25 | static nsresult Init(); |
michael@0 | 26 | static nsresult Shutdown(bool finishDeleting); |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * This routine attempts to delete a directory that may contain some files |
michael@0 | 30 | * that are still in use. This latter point is only an issue on Windows and |
michael@0 | 31 | * a few other systems. |
michael@0 | 32 | * |
michael@0 | 33 | * If the moveToTrash parameter is true we first rename the given directory |
michael@0 | 34 | * "foo.Trash123" (where "foo" is the original directory name, and "123" is |
michael@0 | 35 | * a random number, in order to support multiple concurrent deletes). The |
michael@0 | 36 | * directory is then deleted, file-by-file, on a background thread. |
michael@0 | 37 | * |
michael@0 | 38 | * If the moveToTrash parameter is false, then the given directory is deleted |
michael@0 | 39 | * directly. |
michael@0 | 40 | * |
michael@0 | 41 | * If 'delay' is non-zero, the directory will not be deleted until the |
michael@0 | 42 | * specified number of milliseconds have passed. (The directory is still |
michael@0 | 43 | * renamed immediately if 'moveToTrash' is passed, so upon return it is safe |
michael@0 | 44 | * to create a directory with the same name). |
michael@0 | 45 | */ |
michael@0 | 46 | static nsresult DeleteDir(nsIFile *dir, bool moveToTrash, uint32_t delay = 0); |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * Returns the trash directory corresponding to the given directory. |
michael@0 | 50 | */ |
michael@0 | 51 | static nsresult GetTrashDir(nsIFile *dir, nsCOMPtr<nsIFile> *result); |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * Remove all trashes left from previous run. This function does nothing when |
michael@0 | 55 | * called second and more times. |
michael@0 | 56 | */ |
michael@0 | 57 | static nsresult RemoveOldTrashes(nsIFile *cacheDir); |
michael@0 | 58 | |
michael@0 | 59 | static void TimerCallback(nsITimer *aTimer, void *arg); |
michael@0 | 60 | |
michael@0 | 61 | private: |
michael@0 | 62 | friend class nsBlockOnBackgroundThreadEvent; |
michael@0 | 63 | friend class nsDestroyThreadEvent; |
michael@0 | 64 | |
michael@0 | 65 | nsresult InitThread(); |
michael@0 | 66 | void DestroyThread(); |
michael@0 | 67 | nsresult PostTimer(void *arg, uint32_t delay); |
michael@0 | 68 | nsresult RemoveDir(nsIFile *file, bool *stopDeleting); |
michael@0 | 69 | |
michael@0 | 70 | static nsDeleteDir * gInstance; |
michael@0 | 71 | mozilla::Mutex mLock; |
michael@0 | 72 | mozilla::CondVar mCondVar; |
michael@0 | 73 | nsCOMArray<nsITimer> mTimers; |
michael@0 | 74 | nsCOMPtr<nsIThread> mThread; |
michael@0 | 75 | bool mShutdownPending; |
michael@0 | 76 | bool mStopDeleting; |
michael@0 | 77 | }; |
michael@0 | 78 | |
michael@0 | 79 | #endif // nsDeleteDir_h__ |