report_queue_configuration.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2020 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_REPORTING_CLIENT_REPORT_QUEUE_CONFIGURATION_H_
  5. #define COMPONENTS_REPORTING_CLIENT_REPORT_QUEUE_CONFIGURATION_H_
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include "base/callback.h"
  10. #include "components/reporting/proto/synced/record_constants.pb.h"
  11. #include "components/reporting/util/status.h"
  12. #include "components/reporting/util/statusor.h"
  13. namespace reporting {
  14. // |EventType| enum is used to distinguish between user and device event types,
  15. // and inherently determine the type of DM tokens (user vs device) generated.
  16. enum class EventType { kDevice, kUser };
  17. // ReportQueueConfiguration configures a report queue.
  18. // |dm_token| if set will be attached to all records generated with this queue.
  19. // Pass user DM tokens where applicable so the server can associate these events
  20. // with the user. |event_type| describes the event type being reported and is
  21. // indirectly used to retrieve DM tokens for downstream processing. Please use
  22. // |EventType::kUser| for events that need to be associated with the current
  23. // user. |destination| indicates what server side handler will be handling the
  24. // records that are generated by the ReportQueueImpl. |policy_check_callback_|
  25. // is a RepeatingCallback that verifies the specific report queue is allowed.
  26. class ReportQueueConfiguration {
  27. public:
  28. // PolicyCheckCallbacks should return error::UNAUTHENTICATED if a policy check
  29. // fails due to policies. Any other error as appropriate, and OK if a policy
  30. // check is successful.
  31. using PolicyCheckCallback = base::RepeatingCallback<Status(void)>;
  32. ~ReportQueueConfiguration();
  33. ReportQueueConfiguration(const ReportQueueConfiguration& other) = delete;
  34. ReportQueueConfiguration& operator=(const ReportQueueConfiguration& other) =
  35. delete;
  36. // Deprecated and should not be used.
  37. //
  38. // Factory for generating a ReportQueueConfiguration.
  39. // If any of the parameters are invalid, will return error::INVALID_ARGUMENT.
  40. // |dm_token| is valid when dm_token.is_valid() is true.
  41. // |destination| is valid when it is any value other than
  42. // Destination::UNDEFINED_DESTINATION.
  43. static StatusOr<std::unique_ptr<ReportQueueConfiguration>> Create(
  44. base::StringPiece dm_token,
  45. Destination destination,
  46. PolicyCheckCallback policy_check_callback);
  47. // Factory for generating a ReportQueueConfiguration.
  48. // |event_type| is the type of event being reported, and is indirectly used to
  49. // retrieve DM tokens for downstream processing when building the report
  50. // queue. Using |EventType::kDevice| will skip DM token retrieval, so please
  51. // use |EventType::kUser| for events that need to be associated with the
  52. // current user. If any of the parameters are invalid, will return
  53. // error::INVALID_ARGUMENT. |destination| is valid when it is any value other
  54. // than Destination::UNDEFINED_DESTINATION.
  55. static StatusOr<std::unique_ptr<ReportQueueConfiguration>> Create(
  56. EventType event_type,
  57. Destination destination,
  58. PolicyCheckCallback policy_check_callback);
  59. Destination destination() const { return destination_; }
  60. std::string dm_token() { return dm_token_; }
  61. EventType event_type() const { return event_type_; }
  62. Status SetDMToken(base::StringPiece dm_token);
  63. Status CheckPolicy() const;
  64. private:
  65. ReportQueueConfiguration();
  66. Status SetEventType(EventType event_type);
  67. Status SetDestination(Destination destination);
  68. Status SetPolicyCheckCallback(PolicyCheckCallback policy_check_callback);
  69. std::string dm_token_;
  70. EventType event_type_;
  71. Destination destination_;
  72. PolicyCheckCallback policy_check_callback_;
  73. };
  74. } // namespace reporting
  75. #endif // COMPONENTS_REPORTING_CLIENT_REPORT_QUEUE_CONFIGURATION_H_