aggregation_service_tool.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2021 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 TOOLS_AGGREGATION_SERVICE_AGGREGATION_SERVICE_TOOL_H_
  5. #define TOOLS_AGGREGATION_SERVICE_AGGREGATION_SERVICE_TOOL_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/strings/string_split.h"
  10. #include "base/values.h"
  11. #include "tools/aggregation_service/aggregation_service_tool_network_initializer.h"
  12. #include "url/gurl.h"
  13. namespace base {
  14. class FilePath;
  15. } // namespace base
  16. namespace content {
  17. class TestAggregationService;
  18. } // namespace content
  19. namespace url {
  20. class Origin;
  21. } // namespace url
  22. namespace aggregation_service {
  23. struct UrlKeyFile {
  24. UrlKeyFile(GURL url, std::string key_file);
  25. UrlKeyFile(const UrlKeyFile& other);
  26. UrlKeyFile& operator=(const UrlKeyFile& other);
  27. ~UrlKeyFile();
  28. GURL url;
  29. std::string key_file;
  30. };
  31. // This class is a wrapper for aggregation service tool.
  32. class AggregationServiceTool {
  33. public:
  34. AggregationServiceTool();
  35. ~AggregationServiceTool();
  36. // Sets whether to disable the AggregatableReport's payload(s) being encrypted
  37. // after serialization.
  38. void SetDisablePayloadEncryption(bool should_disable);
  39. // Sets public keys to storage from the url-filename pairs and returns
  40. // whether it's successful.
  41. bool SetPublicKeys(const std::vector<UrlKeyFile>& key_files);
  42. // Construct an aggregatable report from the specified information and returns
  43. // a `base::Value::Dict` for its JSON representation. Empty
  44. // `base::Value::Dict` will be returned in case of error.
  45. base::Value::Dict AssembleReport(std::string operation_str,
  46. std::string bucket_str,
  47. std::string value_str,
  48. std::string aggregation_mode_str,
  49. url::Origin reporting_origin,
  50. std::vector<GURL> processing_urls,
  51. bool is_debug_mode_enabled,
  52. base::Value::Dict additional_fields,
  53. std::string api_version,
  54. std::string api_identifier);
  55. // Sends the contents of the aggregatable report to the specified reporting
  56. // url `url` and returns whether it's successful.
  57. bool SendReport(const base::Value& contents, const GURL& url);
  58. // Writes the contents of the aggregatable report to the specified file
  59. // `filename` and returns whether it's successful.
  60. bool WriteReportToFile(const base::Value& contents,
  61. const base::FilePath& filename);
  62. private:
  63. bool SetPublicKeysFromFile(const GURL& url,
  64. const std::string& json_file_path);
  65. ToolNetworkInitializer network_initializer_;
  66. std::unique_ptr<content::TestAggregationService> agg_service_;
  67. };
  68. } // namespace aggregation_service
  69. #endif // TOOLS_AGGREGATION_SERVICE_AGGREGATION_SERVICE_TOOL_H_