Bug 1888033 - [Menu Redesign] Add a secret setting and feature flag for the menu...
[gecko.git] / toolkit / xre / nsUpdateDriver.h
blobdea98780465fdae1d97f06ea0fbf4fbf10285375
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 # define MAYBE_WAIT_TIMEOUT_MS (60U * 1000U)
34 #elif XP_MACOSX
35 # define UPDATER_APP "updater.app"
36 # define UPDATER_BIN "org.mozilla.updater"
37 #else
38 # define UPDATER_BIN "updater"
39 #endif
41 /**
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
57 * parameter to false.
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 {
70 public:
71 nsUpdateProcessor();
73 NS_DECL_THREADSAFE_ISUPPORTS
74 NS_DECL_NSIUPDATEPROCESSOR
76 private:
77 ~nsUpdateProcessor();
79 struct StagedUpdateInfo {
80 StagedUpdateInfo() : mArgc(0), mArgv(nullptr) {}
81 ~StagedUpdateInfo() {
82 for (int i = 0; i < mArgc; ++i) {
83 delete[] mArgv[i];
85 delete[] mArgv;
88 nsCOMPtr<nsIFile> mGREDir;
89 nsCOMPtr<nsIFile> mAppDir;
90 nsCOMPtr<nsIFile> mUpdateRoot;
91 int mArgc;
92 char** mArgv;
93 nsCString mAppVersion;
96 private:
97 void StartStagedUpdate();
98 void UpdateDone();
99 void ShutdownWorkerThread();
101 #ifndef XP_WIN
102 void WaitForProcess();
103 #endif
105 private:
106 ProcessType mUpdaterPID;
107 nsCOMPtr<nsIThread> mWorkerThread;
108 #ifdef XP_WIN
109 mozilla::HandleWatcher mProcessWatcher;
110 #endif
111 StagedUpdateInfo mInfo;
113 #endif // nsUpdateDriver_h__