gecko-dev/toolkit/xre/ProfileReset.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 строки
3.0 KiB
C
Исходник Обычный вид История

/* -*- 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 "nsToolkitProfileService.h"
#include "nsIFile.h"
#include "nsIThread.h"
#include "nsThreadUtils.h"
static bool gProfileResetCleanupCompleted = false;
static const char kResetProgressURL[] =
Bug 1601093, Rename the remaining .xul files to .xhtml in toolkit/ r=marionette-reviewers,mossop,whimboo Differential Revision: https://phabricator.services.mozilla.com/D55857 --HG-- rename : toolkit/components/alerts/resources/content/alert.xul => toolkit/components/alerts/resources/content/alert.xhtml rename : toolkit/components/apppicker/content/appPicker.xul => toolkit/components/apppicker/content/appPicker.xhtml rename : toolkit/components/extensions/dummy.xul => toolkit/components/extensions/dummy.xhtml rename : toolkit/components/passwordmgr/content/passwordManager.xul => toolkit/components/passwordmgr/content/passwordManager.xhtml rename : toolkit/components/printing/content/printPageSetup.xul => toolkit/components/printing/content/printPageSetup.xhtml rename : toolkit/components/printing/content/printPreviewProgress.xul => toolkit/components/printing/content/printPreviewProgress.xhtml rename : toolkit/components/printing/content/printProgress.xul => toolkit/components/printing/content/printProgress.xhtml rename : toolkit/components/prompts/content/commonDialog.xul => toolkit/components/prompts/content/commonDialog.xhtml rename : toolkit/components/prompts/content/selectDialog.xul => toolkit/components/prompts/content/selectDialog.xhtml rename : toolkit/components/viewconfig/content/config.xul => toolkit/components/viewconfig/content/config.xhtml rename : toolkit/content/editMenuKeys.inc.xul => toolkit/content/editMenuKeys.inc.xhtml rename : toolkit/content/resetProfile.xul => toolkit/content/resetProfile.xhtml rename : toolkit/content/resetProfileProgress.xul => toolkit/content/resetProfileProgress.xhtml rename : toolkit/modules/win.xul => toolkit/modules/win.xhtml rename : toolkit/profile/content/createProfileWizard.xul => toolkit/profile/content/createProfileWizard.xhtml rename : toolkit/profile/content/profileDowngrade.xul => toolkit/profile/content/profileDowngrade.xhtml rename : toolkit/profile/content/profileSelection.xul => toolkit/profile/content/profileSelection.xhtml extra : moz-landing-system : lando
2019-12-11 20:44:54 +03:00
"chrome://global/content/resetProfileProgress.xhtml";
nsresult ProfileResetCleanup(nsToolkitProfileService* aService,
nsIToolkitProfile* aOldProfile);
class ProfileResetCleanupResultTask : public mozilla::Runnable {
public:
ProfileResetCleanupResultTask()
: mozilla::Runnable("ProfileResetCleanupResultTask"),
mWorkerThread(do_GetCurrentThread()) {
MOZ_ASSERT(!NS_IsMainThread());
}
NS_IMETHOD Run() override {
MOZ_ASSERT(NS_IsMainThread());
mWorkerThread->Shutdown();
return NS_OK;
}
private:
nsCOMPtr<nsIThread> mWorkerThread;
};
class ProfileResetCleanupAsyncTask : public mozilla::Runnable {
public:
ProfileResetCleanupAsyncTask(nsIFile* aProfileDir, nsIFile* aProfileLocalDir,
nsIFile* aTargetDir, const nsAString& aLeafName)
: mozilla::Runnable("ProfileResetCleanupAsyncTask"),
mProfileDir(aProfileDir),
mProfileLocalDir(aProfileLocalDir),
mTargetDir(aTargetDir),
mLeafName(aLeafName) {}
/**
* Copy a root profile to a backup folder before deleting it. Then delete the
* local profile dir.
*/
NS_IMETHOD Run() override {
// Copy profile's files to the destination. The profile folder will be
// removed after the changes to the known profiles have been flushed to disk
// in nsToolkitProfileService::ApplyResetProfile which isn't called until
// after this thread finishes copying the files.
nsresult rv = mProfileDir->CopyToFollowingLinks(mTargetDir, mLeafName);
// I guess we just warn if we fail to make the backup?
if (NS_WARN_IF(NS_FAILED(rv))) {
NS_WARNING("Could not backup the root profile directory");
}
// 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:
nsCOMPtr<nsIFile> mProfileDir;
nsCOMPtr<nsIFile> mProfileLocalDir;
nsCOMPtr<nsIFile> mTargetDir;
nsString mLeafName;
};