1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_COMMERCE_CORE_SUBSCRIPTIONS_COMMERCE_SUBSCRIPTION_H_
#define COMPONENTS_COMMERCE_CORE_SUBSCRIPTIONS_COMMERCE_SUBSCRIPTION_H_
#include <stdint.h>
#include <optional>
#include <string>
/**
* To add a new SubscriptionType / IdentifierType / ManagementType:
* 1. Define the type in the enum class in commerce_subscription.h.
* 2. Update the conversion methods between the type and std::string in
* commerce_subscription.cc.
* 3. Add the corresponding entry in {@link
* commerce_subscription_db_content.proto} to ensure the storage works
* correctly.
*/
namespace commerce {
// The type of subscription.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.commerce.core
enum class SubscriptionType {
// Unspecified type.
kTypeUnspecified = 0,
// Subscription for price tracking.
kPriceTrack = 1,
};
// The type of subscription identifier.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.commerce.core
enum class IdentifierType {
// Unspecified identifier type.
kIdentifierTypeUnspecified = 0,
// Offer id identifier, used in chrome-managed price tracking.
kOfferId = 1,
// Product cluster id identifier, used in user-managed price tracking.
kProductClusterId = 2,
};
// The type of subscription management.
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.commerce.core
enum class ManagementType {
// Unspecified management type.
kTypeUnspecified = 0,
// Automatic chrome-managed subscription.
kChromeManaged = 1,
// Explicit user-managed subscription.
kUserManaged = 2,
};
// The user seen offer data upon price tracking subscribing, used to improve the
// price drop notification quality.
struct UserSeenOffer {
UserSeenOffer(std::string offer_id,
long user_seen_price,
std::string country_code,
std::string locale);
UserSeenOffer(const UserSeenOffer&);
UserSeenOffer& operator=(const UserSeenOffer&);
~UserSeenOffer();
// Associated offer id.
std::string offer_id;
// The price upon subscribing.
long user_seen_price;
// Country code of the offer.
std::string country_code;
// Locale of the offer.
std::string locale;
};
extern const int64_t kUnknownSubscriptionTimestamp;
extern const uint64_t kInvalidSubscriptionId;
struct CommerceSubscription {
// The CommerceSubscription instantiation outside of this subscriptions/
// component should always use kUnknownSubscriptionTimestamp.
CommerceSubscription(
SubscriptionType type,
IdentifierType id_type,
std::string id,
ManagementType management_type,
int64_t timestamp = kUnknownSubscriptionTimestamp,
std::optional<UserSeenOffer> user_seen_offer = std::nullopt);
CommerceSubscription(const CommerceSubscription&);
CommerceSubscription& operator=(const CommerceSubscription&);
~CommerceSubscription();
SubscriptionType type;
IdentifierType id_type;
std::string id;
ManagementType management_type;
// The timestamp when the subscription is created on the server side. Upon
// successful creation on the server side, the valid timestamp will be passed
// back to client side and then stored locally.
int64_t timestamp;
std::optional<UserSeenOffer> user_seen_offer;
};
std::string SubscriptionTypeToString(SubscriptionType type);
SubscriptionType StringToSubscriptionType(const std::string& s);
std::string SubscriptionIdTypeToString(IdentifierType type);
IdentifierType StringToSubscriptionIdType(const std::string& s);
std::string SubscriptionManagementTypeToString(ManagementType type);
ManagementType StringToSubscriptionManagementType(const std::string& s);
// Gets a key for the provided subscription that can be used for storage or
// caching.
std::string GetStorageKeyForSubscription(
const CommerceSubscription& subscription);
} // namespace commerce
#endif // COMPONENTS_COMMERCE_CORE_SUBSCRIPTIONS_COMMERCE_SUBSCRIPTION_H_
|