2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsUpdateDriver_h__
|
|
|
|
#define nsUpdateDriver_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2012-05-22 07:50:04 -07:00
|
|
|
#ifdef MOZ_UPDATER
|
|
|
|
#include "nsIUpdateService.h"
|
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
2012-06-19 20:49:05 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-05-22 07:50:04 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIFile;
|
|
|
|
|
2012-05-22 07:50:04 -07:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
typedef HANDLE ProcessType;
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
typedef pid_t ProcessType;
|
|
|
|
#else
|
|
|
|
#include "prproces.h"
|
|
|
|
typedef PRProcess* ProcessType;
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* This function processes any available updates. As part of that process, it
|
|
|
|
* may exit the current process and relaunch it at a later time.
|
|
|
|
*
|
|
|
|
* Two directories are passed to this function: greDir (where the actual
|
|
|
|
* binary resides) and appDir (which contains application.ini for XULRunner
|
|
|
|
* apps). If this is not a XULRunner app then appDir is identical to greDir.
|
|
|
|
*
|
|
|
|
* The argc and argv passed to this function should be what is needed to
|
|
|
|
* relaunch the current process.
|
|
|
|
*
|
2008-11-14 04:11:08 -08:00
|
|
|
* The appVersion param passed to this function is the current application's
|
|
|
|
* version and is used to determine if an update's version is older than the
|
|
|
|
* current application version.
|
|
|
|
*
|
2012-05-22 07:50:04 -07:00
|
|
|
* If you want the update to be processed without restarting, set the restart
|
|
|
|
* parameter to false.
|
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* This function does not modify appDir.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(nsresult) ProcessUpdates(nsIFile *greDir, nsIFile *appDir,
|
|
|
|
nsIFile *updRootDir,
|
2008-11-14 04:11:08 -08:00
|
|
|
int argc, char **argv,
|
2012-05-22 07:50:04 -07:00
|
|
|
const char *appVersion,
|
|
|
|
bool restart = true,
|
2012-09-30 19:55:51 -07:00
|
|
|
bool isOSUpdate = false,
|
|
|
|
nsIFile *osApplyToDir = nullptr,
|
2012-07-30 07:20:58 -07:00
|
|
|
ProcessType *pid = nullptr);
|
2012-05-22 07:50:04 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_UPDATER
|
|
|
|
// The implementation of the update processor handles the task of loading the
|
|
|
|
// updater application in the background for applying an update.
|
|
|
|
// XXX ehsan this is living in this file in order to make use of the existing
|
|
|
|
// stuff here, we might want to move it elsewhere in the future.
|
2012-06-19 20:49:05 -07:00
|
|
|
class nsUpdateProcessor MOZ_FINAL : public nsIUpdateProcessor
|
2012-05-22 07:50:04 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsUpdateProcessor();
|
|
|
|
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-05-22 07:50:04 -07:00
|
|
|
NS_DECL_NSIUPDATEPROCESSOR
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct BackgroundUpdateInfo {
|
|
|
|
BackgroundUpdateInfo()
|
|
|
|
: mArgc(0),
|
2012-09-30 19:55:51 -07:00
|
|
|
mArgv(nullptr),
|
|
|
|
mIsOSUpdate(false)
|
2012-05-22 07:50:04 -07:00
|
|
|
{}
|
|
|
|
~BackgroundUpdateInfo() {
|
|
|
|
for (int i = 0; i < mArgc; ++i) {
|
|
|
|
delete[] mArgv[i];
|
|
|
|
}
|
|
|
|
delete[] mArgv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> mGREDir;
|
|
|
|
nsCOMPtr<nsIFile> mAppDir;
|
|
|
|
nsCOMPtr<nsIFile> mUpdateRoot;
|
2012-09-30 19:55:51 -07:00
|
|
|
nsCOMPtr<nsIFile> mOSApplyToDir;
|
2012-05-22 07:50:04 -07:00
|
|
|
int mArgc;
|
|
|
|
char **mArgv;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString mAppVersion;
|
2012-09-30 19:55:51 -07:00
|
|
|
bool mIsOSUpdate;
|
2012-05-22 07:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void StartBackgroundUpdate();
|
|
|
|
void WaitForProcess();
|
|
|
|
void UpdateDone();
|
|
|
|
void ShutdownWatcherThread();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcessType mUpdaterPID;
|
|
|
|
nsCOMPtr<nsIThread> mProcessWatcher;
|
|
|
|
nsCOMPtr<nsIUpdate> mUpdate;
|
|
|
|
BackgroundUpdateInfo mInfo;
|
|
|
|
};
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif // nsUpdateDriver_h__
|