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