protocol_definition.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Copyright (c) 2018 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_PROTOCOL_DEFINITION_H_
  5. #define COMPONENTS_UPDATE_CLIENT_PROTOCOL_DEFINITION_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/containers/flat_map.h"
  10. #include "base/values.h"
  11. #include "build/build_config.h"
  12. #include "components/update_client/activity_data_service.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. namespace update_client {
  15. // The protocol versions so far are:
  16. // * Version 3.1: it changes how the run actions are serialized.
  17. // * Version 3.0: it is the version implemented by the desktop updaters.
  18. constexpr char kProtocolVersion[] = "3.1";
  19. // Due to implementation constraints of the JSON parser and serializer,
  20. // precision of integer numbers greater than 2^53 is lost.
  21. constexpr int64_t kProtocolMaxInt = 1LL << 53;
  22. namespace protocol_request {
  23. struct HW {
  24. uint32_t physmemory = 0; // Physical memory rounded down to the closest GB.
  25. bool sse = false;
  26. bool sse2 = false;
  27. bool sse3 = false;
  28. bool sse41 = false;
  29. bool sse42 = false;
  30. bool ssse3 = false;
  31. bool avx = false;
  32. };
  33. struct OS {
  34. OS();
  35. OS(const OS&) = delete;
  36. OS& operator=(const OS&) = delete;
  37. OS(OS&&);
  38. OS& operator=(OS&&);
  39. ~OS();
  40. std::string platform;
  41. std::string version;
  42. std::string service_pack;
  43. std::string arch;
  44. };
  45. struct Updater {
  46. Updater();
  47. Updater(const Updater&);
  48. ~Updater();
  49. std::string name;
  50. std::string version;
  51. bool is_machine = false;
  52. bool autoupdate_check_enabled = false;
  53. absl::optional<int> last_started;
  54. absl::optional<int> last_checked;
  55. int update_policy = 0;
  56. };
  57. struct UpdateCheck {
  58. UpdateCheck();
  59. ~UpdateCheck();
  60. bool is_update_disabled = false;
  61. std::string target_version_prefix;
  62. bool rollback_allowed = false;
  63. bool same_version_update_allowed = false;
  64. };
  65. // `data` element.
  66. struct Data {
  67. Data();
  68. Data(const Data& other);
  69. Data& operator=(const Data& other);
  70. Data(const std::string& name,
  71. const std::string& install_data_index,
  72. const std::string& untrusted_data);
  73. ~Data();
  74. // `name` can be either "install" or "untrusted", corresponding to
  75. // `install_data_index` and `untrusted_data`.
  76. std::string name;
  77. std::string install_data_index;
  78. std::string untrusted_data;
  79. };
  80. // didrun element. The element is named "ping" for legacy reasons.
  81. struct Ping {
  82. Ping();
  83. Ping(const Ping&);
  84. ~Ping();
  85. // Preferred user count metrics ("ad" and "rd").
  86. absl::optional<int> date_last_active;
  87. absl::optional<int> date_last_roll_call;
  88. // Legacy user count metrics ("a" and "r").
  89. absl::optional<int> days_since_last_active_ping;
  90. int days_since_last_roll_call = 0;
  91. std::string ping_freshness;
  92. };
  93. struct App {
  94. App();
  95. App(const App&) = delete;
  96. App& operator=(const App&) = delete;
  97. App(App&&);
  98. App& operator=(App&&);
  99. ~App();
  100. std::string app_id;
  101. std::string version;
  102. std::string ap;
  103. base::flat_map<std::string, std::string> installer_attributes;
  104. std::string lang;
  105. std::string brand_code;
  106. int install_date = kDateUnknown;
  107. std::string install_source;
  108. std::string install_location;
  109. std::string fingerprint;
  110. std::string cohort; // Opaque string.
  111. std::string cohort_hint; // Server may use to move the app to a new cohort.
  112. std::string cohort_name; // Human-readable interpretation of the cohort.
  113. std::string release_channel;
  114. absl::optional<bool> enabled;
  115. absl::optional<std::vector<int>> disabled_reasons;
  116. // Optional update check.
  117. absl::optional<UpdateCheck> update_check;
  118. // Optional `data` elements.
  119. std::vector<Data> data;
  120. // Optional 'did run' ping.
  121. absl::optional<Ping> ping;
  122. // Progress/result pings.
  123. absl::optional<std::vector<base::Value>> events;
  124. };
  125. struct Request {
  126. Request();
  127. Request(const Request&) = delete;
  128. Request& operator=(const Request&) = delete;
  129. Request(Request&&);
  130. Request& operator=(Request&&);
  131. ~Request();
  132. std::string protocol_version;
  133. // True if the updater operates in the per-system configuration.
  134. bool is_machine = false;
  135. // Unique identifier for this session, used to correlate multiple requests
  136. // associated with a single update operation.
  137. std::string session_id;
  138. // Unique identifier for this request, used to associate the same request
  139. // received multiple times on the server.
  140. std::string request_id;
  141. std::string updatername;
  142. std::string updaterversion;
  143. std::string prodversion;
  144. std::string updaterchannel;
  145. std::string prodchannel;
  146. std::string operating_system;
  147. std::string arch;
  148. std::string nacl_arch;
  149. #if BUILDFLAG(IS_WIN)
  150. bool is_wow64 = false;
  151. #endif
  152. // Provides a hint for what download urls should be returned by server.
  153. // This data member is controlled by group policy settings.
  154. // The only group policy value supported so far is |cacheable|.
  155. std::string dlpref;
  156. // True if this machine is part of a managed enterprise domain.
  157. absl::optional<bool> domain_joined;
  158. base::flat_map<std::string, std::string> additional_attributes;
  159. HW hw;
  160. OS os;
  161. absl::optional<Updater> updater;
  162. std::vector<App> apps;
  163. };
  164. } // namespace protocol_request
  165. } // namespace update_client
  166. #endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_DEFINITION_H_