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"
33 # define MAYBE_WAIT_TIMEOUT_MS (60U * 1000U)
35 # define UPDATER_APP "updater.app"
36 # define UPDATER_BIN "org.mozilla.updater"
38 # define UPDATER_BIN "updater"
42 * This function processes any available updates. As part of that process, it
43 * may exit the current process and relaunch it at a later time.
45 * Two directories are passed to this function: greDir (where the actual
46 * binary resides) and appDir (which contains application.ini for XULRunner
47 * apps). If this is not a XULRunner app then appDir is identical to greDir.
49 * The argc and argv passed to this function should be what is needed to
50 * relaunch the current process.
52 * The appVersion param passed to this function is the current application's
53 * version and is used to determine if an update's version is older than the
54 * current application version.
56 * If you want the update to be processed without restarting, set the restart
59 * This function does not modify appDir.
61 nsresult
ProcessUpdates(nsIFile
* greDir
, nsIFile
* appDir
, nsIFile
* updRootDir
,
62 int argc
, char** argv
, const char* appVersion
,
63 bool restart
= true, ProcessType
* pid
= nullptr);
65 // The implementation of the update processor handles the task of loading the
66 // updater application for staging an update.
67 // XXX ehsan this is living in this file in order to make use of the existing
68 // stuff here, we might want to move it elsewhere in the future.
69 class nsUpdateProcessor final
: public nsIUpdateProcessor
{
73 NS_DECL_THREADSAFE_ISUPPORTS
74 NS_DECL_NSIUPDATEPROCESSOR
79 struct StagedUpdateInfo
{
80 StagedUpdateInfo() : mArgc(0), mArgv(nullptr) {}
82 for (int i
= 0; i
< mArgc
; ++i
) {
88 nsCOMPtr
<nsIFile
> mGREDir
;
89 nsCOMPtr
<nsIFile
> mAppDir
;
90 nsCOMPtr
<nsIFile
> mUpdateRoot
;
93 nsCString mAppVersion
;
97 void StartStagedUpdate();
99 void ShutdownWorkerThread();
102 void WaitForProcess();
106 ProcessType mUpdaterPID
;
107 nsCOMPtr
<nsIThread
> mWorkerThread
;
109 mozilla::HandleWatcher mProcessWatcher
;
111 StagedUpdateInfo mInfo
;
113 #endif // nsUpdateDriver_h__