1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsUpdateDriver_h__
8 #define nsUpdateDriver_h__
11 #include "nsIUpdateService.h"
12 #include "nsIThread.h"
15 #include "mozilla/Attributes.h"
21 # include "mozilla/WinHandleWatcher.h"
22 typedef HANDLE ProcessType
;
23 #elif defined(XP_UNIX)
24 typedef pid_t ProcessType
;
26 # include "prproces.h"
27 typedef PRProcess
* ProcessType
;
31 # define UPDATER_BIN "updater.exe"
32 # define MAINTENANCE_SVC_NAME L"MozillaMaintenance"
34 # define UPDATER_APP "updater.app"
35 # define UPDATER_BIN "org.mozilla.updater"
37 # define UPDATER_BIN "updater"
41 * This function processes any available updates. As part of that process, it
42 * may exit the current process and relaunch it at a later time.
44 * Two directories are passed to this function: greDir (where the actual
45 * binary resides) and appDir (which contains application.ini for XULRunner
46 * apps). If this is not a XULRunner app then appDir is identical to greDir.
48 * The argc and argv passed to this function should be what is needed to
49 * relaunch the current process.
51 * The appVersion param passed to this function is the current application's
52 * version and is used to determine if an update's version is older than the
53 * current application version.
55 * If you want the update to be processed without restarting, set the restart
58 * This function does not modify appDir.
60 nsresult
ProcessUpdates(nsIFile
* greDir
, nsIFile
* appDir
, nsIFile
* updRootDir
,
61 int argc
, char** argv
, const char* appVersion
,
62 bool restart
= true, ProcessType
* pid
= nullptr);
64 // The implementation of the update processor handles the task of loading the
65 // updater application for staging an update.
66 // XXX ehsan this is living in this file in order to make use of the existing
67 // stuff here, we might want to move it elsewhere in the future.
68 class nsUpdateProcessor final
: public nsIUpdateProcessor
{
72 NS_DECL_THREADSAFE_ISUPPORTS
73 NS_DECL_NSIUPDATEPROCESSOR
78 struct StagedUpdateInfo
{
79 StagedUpdateInfo() : mArgc(0), mArgv(nullptr) {}
81 for (int i
= 0; i
< mArgc
; ++i
) {
87 nsCOMPtr
<nsIFile
> mGREDir
;
88 nsCOMPtr
<nsIFile
> mAppDir
;
89 nsCOMPtr
<nsIFile
> mUpdateRoot
;
92 nsCString mAppVersion
;
96 void StartStagedUpdate();
98 void ShutdownWorkerThread();
101 void WaitForProcess();
105 ProcessType mUpdaterPID
;
106 nsCOMPtr
<nsIThread
> mWorkerThread
;
108 mozilla::HandleWatcher mProcessWatcher
;
110 StagedUpdateInfo mInfo
;
112 #endif // nsUpdateDriver_h__