toolkit/xre/nsUpdateDriver.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/xre/nsUpdateDriver.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsUpdateDriver_h__
    1.11 +#define nsUpdateDriver_h__
    1.12 +
    1.13 +#include "nscore.h"
    1.14 +#ifdef MOZ_UPDATER
    1.15 +#include "nsIUpdateService.h"
    1.16 +#include "nsIThread.h"
    1.17 +#include "nsCOMPtr.h"
    1.18 +#include "nsString.h"
    1.19 +#include "mozilla/Attributes.h"
    1.20 +#endif
    1.21 +
    1.22 +class nsIFile;
    1.23 +
    1.24 +#if defined(XP_WIN)
    1.25 +#include <windows.h>
    1.26 +  typedef HANDLE     ProcessType;
    1.27 +#elif defined(XP_MACOSX)
    1.28 +  typedef pid_t      ProcessType;
    1.29 +#else
    1.30 +#include "prproces.h"
    1.31 +  typedef PRProcess* ProcessType;
    1.32 +#endif
    1.33 +
    1.34 +/**
    1.35 + * This function processes any available updates.  As part of that process, it
    1.36 + * may exit the current process and relaunch it at a later time.
    1.37 + *
    1.38 + * Two directories are passed to this function: greDir (where the actual
    1.39 + * binary resides) and appDir (which contains application.ini for XULRunner
    1.40 + * apps). If this is not a XULRunner app then appDir is identical to greDir.
    1.41 + * 
    1.42 + * The argc and argv passed to this function should be what is needed to
    1.43 + * relaunch the current process.
    1.44 + *
    1.45 + * The appVersion param passed to this function is the current application's
    1.46 + * version and is used to determine if an update's version is older than the
    1.47 + * current application version.
    1.48 + *
    1.49 + * If you want the update to be processed without restarting, set the restart
    1.50 + * parameter to false.
    1.51 + *
    1.52 + * This function does not modify appDir.
    1.53 + */
    1.54 +NS_HIDDEN_(nsresult) ProcessUpdates(nsIFile *greDir, nsIFile *appDir,
    1.55 +                                    nsIFile *updRootDir,
    1.56 +                                    int argc, char **argv,
    1.57 +                                    const char *appVersion,
    1.58 +                                    bool restart = true,
    1.59 +                                    bool isOSUpdate = false,
    1.60 +                                    nsIFile *osApplyToDir = nullptr,
    1.61 +                                    ProcessType *pid = nullptr);
    1.62 +
    1.63 +#ifdef MOZ_UPDATER
    1.64 +// The implementation of the update processor handles the task of loading the
    1.65 +// updater application for staging an update.
    1.66 +// XXX ehsan this is living in this file in order to make use of the existing
    1.67 +// stuff here, we might want to move it elsewhere in the future.
    1.68 +class nsUpdateProcessor MOZ_FINAL : public nsIUpdateProcessor
    1.69 +{
    1.70 +public:
    1.71 +  nsUpdateProcessor();
    1.72 +
    1.73 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.74 +  NS_DECL_NSIUPDATEPROCESSOR
    1.75 +
    1.76 +private:
    1.77 +  struct StagedUpdateInfo {
    1.78 +    StagedUpdateInfo()
    1.79 +      : mArgc(0),
    1.80 +        mArgv(nullptr),
    1.81 +        mIsOSUpdate(false)
    1.82 +    {}
    1.83 +    ~StagedUpdateInfo() {
    1.84 +      for (int i = 0; i < mArgc; ++i) {
    1.85 +        delete[] mArgv[i];
    1.86 +      }
    1.87 +      delete[] mArgv;
    1.88 +    }
    1.89 +
    1.90 +    nsCOMPtr<nsIFile> mGREDir;
    1.91 +    nsCOMPtr<nsIFile> mAppDir;
    1.92 +    nsCOMPtr<nsIFile> mUpdateRoot;
    1.93 +    nsCOMPtr<nsIFile> mOSApplyToDir;
    1.94 +    int mArgc;
    1.95 +    char **mArgv;
    1.96 +    nsAutoCString mAppVersion;
    1.97 +    bool mIsOSUpdate;
    1.98 +  };
    1.99 +
   1.100 +private:
   1.101 +  void StartStagedUpdate();
   1.102 +  void WaitForProcess();
   1.103 +  void UpdateDone();
   1.104 +  void ShutdownWatcherThread();
   1.105 +
   1.106 +private:
   1.107 +  ProcessType mUpdaterPID;
   1.108 +  nsCOMPtr<nsIThread> mProcessWatcher;
   1.109 +  nsCOMPtr<nsIUpdate> mUpdate;
   1.110 +  StagedUpdateInfo mInfo;
   1.111 +};
   1.112 +#endif
   1.113 +
   1.114 +#endif  // nsUpdateDriver_h__

mercurial