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.

country_checker.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* -*- Mode: c++; tab-width: 4; c-basic-offset: 4 -*-
  2. *
  3. * Copyright (C) 1995-2011 Opera Software AS. All rights reserved.
  4. *
  5. * This file is part of the Opera web browser.
  6. * It may not be distributed under any circumstances.
  7. */
  8. #ifndef REGION_CHECKER_H
  9. #define REGION_CHECKER_H
  10. #ifdef AUTO_UPDATE_SUPPORT
  11. #include "adjunct/autoupdate/autoupdater.h"
  12. /**
  13. * Listener interface to be implemented by anyone using CountryChecker - the check is async and this way you will be notified back
  14. * when it finishes.
  15. */
  16. class CountryCheckerListener
  17. {
  18. public:
  19. virtual ~CountryCheckerListener() {}
  20. /**
  21. * Called when the country check is finished, succeeded or not.
  22. */
  23. virtual void CountryCheckFinished() = 0;
  24. };
  25. /**
  26. * Specialized request to the autoupdate server that retrieves country code based on computer's IP address.
  27. */
  28. class CountryChecker
  29. : public StatusXMLDownloaderListener
  30. , public OpTimerListener
  31. {
  32. public:
  33. enum RCStatus {
  34. /**
  35. * The object has not been initialized at all, i.e. Init() was not called.
  36. */
  37. NotInitialized,
  38. /**
  39. * Something went wrong during the Init() call, the object can't be used.
  40. */
  41. InitFailed,
  42. /**
  43. * The object has been initialized and can be used to perform the check.
  44. */
  45. CheckNotPerformed,
  46. /**
  47. * Country code check is in progress, wait until you'll be notified via a CountryCheckerListener callback.
  48. */
  49. CheckInProgress,
  50. /**
  51. * Country code check failed for some reason, network or autoupdate server issue probably.
  52. */
  53. CheckFailed,
  54. /**
  55. * Country code check was cancelled after time out.
  56. */
  57. CheckTimedOut,
  58. /**
  59. * Country code check finished without errors and Opera received nonempty country code.
  60. */
  61. CheckSucceded
  62. };
  63. CountryChecker();
  64. ~CountryChecker();
  65. /**
  66. * The CountryChecker object needs to be initialized before it can be used.
  67. *
  68. * @param listener - listener that will be notified when the country code check is over (may be NULL).
  69. *
  70. * @returns - OpStatus::OK if the object was initialized correctly, OpStatus::ERR otherwise.
  71. */
  72. OP_STATUS Init(CountryCheckerListener* listener);
  73. /**
  74. * Call this method to send country code request to the autoupdate server.
  75. * If this method returns OpStatus::OK, you should wait for the callback via the CountryCheckerListener interface
  76. * before proceeding further, this is due to the time needed to communicate with the autoupdate server.
  77. *
  78. * @param timeout timeout for the request in ms (0 means no timeout)
  79. *
  80. * @returns - OpStatus::OK - communication with server in progress, wait for callback,
  81. * OpStatus::ERR - starting the server communication failed, don't expect the callback and proceed now.
  82. */
  83. OP_STATUS CheckCountryCode(UINT32 timeout);
  84. /**
  85. * Get the current status of the object, see the Status enum for description.
  86. *
  87. * @returns - the current status of the object.
  88. */
  89. RCStatus GetStatus() const { return m_status; }
  90. /**
  91. * Get country code received from the autoupdate server.
  92. * If GetStatus returns CheckSucceeded then string returned by this function is not empty.
  93. *
  94. * @returns - country code received from the autoupdate server
  95. */
  96. OpStringC GetCountryCode() { return m_country_code; }
  97. /**
  98. * Implementation of StatusXMLDownloaderListener
  99. */
  100. void StatusXMLDownloaded(StatusXMLDownloader* downloader);
  101. void StatusXMLDownloadFailed(StatusXMLDownloader* downloader, StatusXMLDownloader::DownloadStatus);
  102. /**
  103. * Implementation of OpTimerListener
  104. */
  105. void OnTimeOut(OpTimer* timer);
  106. private:
  107. /**
  108. * Get address of server to be used for country check.
  109. *
  110. * @param address gets address of the server
  111. *
  112. * @return OpStatus::OK on success, OpStatus::ERR_NO_MEMORY on OOM, OpStatus::ERR if address is unknown.
  113. */
  114. OP_STATUS GetServerAddress(OpString& address);
  115. /**
  116. * The current status of the object.
  117. */
  118. RCStatus m_status;
  119. /**
  120. * The autoupdate request XML construction helper.
  121. */
  122. AutoUpdateXML* m_autoupdate_xml;
  123. /**
  124. * The autoupdate XML communication helper.
  125. */
  126. StatusXMLDownloader* m_status_xml_downloader;
  127. /**
  128. * The listener that will be notified about the succesfull region check.
  129. */
  130. CountryCheckerListener* m_listener;
  131. /**
  132. * Autoupdate server address helper.
  133. */
  134. AutoUpdateServerURL* m_autoupdate_server_url;
  135. /**
  136. * Country code received from the autoupdate server.
  137. */
  138. OpString m_country_code;
  139. /**
  140. * Aborts country check if it times out.
  141. */
  142. OpTimer m_timer;
  143. };
  144. #endif // AUTO_UPDATE_SUPPORT
  145. #endif // REGION_CHECKER_H