auto_updater.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_AUTO_UPDATER_H_
  5. #define ELECTRON_SHELL_BROWSER_AUTO_UPDATER_H_
  6. #include <map>
  7. #include <string>
  8. #include "build/build_config.h"
  9. namespace base {
  10. class Time;
  11. }
  12. namespace gin {
  13. class Arguments;
  14. }
  15. namespace auto_updater {
  16. class Delegate {
  17. public:
  18. // An error happened.
  19. virtual void OnError(const std::string& message) {}
  20. virtual void OnError(const std::string& message,
  21. const int code,
  22. const std::string& domain) {}
  23. // Checking to see if there is an update
  24. virtual void OnCheckingForUpdate() {}
  25. // There is an update available and it is being downloaded
  26. virtual void OnUpdateAvailable() {}
  27. // There is no available update.
  28. virtual void OnUpdateNotAvailable() {}
  29. // There is a new update which has been downloaded.
  30. virtual void OnUpdateDownloaded(const std::string& release_notes,
  31. const std::string& release_name,
  32. const base::Time& release_date,
  33. const std::string& update_url) {}
  34. protected:
  35. virtual ~Delegate() {}
  36. };
  37. class AutoUpdater {
  38. public:
  39. typedef std::map<std::string, std::string> HeaderMap;
  40. AutoUpdater() = delete;
  41. // disable copy
  42. AutoUpdater(const AutoUpdater&) = delete;
  43. AutoUpdater& operator=(const AutoUpdater&) = delete;
  44. // Gets/Sets the delegate.
  45. static Delegate* GetDelegate();
  46. static void SetDelegate(Delegate* delegate);
  47. static std::string GetFeedURL();
  48. // FIXME(zcbenz): We should not do V8 in this file, this method should only
  49. // accept C++ struct as parameter, and atom_api_auto_updater.cc is responsible
  50. // for parsing the parameter from JavaScript.
  51. static void SetFeedURL(gin::Arguments* args);
  52. static void CheckForUpdates();
  53. static void QuitAndInstall();
  54. static bool IsVersionAllowedForUpdate(const std::string& current_version,
  55. const std::string& target_version);
  56. private:
  57. static Delegate* delegate_;
  58. };
  59. } // namespace auto_updater
  60. #endif // ELECTRON_SHELL_BROWSER_AUTO_UPDATER_H_