configurator.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_UPDATE_CLIENT_CONFIGURATOR_H_
  5. #define COMPONENTS_UPDATE_CLIENT_CONFIGURATOR_H_
  6. #include <memory>
  7. #include <string>
  8. #include <tuple>
  9. #include <vector>
  10. #include "base/callback_forward.h"
  11. #include "base/containers/flat_map.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. class GURL;
  15. class PrefService;
  16. namespace base {
  17. class Version;
  18. }
  19. namespace update_client {
  20. class ActivityDataService;
  21. class CrxDownloaderFactory;
  22. class NetworkFetcherFactory;
  23. class PatcherFactory;
  24. class ProtocolHandlerFactory;
  25. class UnzipperFactory;
  26. using UpdaterStateAttributes = base::flat_map<std::string, std::string>;
  27. using UpdaterStateProvider =
  28. base::RepeatingCallback<UpdaterStateAttributes(bool is_machine)>;
  29. // Controls the component updater behavior.
  30. // TODO(sorin): this class will be split soon in two. One class controls
  31. // the behavior of the update client, and the other class controls the
  32. // behavior of the component updater.
  33. class Configurator : public base::RefCountedThreadSafe<Configurator> {
  34. public:
  35. // Delay in seconds from calling Start() to the first update check.
  36. virtual double InitialDelay() const = 0;
  37. // Delay in seconds to every subsequent update check. 0 means don't check.
  38. virtual int NextCheckDelay() const = 0;
  39. // Minimum delta time in seconds before an on-demand check is allowed
  40. // for the same component.
  41. virtual int OnDemandDelay() const = 0;
  42. // The time delay in seconds between applying updates for different
  43. // components.
  44. virtual int UpdateDelay() const = 0;
  45. // The URLs for the update checks. The URLs are tried in order, the first one
  46. // that succeeds wins. Since some components cannot be updated over HTTP,
  47. // HTTPS URLs should appear first.
  48. virtual std::vector<GURL> UpdateUrl() const = 0;
  49. // The URLs for pings. Returns an empty vector if and only if pings are
  50. // disabled. Similarly, these URLs have a fall back behavior too.
  51. virtual std::vector<GURL> PingUrl() const = 0;
  52. // The ProdId is used as a prefix in some of the version strings which appear
  53. // in the protocol requests. Possible values include "chrome", "chromecrx",
  54. // "chromiumcrx", and "unknown".
  55. virtual std::string GetProdId() const = 0;
  56. // Version of the application. Used to compare the component manifests.
  57. virtual base::Version GetBrowserVersion() const = 0;
  58. // Returns the value we use for the "updaterchannel=" and "prodchannel="
  59. // parameters. Possible return values include: "canary", "dev", "beta", and
  60. // "stable".
  61. virtual std::string GetChannel() const = 0;
  62. // Returns the language for the present locale. Possible return values are
  63. // standard tags for languages, such as "en", "en-US", "de", "fr", "af", etc.
  64. virtual std::string GetLang() const = 0;
  65. // Returns the OS's long name like "Windows", "Mac OS X", etc.
  66. virtual std::string GetOSLongName() const = 0;
  67. // Parameters added to each url request. It can be empty if none are needed.
  68. // Returns a map of name-value pairs that match ^[-_a-zA-Z0-9]$ regex.
  69. virtual base::flat_map<std::string, std::string> ExtraRequestParams()
  70. const = 0;
  71. // Provides a hint for the server to control the order in which multiple
  72. // download urls are returned. The hint may or may not be honored in the
  73. // response returned by the server.
  74. // Returns an empty string if no policy is in effect.
  75. virtual std::string GetDownloadPreference() const = 0;
  76. virtual scoped_refptr<NetworkFetcherFactory> GetNetworkFetcherFactory() = 0;
  77. virtual scoped_refptr<CrxDownloaderFactory> GetCrxDownloaderFactory() = 0;
  78. virtual scoped_refptr<UnzipperFactory> GetUnzipperFactory() = 0;
  79. virtual scoped_refptr<PatcherFactory> GetPatcherFactory() = 0;
  80. // True means that this client can handle delta updates.
  81. virtual bool EnabledDeltas() const = 0;
  82. // True means that the background downloader can be used for downloading
  83. // non on-demand components.
  84. virtual bool EnabledBackgroundDownloader() const = 0;
  85. // True if signing of update checks is enabled.
  86. virtual bool EnabledCupSigning() const = 0;
  87. // Returns a PrefService that the update_client can use to store persistent
  88. // update information. The PrefService must outlive the entire update_client,
  89. // and be safe to access from the thread the update_client is constructed
  90. // on.
  91. // Returning null is safe and will disable any functionality that requires
  92. // persistent storage.
  93. virtual PrefService* GetPrefService() const = 0;
  94. // Returns an ActivityDataService that the update_client can use to access
  95. // to update information (namely active bit, last active/rollcall days)
  96. // normally stored in the user extension profile.
  97. // Similar to PrefService, ActivityDataService must outlive the entire
  98. // update_client, and be safe to access from the thread the update_client
  99. // is constructed on.
  100. // Returning null is safe and will disable any functionality that requires
  101. // accessing to the information provided by ActivityDataService.
  102. virtual ActivityDataService* GetActivityDataService() const = 0;
  103. // Returns true if the Chrome is installed for the current user only, or false
  104. // if Chrome is installed for all users on the machine. This function must be
  105. // called only from a blocking pool thread, as it may access the file system.
  106. virtual bool IsPerUserInstall() const = 0;
  107. // Returns the class factory to create protocol parser and protocol
  108. // serializer object instances.
  109. virtual std::unique_ptr<ProtocolHandlerFactory> GetProtocolHandlerFactory()
  110. const = 0;
  111. // Returns true if Chrome is installed on a system managed by cloud or
  112. // group policies, false if the system is not managed, or nullopt if the
  113. // platform does not support client management at all.
  114. virtual absl::optional<bool> IsMachineExternallyManaged() const = 0;
  115. // Returns a callable to get the state of the platform updater, if the
  116. // embedder includes an updater. Returns a null callback otherwise.
  117. virtual UpdaterStateProvider GetUpdaterStateProvider() const = 0;
  118. protected:
  119. friend class base::RefCountedThreadSafe<Configurator>;
  120. virtual ~Configurator() = default;
  121. };
  122. } // namespace update_client
  123. #endif // COMPONENTS_UPDATE_CLIENT_CONFIGURATOR_H_