Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / toolkit / xre / ProfileReset.h
blobfaf74d09820e8bbe6da8c10f2d8e87d4557e9ab7
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsIToolkitProfileService.h"
7 #include "nsIFile.h"
8 #include "nsThreadUtils.h"
10 static bool gProfileResetCleanupCompleted = false;
11 static const char kResetProgressURL[] = "chrome://global/content/resetProfileProgress.xul";
13 nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
14 nsIToolkitProfile* *aNewProfile);
16 nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile);
18 class ProfileResetCleanupResultTask : public nsRunnable
20 public:
21 ProfileResetCleanupResultTask()
22 : mWorkerThread(do_GetCurrentThread())
24 MOZ_ASSERT(!NS_IsMainThread());
27 NS_IMETHOD Run() {
28 MOZ_ASSERT(NS_IsMainThread());
29 mWorkerThread->Shutdown();
30 return NS_OK;
33 private:
34 nsCOMPtr<nsIThread> mWorkerThread;
37 class ProfileResetCleanupAsyncTask : public nsRunnable
39 public:
40 ProfileResetCleanupAsyncTask(nsIFile* aProfileDir, nsIFile* aProfileLocalDir,
41 nsIFile* aTargetDir, const nsAString &aLeafName)
42 : mProfileDir(aProfileDir)
43 , mProfileLocalDir(aProfileLocalDir)
44 , mTargetDir(aTargetDir)
45 , mLeafName(aLeafName)
46 { }
48 /**
49 * Copy a root profile to a backup folder before deleting it. Then delete the local profile dir.
51 NS_IMETHOD Run()
53 // Copy to the destination then delete the profile. A move doesn't follow links.
54 nsresult rv = mProfileDir->CopyToFollowingLinks(mTargetDir, mLeafName);
55 if (NS_SUCCEEDED(rv))
56 rv = mProfileDir->Remove(true);
57 else
58 NS_WARNING("Could not backup the root profile directory");
60 // If we have a separate local cache profile directory, just delete it.
61 // Don't return an error if this fails so that reset can proceed if it can't be deleted.
62 bool sameDir;
63 nsresult rvLocal = mProfileDir->Equals(mProfileLocalDir, &sameDir);
64 if (NS_SUCCEEDED(rvLocal) && !sameDir) {
65 rvLocal = mProfileLocalDir->Remove(true);
66 if (NS_FAILED(rvLocal)) NS_WARNING("Could not remove the old local profile directory (cache)");
68 gProfileResetCleanupCompleted = true;
70 nsCOMPtr<nsIRunnable> resultRunnable = new ProfileResetCleanupResultTask();
71 NS_DispatchToMainThread(resultRunnable);
72 return NS_OK;
75 private:
76 nsCOMPtr<nsIFile> mProfileDir;
77 nsCOMPtr<nsIFile> mProfileLocalDir;
78 nsCOMPtr<nsIFile> mTargetDir;
79 nsAutoString mLeafName;