auto_updater.h 2.2 KB

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