LCOV - code coverage report
Current view: top level - toolkit/xre - ProfileReset.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 29 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : #include "nsIToolkitProfileService.h"
       7             : #include "nsIFile.h"
       8             : #include "nsThreadUtils.h"
       9             : 
      10             : static bool gProfileResetCleanupCompleted = false;
      11             : static const char kResetProgressURL[] = "chrome://global/content/resetProfileProgress.xul";
      12             : 
      13             : nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
      14             :                             const nsACString& aOldProfileName,
      15             :                             nsIToolkitProfile* *aNewProfile);
      16             : 
      17             : nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile);
      18             : 
      19           0 : class ProfileResetCleanupResultTask : public mozilla::Runnable
      20             : {
      21             : public:
      22           0 :   ProfileResetCleanupResultTask()
      23           0 :     : mozilla::Runnable("ProfileResetCleanupResultTask")
      24           0 :     , mWorkerThread(do_GetCurrentThread())
      25             :   {
      26           0 :     MOZ_ASSERT(!NS_IsMainThread());
      27           0 :   }
      28             : 
      29           0 :   NS_IMETHOD Run() override {
      30           0 :     MOZ_ASSERT(NS_IsMainThread());
      31           0 :     mWorkerThread->Shutdown();
      32           0 :     return NS_OK;
      33             :   }
      34             : 
      35             : private:
      36             :   nsCOMPtr<nsIThread> mWorkerThread;
      37             : };
      38             : 
      39           0 : class ProfileResetCleanupAsyncTask : public mozilla::Runnable
      40             : {
      41             : public:
      42           0 :   ProfileResetCleanupAsyncTask(nsIFile* aProfileDir,
      43             :                                nsIFile* aProfileLocalDir,
      44             :                                nsIFile* aTargetDir,
      45             :                                const nsAString& aLeafName)
      46           0 :     : mozilla::Runnable("ProfileResetCleanupAsyncTask")
      47             :     , mProfileDir(aProfileDir)
      48             :     , mProfileLocalDir(aProfileLocalDir)
      49             :     , mTargetDir(aTargetDir)
      50           0 :     , mLeafName(aLeafName)
      51           0 :   { }
      52             : 
      53             : /**
      54             :  * Copy a root profile to a backup folder before deleting it.  Then delete the local profile dir.
      55             :  */
      56           0 :   NS_IMETHOD Run() override
      57             :   {
      58             :     // Copy to the destination then delete the profile. A move doesn't follow links.
      59           0 :     nsresult rv = mProfileDir->CopyToFollowingLinks(mTargetDir, mLeafName);
      60           0 :     if (NS_SUCCEEDED(rv))
      61           0 :       rv = mProfileDir->Remove(true);
      62           0 :     if (NS_WARN_IF(NS_FAILED(rv))) {
      63           0 :       NS_WARNING("Could not backup the root profile directory");
      64             :     }
      65             : 
      66             :     // If we have a separate local cache profile directory, just delete it.
      67             :     // Don't return an error if this fails so that reset can proceed if it can't be deleted.
      68             :     bool sameDir;
      69           0 :     nsresult rvLocal = mProfileDir->Equals(mProfileLocalDir, &sameDir);
      70           0 :     if (NS_SUCCEEDED(rvLocal) && !sameDir) {
      71           0 :       rvLocal = mProfileLocalDir->Remove(true);
      72           0 :       if (NS_FAILED(rvLocal)) NS_WARNING("Could not remove the old local profile directory (cache)");
      73             :     }
      74           0 :     gProfileResetCleanupCompleted = true;
      75             : 
      76           0 :     nsCOMPtr<nsIRunnable> resultRunnable = new ProfileResetCleanupResultTask();
      77           0 :     NS_DispatchToMainThread(resultRunnable);
      78           0 :     return NS_OK;
      79             :   }
      80             : 
      81             : private:
      82             :   nsCOMPtr<nsIFile> mProfileDir;
      83             :   nsCOMPtr<nsIFile> mProfileLocalDir;
      84             :   nsCOMPtr<nsIFile> mTargetDir;
      85             :   nsString mLeafName;
      86             : };

Generated by: LCOV version 1.13