toolkit/xre/ProfileReset.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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
    19 {
    20 public:
    21   ProfileResetCleanupResultTask()
    22     : mWorkerThread(do_GetCurrentThread())
    23   {
    24     MOZ_ASSERT(!NS_IsMainThread());
    25   }
    27   NS_IMETHOD Run() {
    28     MOZ_ASSERT(NS_IsMainThread());
    29     mWorkerThread->Shutdown();
    30     return NS_OK;
    31   }
    33 private:
    34   nsCOMPtr<nsIThread> mWorkerThread;
    35 };
    37 class ProfileResetCleanupAsyncTask : public nsRunnable
    38 {
    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.
    50  */
    51   NS_IMETHOD Run()
    52   {
    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)");
    67     }
    68     gProfileResetCleanupCompleted = true;
    70     nsCOMPtr<nsIRunnable> resultRunnable = new ProfileResetCleanupResultTask();
    71     NS_DispatchToMainThread(resultRunnable);
    72     return NS_OK;
    73   }
    75 private:
    76   nsCOMPtr<nsIFile> mProfileDir;
    77   nsCOMPtr<nsIFile> mProfileLocalDir;
    78   nsCOMPtr<nsIFile> mTargetDir;
    79   nsAutoString mLeafName;
    80 };

mercurial