Skip to content

Commit

Permalink
Tokens that fail to redeem due to network errors should be added to a…
Browse files Browse the repository at this point in the history
… queue and retried

fixes brave/brave-browser#3662
  • Loading branch information
tmancey authored Mar 25, 2019
1 parent aa0bb45 commit 47fe612
Show file tree
Hide file tree
Showing 19 changed files with 808 additions and 305 deletions.
1 change: 1 addition & 0 deletions vendor/bat-native-ads/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ source_set("ads") {
"src/bat/ads/bundle_state.cc",
"src/bat/ads/client_info.cc",
"src/bat/ads/issuer_info.cc",
"src/bat/ads/confirmation_type.cc",
"src/bat/ads/issuers_info.cc",
"src/bat/ads/notification_info.cc",
"src/bat/ads/internal/ads_impl.cc",
Expand Down
37 changes: 26 additions & 11 deletions vendor/bat-native-ads/include/bat/ads/confirmation_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
#ifndef BAT_ADS_CONFIRMATION_TYPE_H_
#define BAT_ADS_CONFIRMATION_TYPE_H_

#include <string>

namespace ads {

static char kConfirmationTypeClick[] = "click";
static char kConfirmationTypeDismiss[] = "dismiss";
static char kConfirmationTypeView[] = "view";
static char kConfirmationTypeLanded[] = "landed";

enum class ConfirmationType {
UNKNOWN,
CLICK,
DISMISS,
VIEW,
LANDED
class ConfirmationType {
public:
enum Value : int {
UNKNOWN,
CLICK,
DISMISS,
VIEW,
LANDED
};

ConfirmationType() = default;
constexpr ConfirmationType(const Value value) : value_(value) {}
explicit ConfirmationType(const std::string& value);

bool IsSupported() const;

int value() const;
operator std::string() const;

bool operator==(ConfirmationType type) const;
bool operator!=(ConfirmationType type) const;

private:
Value value_;
};

} // namespace ads
Expand Down
69 changes: 69 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/confirmation_type.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "bat/ads/confirmation_type.h"

namespace ads {

static const char kConfirmationTypeClick[] = "click";
static const char kConfirmationTypeDismiss[] = "dismiss";
static const char kConfirmationTypeView[] = "view";
static const char kConfirmationTypeLanded[] = "landed";

ConfirmationType::ConfirmationType(const std::string& value) {
if (value == kConfirmationTypeClick) {
value_ = CLICK;
} else if (value == kConfirmationTypeDismiss) {
value_ = DISMISS;
} else if (value == kConfirmationTypeView) {
value_ = VIEW;
} else if (value == kConfirmationTypeLanded) {
value_ = LANDED;
} else {
value_ = UNKNOWN;
}
}

bool ConfirmationType::IsSupported() const {
return value_ != UNKNOWN;
}

int ConfirmationType::value() const {
return value_;
}

ConfirmationType::operator std::string() const {
switch (value_) {
case UNKNOWN: {
return "";
}

case CLICK: {
return kConfirmationTypeClick;
}

case DISMISS: {
return kConfirmationTypeDismiss;
}

case VIEW: {
return kConfirmationTypeView;
}

case LANDED: {
return kConfirmationTypeLanded;
}
}
}

bool ConfirmationType::operator==(ConfirmationType type) const {
return value_ == type.value_;
}

bool ConfirmationType::operator!=(ConfirmationType type) const {
return value_ != type.value_;
}

} // namespace ads
29 changes: 1 addition & 28 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1289,35 +1289,8 @@ void AdsImpl::GenerateAdReportingConfirmationEvent(
writer.String("notificationId");
writer.String(info.uuid.c_str());

std::string type;
switch (info.type) {
case ConfirmationType::UNKNOWN: {
DCHECK(false) << "Invalid confirmation type";
break;
}

case ConfirmationType::CLICK: {
type = kConfirmationTypeClick;
break;
}

case ConfirmationType::DISMISS: {
type = kConfirmationTypeDismiss;
break;
}

case ConfirmationType::VIEW: {
type = kConfirmationTypeView;
break;
}

case ConfirmationType::LANDED: {
type = kConfirmationTypeLanded;
break;
}
}

writer.String("notificationType");
auto type = std::string(info.type);
writer.String(type.c_str());

writer.EndObject();
Expand Down
40 changes: 3 additions & 37 deletions vendor/bat-native-ads/src/bat/ads/notification_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,7 @@ Result NotificationInfo::FromJson(

if (document.HasMember("confirmation_type")) {
std::string confirmation_type = document["confirmation_type"].GetString();
if (confirmation_type == kConfirmationTypeClick) {
type = ConfirmationType::CLICK;
} else if (confirmation_type == kConfirmationTypeDismiss) {
type = ConfirmationType::DISMISS;
} else if (confirmation_type == kConfirmationTypeView) {
type = ConfirmationType::VIEW;
} else if (confirmation_type == kConfirmationTypeLanded) {
type = ConfirmationType::LANDED;
} else {
type = ConfirmationType::UNKNOWN;
}
type = ConfirmationType(confirmation_type);
}

return SUCCESS;
Expand Down Expand Up @@ -116,32 +106,8 @@ void SaveToJson(JsonWriter* writer, const NotificationInfo& info) {
writer->String(info.uuid.c_str());

writer->String("confirmation_type");
switch (info.type) {
case ConfirmationType::UNKNOWN: {
writer->String("");
break;
}

case ConfirmationType::CLICK: {
writer->String(kConfirmationTypeClick);
break;
}

case ConfirmationType::DISMISS: {
writer->String(kConfirmationTypeDismiss);
break;
}

case ConfirmationType::VIEW: {
writer->String(kConfirmationTypeView);
break;
}

case ConfirmationType::LANDED: {
writer->String(kConfirmationTypeLanded);
break;
}
}
auto type = std::string(info.type);
writer->String(type.c_str());

writer->EndObject();
}
Expand Down
4 changes: 4 additions & 0 deletions vendor/bat-native-confirmations/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ source_set("bat-native-confirmations") {
]

sources = [
"include/bat/confirmations/confirmation_type.h",
"include/bat/confirmations/confirmations_client.h",
"include/bat/confirmations/confirmations.h",
"include/bat/confirmations/export.h",
"include/bat/confirmations/issuer_info.h",
"include/bat/confirmations/issuers_info.h",
"include/bat/confirmations/notification_info.h",
"include/bat/confirmations/wallet_info.h",
"src/bat/confirmations/confirmation_type.cc",
"src/bat/confirmations/confirmations.cc",
"src/bat/confirmations/issuer_info.cc",
"src/bat/confirmations/issuers_info.cc",
"src/bat/confirmations/notification_info.cc",
"src/bat/confirmations/wallet_info.cc",
"src/bat/confirmations/internal/ads_serve_helper.cc",
"src/bat/confirmations/internal/ads_serve_helper.h",
"src/bat/confirmations/internal/confirmation_info.cc",
"src/bat/confirmations/internal/confirmation_info.h",
"src/bat/confirmations/internal/confirmations_impl.cc",
"src/bat/confirmations/internal/confirmations_impl.h",
"src/bat/confirmations/internal/create_confirmation_request.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
#ifndef BAT_CONFIRMATIONS_CONFIRMATION_TYPE_H_
#define BAT_CONFIRMATIONS_CONFIRMATION_TYPE_H_

#include <string>

namespace confirmations {

static char kConfirmationTypeClick[] = "click";
static char kConfirmationTypeDismiss[] = "dismiss";
static char kConfirmationTypeView[] = "view";
static char kConfirmationTypeLanded[] = "landed";

enum class ConfirmationType {
UNKNOWN,
CLICK,
DISMISS,
VIEW,
LANDED
class ConfirmationType {
public:
enum Value : int {
UNKNOWN,
CLICK,
DISMISS,
VIEW,
LANDED
};

ConfirmationType() = default;
constexpr ConfirmationType(const Value value) : value_(value) {}
explicit ConfirmationType(const std::string& value);

bool IsSupported() const;

int value() const;
operator std::string() const;

bool operator==(ConfirmationType type) const;
bool operator!=(ConfirmationType type) const;

private:
Value value_;
};

} // namespace confirmations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "bat/confirmations/confirmation_type.h"

namespace confirmations {

static const char kConfirmationTypeClick[] = "click";
static const char kConfirmationTypeDismiss[] = "dismiss";
static const char kConfirmationTypeView[] = "view";
static const char kConfirmationTypeLanded[] = "landed";

ConfirmationType::ConfirmationType(const std::string& value) {
if (value == kConfirmationTypeClick) {
value_ = CLICK;
} else if (value == kConfirmationTypeDismiss) {
value_ = DISMISS;
} else if (value == kConfirmationTypeView) {
value_ = VIEW;
} else if (value == kConfirmationTypeLanded) {
value_ = LANDED;
} else {
value_ = UNKNOWN;
}
}

bool ConfirmationType::IsSupported() const {
return value_ != UNKNOWN;
}

int ConfirmationType::value() const {
return value_;
}

ConfirmationType::operator std::string() const {
switch (value_) {
case UNKNOWN: {
return "";
}

case CLICK: {
return kConfirmationTypeClick;
}

case DISMISS: {
return kConfirmationTypeDismiss;
}

case VIEW: {
return kConfirmationTypeView;
}

case LANDED: {
return kConfirmationTypeLanded;
}
}
}

bool ConfirmationType::operator==(ConfirmationType type) const {
return value_ == type.value_;
}

bool ConfirmationType::operator!=(ConfirmationType type) const {
return value_ != type.value_;
}

} // namespace confirmations
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "bat/confirmations/internal/confirmation_info.h"

namespace confirmations {

ConfirmationInfo::ConfirmationInfo() :
id(""),
creative_instance_id(""),
type(ConfirmationType::UNKNOWN),
token_info(TokenInfo()),
payment_token(nullptr),
blinded_payment_token(nullptr),
credential("") {}

ConfirmationInfo::ConfirmationInfo(const ConfirmationInfo& info) :
id(info.id),
creative_instance_id(info.creative_instance_id),
type(info.type),
token_info(info.token_info),
payment_token(info.payment_token),
blinded_payment_token(info.blinded_payment_token),
credential(info.credential) {}

ConfirmationInfo::~ConfirmationInfo() {}

} // namespace confirmations
Loading

0 comments on commit 47fe612

Please sign in to comment.