Bug 1841035 [wpt PR 40807] - LoAF: reduce memory usage, a=testonly
[gecko.git] / toolkit / xre / nsUpdateDriver.h
blob24a20f3f76d50fac618809e64be0a13734867a49
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__
10 #include "nscore.h"
11 #include "nsIUpdateService.h"
12 #include "nsIThread.h"
13 #include "nsCOMPtr.h"
14 #include "nsString.h"
15 #include "mozilla/Attributes.h"
17 class nsIFile;
19 #if defined(XP_WIN)
20 # include <windows.h>
21 # include "mozilla/WinHandleWatcher.h"
22 typedef HANDLE ProcessType;
23 #elif defined(XP_UNIX)
24 typedef pid_t ProcessType;
25 #else
26 # include "prproces.h"
27 typedef PRProcess* ProcessType;
28 #endif
30 #ifdef XP_WIN
31 # define UPDATER_BIN "updater.exe"
32 # define MAINTENANCE_SVC_NAME L"MozillaMaintenance"
33 #elif XP_MACOSX
34 # define UPDATER_APP "updater.app"
35 # define UPDATER_BIN "org.mozilla.updater"
36 #else
37 # define UPDATER_BIN "updater"
38 #endif
40 /**
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
56 * parameter to false.
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 {
69 public:
70 nsUpdateProcessor();
72 NS_DECL_THREADSAFE_ISUPPORTS
73 NS_DECL_NSIUPDATEPROCESSOR
75 private:
76 ~nsUpdateProcessor();
78 struct StagedUpdateInfo {
79 StagedUpdateInfo() : mArgc(0), mArgv(nullptr) {}
80 ~StagedUpdateInfo() {
81 for (int i = 0; i < mArgc; ++i) {
82 delete[] mArgv[i];
84 delete[] mArgv;
87 nsCOMPtr<nsIFile> mGREDir;
88 nsCOMPtr<nsIFile> mAppDir;
89 nsCOMPtr<nsIFile> mUpdateRoot;
90 int mArgc;
91 char** mArgv;
92 nsCString mAppVersion;
95 private:
96 void StartStagedUpdate();
97 void UpdateDone();
98 void ShutdownWorkerThread();
100 #ifndef XP_WIN
101 void WaitForProcess();
102 #endif
104 private:
105 ProcessType mUpdaterPID;
106 nsCOMPtr<nsIThread> mWorkerThread;
107 #ifdef XP_WIN
108 mozilla::HandleWatcher mProcessWatcher;
109 #endif
110 StagedUpdateInfo mInfo;
112 #endif // nsUpdateDriver_h__