michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDeleteDir_h__ michael@0: #define nsDeleteDir_h__ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCOMArray.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/CondVar.h" michael@0: michael@0: class nsIFile; michael@0: class nsIThread; michael@0: class nsITimer; michael@0: michael@0: michael@0: class nsDeleteDir { michael@0: public: michael@0: nsDeleteDir(); michael@0: ~nsDeleteDir(); michael@0: michael@0: static nsresult Init(); michael@0: static nsresult Shutdown(bool finishDeleting); michael@0: michael@0: /** michael@0: * This routine attempts to delete a directory that may contain some files michael@0: * that are still in use. This latter point is only an issue on Windows and michael@0: * a few other systems. michael@0: * michael@0: * If the moveToTrash parameter is true we first rename the given directory michael@0: * "foo.Trash123" (where "foo" is the original directory name, and "123" is michael@0: * a random number, in order to support multiple concurrent deletes). The michael@0: * directory is then deleted, file-by-file, on a background thread. michael@0: * michael@0: * If the moveToTrash parameter is false, then the given directory is deleted michael@0: * directly. michael@0: * michael@0: * If 'delay' is non-zero, the directory will not be deleted until the michael@0: * specified number of milliseconds have passed. (The directory is still michael@0: * renamed immediately if 'moveToTrash' is passed, so upon return it is safe michael@0: * to create a directory with the same name). michael@0: */ michael@0: static nsresult DeleteDir(nsIFile *dir, bool moveToTrash, uint32_t delay = 0); michael@0: michael@0: /** michael@0: * Returns the trash directory corresponding to the given directory. michael@0: */ michael@0: static nsresult GetTrashDir(nsIFile *dir, nsCOMPtr *result); michael@0: michael@0: /** michael@0: * Remove all trashes left from previous run. This function does nothing when michael@0: * called second and more times. michael@0: */ michael@0: static nsresult RemoveOldTrashes(nsIFile *cacheDir); michael@0: michael@0: static void TimerCallback(nsITimer *aTimer, void *arg); michael@0: michael@0: private: michael@0: friend class nsBlockOnBackgroundThreadEvent; michael@0: friend class nsDestroyThreadEvent; michael@0: michael@0: nsresult InitThread(); michael@0: void DestroyThread(); michael@0: nsresult PostTimer(void *arg, uint32_t delay); michael@0: nsresult RemoveDir(nsIFile *file, bool *stopDeleting); michael@0: michael@0: static nsDeleteDir * gInstance; michael@0: mozilla::Mutex mLock; michael@0: mozilla::CondVar mCondVar; michael@0: nsCOMArray mTimers; michael@0: nsCOMPtr mThread; michael@0: bool mShutdownPending; michael@0: bool mStopDeleting; michael@0: }; michael@0: michael@0: #endif // nsDeleteDir_h__