Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

version_checker.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #ifndef VERSION_CHECKER_H
  2. #define VERSION_CHECKER_H
  3. #ifdef AUTO_UPDATE_SUPPORT
  4. #ifdef AUTOUPDATE_PACKAGE_INSTALLATION
  5. #include "adjunct/autoupdate/autoupdater.h"
  6. #include "adjunct/autoupdate/updatableresource.h"
  7. #include "adjunct/autoupdate/updater/audatafile_reader.h"
  8. #include "adjunct/desktop_util/version/operaversion.h"
  9. /**
  10. * Listener interface to be implemented by anyone using VersionChecker - the check is async and this way you will be notified back
  11. * when it finishes.
  12. */
  13. class VersionCheckerListener
  14. {
  15. public:
  16. virtual ~VersionCheckerListener() {}
  17. /**
  18. * Called when the version check is finished, succeeded or not. It's only after you receive this callback, that you can trust th
  19. * status read from the VersionChecker.
  20. */
  21. virtual void VersionCheckFinished() = 0;
  22. };
  23. /**
  24. * The VersionChecker is meant to be a small utility class that allows checking whether the Opera update package that has been downloaded and
  25. * is about to be installed is not too old.
  26. * This class uses the autoupdate server to check whether a newer Opera package is available. The check occurs if there is a downloaded package
  27. * waiting for installation and at the same time the modification time of the autoupdate.txt file included in that package is more than MaxDownloadedPackageAgeDays
  28. * days old.
  29. * This class is meant to be used during startup of the Opera and it is not probable that you will have the chance to utilize it somewhere else.
  30. */
  31. class VersionChecker:
  32. public StatusXMLDownloaderListener
  33. {
  34. public:
  35. enum VCStatus {
  36. /**
  37. * The object has not been initialized at all, i.e. Init() was not called.
  38. */
  39. VCSNotInitialized,
  40. /**
  41. * Something went wrong during the Init() call, the object can't be used.
  42. */
  43. VCSInitFailed,
  44. /**
  45. * Version check is not needed as the update file is not older than MaxDownloadedPackageAgeDays.
  46. */
  47. VCSCheckNotNeeded,
  48. /**
  49. * Version check is needed since the update file is too old, you need to call CheckRemoteVersion().
  50. */
  51. VCSCheckNotPerformed,
  52. /**
  53. * Version check is in progress, wait until you'll be notified via a VersionCheckerListener callback
  54. */
  55. VCSCheckInProgress,
  56. /**
  57. * Checking of update version failed for some reason, network or autoupdate server issue probably
  58. */
  59. VCSCheckVersionFailed,
  60. /**
  61. * The server didn't sent us any update in response to our check request.
  62. */
  63. VCSNoUpdateAvailable,
  64. /**
  65. * An update is available on the server. The update version is older than what we got.
  66. */
  67. VCSOlderUpdateAvailable,
  68. /**
  69. * An update is available on the server. The update version is newer than what we got.
  70. */
  71. VCSNewerUpdateAvailable,
  72. /**
  73. * An update is available on the server. The update version is the same as what we got.
  74. */
  75. VCSSameUpdateAvailable
  76. };
  77. VersionChecker();
  78. ~VersionChecker();
  79. /**
  80. * The VersionChecker object needs to be initialized before it can be used.
  81. *
  82. * @param listener - the VersionCheckerListener implementation that will be notified when the version check is over.
  83. *
  84. * @returns - OpStatus::OK if the object was initialized correctly, OpStatus::ERR otherwise.
  85. */
  86. OP_STATUS Init(VersionCheckerListener* listener);
  87. /**
  88. * Call this method to check whether a newer update than the one that is already downloaded is available on the server.
  89. * Note this method will fail if the check is not needed.
  90. * If this method returns OpStatus::OK, you should wait for the callback via the VersionCheckerListener interface
  91. * before proceeding further, this is due to the time needed to communicate with the autoupdate server.
  92. *
  93. * @returns - OpStatus::OK - communication with server in progress, wait for callback, OpStatus::ERR - check not needed
  94. * or starting the server communication failed, don't expect the callback and proceed now.
  95. */
  96. OP_STATUS CheckRemoteVersion();
  97. /**
  98. * Get the current status of the object, see the VCStatus enum for description.
  99. *
  100. * @returns - the current status of the object.
  101. */
  102. VCStatus GetStatus() const { return m_status; }
  103. /**
  104. * Implementation of StatusXMLDownloaderListener
  105. */
  106. void StatusXMLDownloaded(StatusXMLDownloader* downloader);
  107. void StatusXMLDownloadFailed(StatusXMLDownloader* downloader, StatusXMLDownloader::DownloadStatus);
  108. private:
  109. /* This is the number of days that we allow the downloaded update to be "fresh enough" to be installed.
  110. * In case that an update that we have stored on the disk was downloaded more than MaxDownloadedPackageAgeDays days ago,
  111. * we go and try to find a newer version with the autoupdate server before installing it.
  112. */
  113. static const unsigned int MaxDownloadedPackageAgeDays = 5;
  114. /**
  115. * Determine whether the update available on the disk is older than MaxDownloadedPackageAgeDays, in which case a check
  116. * with the autoupdate server is needed.
  117. *
  118. * @returns - true in case the update is too old, false is we can install it safely.
  119. */
  120. bool CheckIsNeeded();
  121. /**
  122. * Sets the m_downloaded_version with the version found in the update stored on the disk.
  123. *
  124. * @returns - OpStatus::OK in case everything went OK, ERR otherwise.
  125. */
  126. OP_STATUS ReadVersionOfExistingUpdate();
  127. /**
  128. * Checks the modification time of the autoupdate.txt file. This is considered the time that the update was downloaded at.
  129. *
  130. * @param result - a reference to a time_t variable that will receive the modification time in case this method succeeds.
  131. *
  132. * @returns - OpStatus::OK in case everything went OK, ERR otherwise.
  133. */
  134. OP_STATUS GetDataFileLastModificationTime(time_t& result);
  135. /**
  136. * The autoupdate.txt file reader helper.
  137. */
  138. AUDataFileReader m_data_file_reader;
  139. /**
  140. * This object will store the version of the update available on the disk, if any.
  141. * The information here is NOT valid if the object was not Init()ed, the Init() failed, or if the
  142. * current status is VCSCheckNotNeeded.
  143. */
  144. OperaVersion m_downloaded_version;
  145. /**
  146. * The current status of the object.
  147. */
  148. VCStatus m_status;
  149. /**
  150. * The autoupdate request XML construction helper.
  151. */
  152. AutoUpdateXML* m_autoupdate_xml;
  153. /**
  154. * The autoupdate XML communication helper.
  155. */
  156. StatusXMLDownloader* m_status_xml_downloader;
  157. /**
  158. * The listener that will be notified about the succesfull autoupdate version check.
  159. */
  160. VersionCheckerListener* m_listener;
  161. /**
  162. * Autoupdate server address helper.
  163. */
  164. AutoUpdateServerURL* m_autoupdate_server_url;
  165. };
  166. #endif // AUTOUPDATE_PACKAGE_INSTALLATION
  167. #endif // AUTO_UPDATE_SUPPORT
  168. #endif // VERSION_CHECKER_H