Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / netwerk / cache / nsDeleteDir.h
blobb16506165c7107a187e5b7caf18e76f7652ebea0
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 nsIThread;
17 class nsITimer;
20 class nsDeleteDir {
21 public:
22 nsDeleteDir();
23 ~nsDeleteDir();
25 static nsresult Init();
26 static nsresult Shutdown(bool finishDeleting);
28 /**
29 * This routine attempts to delete a directory that may contain some files
30 * that are still in use. This latter point is only an issue on Windows and
31 * a few other systems.
33 * If the moveToTrash parameter is true we first rename the given directory
34 * "foo.Trash123" (where "foo" is the original directory name, and "123" is
35 * a random number, in order to support multiple concurrent deletes). The
36 * directory is then deleted, file-by-file, on a background thread.
38 * If the moveToTrash parameter is false, then the given directory is deleted
39 * directly.
41 * If 'delay' is non-zero, the directory will not be deleted until the
42 * specified number of milliseconds have passed. (The directory is still
43 * renamed immediately if 'moveToTrash' is passed, so upon return it is safe
44 * to create a directory with the same name).
46 static nsresult DeleteDir(nsIFile *dir, bool moveToTrash, uint32_t delay = 0);
48 /**
49 * Returns the trash directory corresponding to the given directory.
51 static nsresult GetTrashDir(nsIFile *dir, nsCOMPtr<nsIFile> *result);
53 /**
54 * Remove all trashes left from previous run. This function does nothing when
55 * called second and more times.
57 static nsresult RemoveOldTrashes(nsIFile *cacheDir);
59 static void TimerCallback(nsITimer *aTimer, void *arg);
61 private:
62 friend class nsBlockOnBackgroundThreadEvent;
63 friend class nsDestroyThreadEvent;
65 nsresult InitThread();
66 void DestroyThread();
67 nsresult PostTimer(void *arg, uint32_t delay);
68 nsresult RemoveDir(nsIFile *file, bool *stopDeleting);
70 static nsDeleteDir * gInstance;
71 mozilla::Mutex mLock;
72 mozilla::CondVar mCondVar;
73 nsCOMArray<nsITimer> mTimers;
74 nsCOMPtr<nsIThread> mThread;
75 bool mShutdownPending;
76 bool mStopDeleting;
79 #endif // nsDeleteDir_h__