2012-03-20 04:01:49 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsIToolkitProfileService.h"
|
2013-09-11 00:56:05 +04:00
|
|
|
#include "nsIFile.h"
|
2012-03-20 04:01:49 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
static bool gProfileResetCleanupCompleted = false;
|
|
|
|
static const char kResetProgressURL[] = "chrome://global/content/resetProfileProgress.xul";
|
|
|
|
|
|
|
|
nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
|
2017-02-10 02:29:58 +03:00
|
|
|
const nsACString& aOldProfileName,
|
2012-03-20 04:01:49 +04:00
|
|
|
nsIToolkitProfile* *aNewProfile);
|
|
|
|
|
|
|
|
nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile);
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ProfileResetCleanupResultTask : public mozilla::Runnable
|
2012-03-20 04:01:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProfileResetCleanupResultTask()
|
2017-06-12 22:34:10 +03:00
|
|
|
: mozilla::Runnable("ProfileResetCleanupResultTask")
|
|
|
|
, mWorkerThread(do_GetCurrentThread())
|
2012-03-20 04:01:49 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2012-03-20 04:01:49 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mWorkerThread->Shutdown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIThread> mWorkerThread;
|
|
|
|
};
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class ProfileResetCleanupAsyncTask : public mozilla::Runnable
|
2012-03-20 04:01:49 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
ProfileResetCleanupAsyncTask(nsIFile* aProfileDir,
|
|
|
|
nsIFile* aProfileLocalDir,
|
|
|
|
nsIFile* aTargetDir,
|
|
|
|
const nsAString& aLeafName)
|
|
|
|
: mozilla::Runnable("ProfileResetCleanupAsyncTask")
|
|
|
|
, mProfileDir(aProfileDir)
|
2012-03-20 04:01:49 +04:00
|
|
|
, mProfileLocalDir(aProfileLocalDir)
|
2013-04-05 16:31:28 +04:00
|
|
|
, mTargetDir(aTargetDir)
|
2012-03-20 04:01:49 +04:00
|
|
|
, mLeafName(aLeafName)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a root profile to a backup folder before deleting it. Then delete the local profile dir.
|
|
|
|
*/
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2012-03-20 04:01:49 +04:00
|
|
|
{
|
|
|
|
// Copy to the destination then delete the profile. A move doesn't follow links.
|
2013-04-05 16:31:28 +04:00
|
|
|
nsresult rv = mProfileDir->CopyToFollowingLinks(mTargetDir, mLeafName);
|
2012-03-20 04:01:49 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = mProfileDir->Remove(true);
|
2015-04-19 03:35:32 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2012-03-20 04:01:49 +04:00
|
|
|
NS_WARNING("Could not backup the root profile directory");
|
2015-04-19 03:35:32 +03:00
|
|
|
}
|
2012-03-20 04:01:49 +04:00
|
|
|
|
|
|
|
// If we have a separate local cache profile directory, just delete it.
|
|
|
|
// Don't return an error if this fails so that reset can proceed if it can't be deleted.
|
|
|
|
bool sameDir;
|
|
|
|
nsresult rvLocal = mProfileDir->Equals(mProfileLocalDir, &sameDir);
|
|
|
|
if (NS_SUCCEEDED(rvLocal) && !sameDir) {
|
|
|
|
rvLocal = mProfileLocalDir->Remove(true);
|
|
|
|
if (NS_FAILED(rvLocal)) NS_WARNING("Could not remove the old local profile directory (cache)");
|
|
|
|
}
|
|
|
|
gProfileResetCleanupCompleted = true;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> resultRunnable = new ProfileResetCleanupResultTask();
|
|
|
|
NS_DispatchToMainThread(resultRunnable);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> mProfileDir;
|
|
|
|
nsCOMPtr<nsIFile> mProfileLocalDir;
|
2013-04-05 16:31:28 +04:00
|
|
|
nsCOMPtr<nsIFile> mTargetDir;
|
2015-11-19 12:31:38 +03:00
|
|
|
nsString mLeafName;
|
2012-03-20 04:01:49 +04:00
|
|
|
};
|