7
7
8
8
#include < cstddef>
9
9
#include < utility>
10
+ #include < vector>
10
11
11
12
#include " base/check_deref.h"
12
13
#include " base/json/json_reader.h"
13
14
#include " base/strings/utf_string_conversions.h"
15
+ #include " base/version.h"
14
16
#include " base/version_info/channel.h"
15
17
#include " base/version_info/version_info.h"
16
18
#include " brave/browser/brave_ads/ad_units/notification_ad/notification_ad_platform_bridge.h"
@@ -56,32 +58,65 @@ constexpr char kSkuOrderLastPaidAtKey[] = "last_paid_at";
56
58
constexpr char kSkuOrderStatusKey [] = " status" ;
57
59
constexpr char kNotificationAdUrlPrefix [] = " https://www.brave.com/ads/?" ;
58
60
61
+ int GetVersionComponent (size_t index) {
62
+ const base::Version& version = version_info::GetVersion ();
63
+ const std::vector<uint32_t >& version_components = version.components ();
64
+ return index < version_components.size ()
65
+ ? static_cast <int >(version_components[index ])
66
+ : 0 ;
67
+ }
68
+
69
+ int GetMajorVersion () {
70
+ return GetVersionComponent (0 );
71
+ }
72
+
73
+ int GetMinorVersion () {
74
+ return GetVersionComponent (1 );
75
+ }
76
+
77
+ int GetBuildVersion () {
78
+ return GetVersionComponent (2 );
79
+ }
80
+
81
+ int GetPatchVersion () {
82
+ return GetVersionComponent (3 );
83
+ }
84
+
85
+ bool IsMobilePlatform () {
86
+ std::string_view operating_system_name = version_info::GetOSType ();
87
+ return operating_system_name == " Android" || operating_system_name == " iOS" ;
88
+ }
89
+
59
90
std::string StripSkuEnvironmentPrefix (const std::string& environment) {
60
91
const size_t pos = environment.find (' :' );
61
92
return environment.substr (pos + 1 );
62
93
}
63
94
64
95
std::string NormalizeSkuStatus (const std::string& status) {
96
+ // Normalize the status field to use consistent (US) spelling, as the JSON
97
+ // source localizes it (e.g., "cancelled" vs "canceled").
65
98
return status == " cancelled" ? " canceled" : status;
66
99
}
67
100
68
101
base::Value::Dict ParseSkuOrder (const base::Value::Dict& dict) {
69
102
base::Value::Dict order;
70
103
71
- if (const auto * const created_at = dict.FindString (kSkuOrderCreatedAtKey )) {
104
+ if (const std::string* const created_at =
105
+ dict.FindString (kSkuOrderCreatedAtKey )) {
72
106
order.Set (kSkuOrderCreatedAtKey , *created_at);
73
107
}
74
108
75
- if (const auto * const expires_at = dict.FindString (kSkuOrderExpiresAtKey )) {
109
+ if (const std::string* const expires_at =
110
+ dict.FindString (kSkuOrderExpiresAtKey )) {
76
111
order.Set (kSkuOrderExpiresAtKey , *expires_at);
77
112
}
78
113
79
- if (const auto * const last_paid_at =
114
+ if (const std::string * const last_paid_at =
80
115
dict.FindString (kSkuOrderLastPaidAtKey )) {
81
116
order.Set (kSkuOrderLastPaidAtKey , *last_paid_at);
82
117
}
83
118
84
- if (const auto * const status = dict.FindString (kSkuOrderStatusKey )) {
119
+ if (const std::string * const status = dict.FindString (kSkuOrderStatusKey )) {
85
120
const std::string normalized_status = NormalizeSkuStatus (*status);
86
121
order.Set (kSkuOrderStatusKey , normalized_status);
87
122
}
@@ -99,7 +134,7 @@ base::Value::Dict ParseSkuOrders(const base::Value::Dict& dict) {
99
134
}
100
135
101
136
const std::string* const location = order->FindString (kSkuOrderLocationKey );
102
- if (!location) {
137
+ if (!location || location-> empty () ) {
103
138
continue ;
104
139
}
105
140
@@ -150,7 +185,8 @@ base::Value::Dict AdsServiceDelegate::GetSkus() const {
150
185
continue ;
151
186
}
152
187
153
- // Parse the SKUs JSON because it is stored as a string in local state.
188
+ // Deserialize the SKUs data from a JSON string stored in local state into a
189
+ // dictionary object for further processing.
154
190
std::optional<base::Value::Dict> sku_state =
155
191
base::JSONReader::ReadDict (value.GetString ());
156
192
if (!sku_state) {
@@ -297,12 +333,17 @@ base::Value::Dict AdsServiceDelegate::GetVirtualPrefs() {
297
333
base::Value::Dict ()
298
334
.Set (" build_channel" ,
299
335
version_info::GetChannelString (chrome::GetChannel ()))
300
- .Set (" version" , version_info::GetVersionNumber ()))
336
+ .Set (" version" , version_info::GetVersionNumber ())
337
+ .Set (" major_version" , GetMajorVersion ())
338
+ .Set (" minor_version" , GetMinorVersion ())
339
+ .Set (" build_version" , GetBuildVersion ())
340
+ .Set (" patch_version" , GetPatchVersion ()))
301
341
.Set (" [virtual]:operating_system" ,
302
342
base::Value::Dict ()
303
343
.Set (" locale" , base::Value::Dict ()
304
344
.Set (" language" , CurrentLanguageCode ())
305
345
.Set (" region" , CurrentCountryCode ()))
346
+ .Set (" is_mobile_platform" , IsMobilePlatform ())
306
347
.Set (" name" , version_info::GetOSType ()))
307
348
.Set (
308
349
" [virtual]:search_engine" ,
0 commit comments