app_package_name_logging_rule.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 ANDROID_WEBVIEW_COMMON_METRICS_APP_PACKAGE_NAME_LOGGING_RULE_H_
  5. #define ANDROID_WEBVIEW_COMMON_METRICS_APP_PACKAGE_NAME_LOGGING_RULE_H_
  6. #include "base/time/time.h"
  7. #include "base/values.h"
  8. #include "base/version.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace android_webview {
  11. // A class to hold the state of whether an app package name should be recorded
  12. // in UMA metrics log or not. This represent the result of looking the app
  13. // package name in a list of allowed apps.
  14. class AppPackageNameLoggingRule {
  15. public:
  16. AppPackageNameLoggingRule(const base::Version& version,
  17. const base::Time& expiry_date);
  18. ~AppPackageNameLoggingRule() = default;
  19. AppPackageNameLoggingRule(const AppPackageNameLoggingRule&) = default;
  20. AppPackageNameLoggingRule& operator=(const AppPackageNameLoggingRule&) =
  21. default;
  22. AppPackageNameLoggingRule(AppPackageNameLoggingRule&&) = default;
  23. AppPackageNameLoggingRule& operator=(AppPackageNameLoggingRule&&) = default;
  24. base::Version GetVersion() const;
  25. base::Time GetExpiryDate() const;
  26. // Return `true` is the app is in the allowlist and the result hasn't expired,
  27. // `false` otherwise.
  28. bool IsAppPackageNameAllowed() const;
  29. // If it has the same version and expiry_date as `record`.
  30. bool IsSameAs(const AppPackageNameLoggingRule& record) const;
  31. base::Value ToDictionary();
  32. // Creates a valid AppPackageNameLoggingRule from a dictionary, or null if
  33. // the dictionary have invalid values.
  34. static absl::optional<AppPackageNameLoggingRule> FromDictionary(
  35. const base::Value& dict);
  36. private:
  37. base::Version version_;
  38. base::Time expiry_date_;
  39. };
  40. } // namespace android_webview
  41. #endif // ANDROID_WEBVIEW_COMMON_METRICS_APP_PACKAGE_NAME_LOGGING_RULE_H_