protocol_serializer.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 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_SERIALIZER_H_
  5. #define COMPONENTS_UPDATE_CLIENT_PROTOCOL_SERIALIZER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/containers/flat_map.h"
  11. #include "base/memory/ref_counted.h"
  12. #include "components/update_client/protocol_definition.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. namespace base {
  15. class Value;
  16. class Version;
  17. }
  18. namespace update_client {
  19. class PersistedData;
  20. // Creates the values for the DDOS extra request headers sent with the update
  21. // check. These headers include "X-Goog-Update-Updater",
  22. // "X-Goog-Update-AppId", and "X-Goog-Update-Interactivity".
  23. base::flat_map<std::string, std::string> BuildUpdateCheckExtraRequestHeaders(
  24. const std::string& prod_id,
  25. const base::Version& browser_version,
  26. const std::vector<std::string>& ids_checked,
  27. bool is_foreground);
  28. protocol_request::Request MakeProtocolRequest(
  29. bool is_machine,
  30. const std::string& session_id,
  31. const std::string& prod_id,
  32. const std::string& browser_version,
  33. const std::string& channel,
  34. const std::string& os_long_name,
  35. const std::string& download_preference,
  36. absl::optional<bool> domain_joined,
  37. const base::flat_map<std::string, std::string>& additional_attributes,
  38. const base::flat_map<std::string, std::string>& updater_state_attributes,
  39. std::vector<protocol_request::App> apps);
  40. protocol_request::App MakeProtocolApp(
  41. const std::string& app_id,
  42. const base::Version& version,
  43. const std::string& ap,
  44. const std::string& brand_code,
  45. const std::string& lang,
  46. int install_date,
  47. const std::string& install_source,
  48. const std::string& install_location,
  49. const std::string& fingerprint,
  50. const std::map<std::string, std::string>& installer_attributes,
  51. const std::string& cohort,
  52. const std::string& cohort_hint,
  53. const std::string& cohort_name,
  54. const std::string& release_channel,
  55. const std::vector<int>& disabled_reasons,
  56. absl::optional<protocol_request::UpdateCheck> update_check,
  57. const std::vector<protocol_request::Data>& data,
  58. absl::optional<protocol_request::Ping> ping,
  59. absl::optional<std::vector<base::Value>> events);
  60. protocol_request::UpdateCheck MakeProtocolUpdateCheck(
  61. bool is_update_disabled,
  62. const std::string& target_version_prefix,
  63. bool rollback_allowed,
  64. bool same_version_update_allowed);
  65. protocol_request::Ping MakeProtocolPing(const std::string& app_id,
  66. const PersistedData* metadata,
  67. bool active);
  68. class ProtocolSerializer {
  69. public:
  70. virtual ~ProtocolSerializer() = default;
  71. virtual std::string Serialize(
  72. const protocol_request::Request& request) const = 0;
  73. protected:
  74. ProtocolSerializer() = default;
  75. };
  76. } // namespace update_client
  77. #endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_SERIALIZER_H_