nsUpdateDriver.h 3.2 KB

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