michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsUpdateDriver_h__ michael@0: #define nsUpdateDriver_h__ michael@0: michael@0: #include "nscore.h" michael@0: #ifdef MOZ_UPDATER michael@0: #include "nsIUpdateService.h" michael@0: #include "nsIThread.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: #include "mozilla/Attributes.h" michael@0: #endif michael@0: michael@0: class nsIFile; michael@0: michael@0: #if defined(XP_WIN) michael@0: #include michael@0: typedef HANDLE ProcessType; michael@0: #elif defined(XP_MACOSX) michael@0: typedef pid_t ProcessType; michael@0: #else michael@0: #include "prproces.h" michael@0: typedef PRProcess* ProcessType; michael@0: #endif michael@0: michael@0: /** michael@0: * This function processes any available updates. As part of that process, it michael@0: * may exit the current process and relaunch it at a later time. michael@0: * michael@0: * Two directories are passed to this function: greDir (where the actual michael@0: * binary resides) and appDir (which contains application.ini for XULRunner michael@0: * apps). If this is not a XULRunner app then appDir is identical to greDir. michael@0: * michael@0: * The argc and argv passed to this function should be what is needed to michael@0: * relaunch the current process. michael@0: * michael@0: * The appVersion param passed to this function is the current application's michael@0: * version and is used to determine if an update's version is older than the michael@0: * current application version. michael@0: * michael@0: * If you want the update to be processed without restarting, set the restart michael@0: * parameter to false. michael@0: * michael@0: * This function does not modify appDir. michael@0: */ michael@0: NS_HIDDEN_(nsresult) ProcessUpdates(nsIFile *greDir, nsIFile *appDir, michael@0: nsIFile *updRootDir, michael@0: int argc, char **argv, michael@0: const char *appVersion, michael@0: bool restart = true, michael@0: bool isOSUpdate = false, michael@0: nsIFile *osApplyToDir = nullptr, michael@0: ProcessType *pid = nullptr); michael@0: michael@0: #ifdef MOZ_UPDATER michael@0: // The implementation of the update processor handles the task of loading the michael@0: // updater application for staging an update. michael@0: // XXX ehsan this is living in this file in order to make use of the existing michael@0: // stuff here, we might want to move it elsewhere in the future. michael@0: class nsUpdateProcessor MOZ_FINAL : public nsIUpdateProcessor michael@0: { michael@0: public: michael@0: nsUpdateProcessor(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIUPDATEPROCESSOR michael@0: michael@0: private: michael@0: struct StagedUpdateInfo { michael@0: StagedUpdateInfo() michael@0: : mArgc(0), michael@0: mArgv(nullptr), michael@0: mIsOSUpdate(false) michael@0: {} michael@0: ~StagedUpdateInfo() { michael@0: for (int i = 0; i < mArgc; ++i) { michael@0: delete[] mArgv[i]; michael@0: } michael@0: delete[] mArgv; michael@0: } michael@0: michael@0: nsCOMPtr mGREDir; michael@0: nsCOMPtr mAppDir; michael@0: nsCOMPtr mUpdateRoot; michael@0: nsCOMPtr mOSApplyToDir; michael@0: int mArgc; michael@0: char **mArgv; michael@0: nsAutoCString mAppVersion; michael@0: bool mIsOSUpdate; michael@0: }; michael@0: michael@0: private: michael@0: void StartStagedUpdate(); michael@0: void WaitForProcess(); michael@0: void UpdateDone(); michael@0: void ShutdownWatcherThread(); michael@0: michael@0: private: michael@0: ProcessType mUpdaterPID; michael@0: nsCOMPtr mProcessWatcher; michael@0: nsCOMPtr mUpdate; michael@0: StagedUpdateInfo mInfo; michael@0: }; michael@0: #endif michael@0: michael@0: #endif // nsUpdateDriver_h__