Bumping manifests a=b2g-bump
[gecko.git] / toolkit / xre / nsUpdateDriver.h
blob4ae28aa736900c451c8f707912dc198af234a671
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 #ifdef MOZ_UPDATER
12 #include "nsIUpdateService.h"
13 #include "nsIThread.h"
14 #include "nsCOMPtr.h"
15 #include "nsString.h"
16 #include "mozilla/Attributes.h"
17 #endif
19 class nsIFile;
21 #if defined(XP_WIN)
22 #include <windows.h>
23 typedef HANDLE ProcessType;
24 #elif defined(XP_MACOSX)
25 typedef pid_t ProcessType;
26 #else
27 #include "prproces.h"
28 typedef PRProcess* ProcessType;
29 #endif
31 /**
32 * This function processes any available updates. As part of that process, it
33 * may exit the current process and relaunch it at a later time.
35 * Two directories are passed to this function: greDir (where the actual
36 * binary resides) and appDir (which contains application.ini for XULRunner
37 * apps). If this is not a XULRunner app then appDir is identical to greDir.
39 * The argc and argv passed to this function should be what is needed to
40 * relaunch the current process.
42 * The appVersion param passed to this function is the current application's
43 * version and is used to determine if an update's version is older than the
44 * current application version.
46 * If you want the update to be processed without restarting, set the restart
47 * parameter to false.
49 * This function does not modify appDir.
51 nsresult ProcessUpdates(nsIFile *greDir, nsIFile *appDir,
52 nsIFile *updRootDir,
53 int argc, char **argv,
54 const char *appVersion,
55 bool restart = true,
56 bool isOSUpdate = false,
57 nsIFile *osApplyToDir = nullptr,
58 ProcessType *pid = nullptr);
60 #ifdef MOZ_UPDATER
61 // The implementation of the update processor handles the task of loading the
62 // updater application for staging an update.
63 // XXX ehsan this is living in this file in order to make use of the existing
64 // stuff here, we might want to move it elsewhere in the future.
65 class nsUpdateProcessor MOZ_FINAL : public nsIUpdateProcessor
67 public:
68 nsUpdateProcessor();
70 NS_DECL_THREADSAFE_ISUPPORTS
71 NS_DECL_NSIUPDATEPROCESSOR
73 private:
74 ~nsUpdateProcessor();
76 struct StagedUpdateInfo {
77 StagedUpdateInfo()
78 : mArgc(0),
79 mArgv(nullptr),
80 mIsOSUpdate(false)
82 ~StagedUpdateInfo() {
83 for (int i = 0; i < mArgc; ++i) {
84 delete[] mArgv[i];
86 delete[] mArgv;
89 nsCOMPtr<nsIFile> mGREDir;
90 nsCOMPtr<nsIFile> mAppDir;
91 nsCOMPtr<nsIFile> mUpdateRoot;
92 nsCOMPtr<nsIFile> mOSApplyToDir;
93 int mArgc;
94 char **mArgv;
95 nsAutoCString mAppVersion;
96 bool mIsOSUpdate;
99 private:
100 void StartStagedUpdate();
101 void WaitForProcess();
102 void UpdateDone();
103 void ShutdownWatcherThread();
105 private:
106 ProcessType mUpdaterPID;
107 nsCOMPtr<nsIThread> mProcessWatcher;
108 nsCOMPtr<nsIUpdate> mUpdate;
109 StagedUpdateInfo mInfo;
111 #endif
113 #endif // nsUpdateDriver_h__