Skip to content

Commit

Permalink
Merge pull request #3027 from brave/result-mojo
Browse files Browse the repository at this point in the history
Moves Result into mojo
  • Loading branch information
NejcZdovc authored Jul 26, 2019
2 parents 3e5dc38 + f0c2f87 commit f8509ef
Show file tree
Hide file tree
Showing 24 changed files with 407 additions and 399 deletions.
4 changes: 2 additions & 2 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class RewardsDOMHandler : public WebUIMessageHandler,
std::unique_ptr<brave_rewards::WalletProperties>
wallet_properties) override;
void OnGrant(brave_rewards::RewardsService* rewards_service,
unsigned int error_code,
brave_rewards::Grant result) override;
unsigned int result,
brave_rewards::Grant grant) override;
void OnGrantCaptcha(brave_rewards::RewardsService* rewards_service,
std::string image, std::string hint) override;
void OnRecoverWallet(brave_rewards::RewardsService* rewards_service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ void ExtensionRewardsServiceObserver::OnWalletInitialized(
uint32_t result) {
auto* event_router = extensions::EventRouter::Get(profile_);

auto converted_result = static_cast<ledger::Result>(result);

// Don't report back if there is no ledger file
if (event_router && result != ledger::Result::NO_LEDGER_STATE) {
if (event_router && converted_result != ledger::Result::NO_LEDGER_STATE) {
std::unique_ptr<base::ListValue> args(
extensions::api::brave_rewards::OnWalletInitialized::Create(
result).release());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,24 @@ std::string RewardsNotificationServiceImpl::GetGrantIdPrefix(
}

void RewardsNotificationServiceImpl::OnGrant(RewardsService* rewards_service,
unsigned int error_code,
unsigned int result,
Grant properties) {
if (error_code == ledger::Result::LEDGER_OK) {
std::string grant_type = properties.type;
std::string prefix = GetGrantIdPrefix(grant_type);
RewardsNotificationService::RewardsNotificationType notification_type
= IsUGPGrant(grant_type)
? RewardsNotificationService::REWARDS_NOTIFICATION_GRANT
: RewardsNotificationService::REWARDS_NOTIFICATION_GRANT_ADS;

RewardsNotificationService::RewardsNotificationArgs args;
AddNotification(notification_type,
args,
prefix + properties.promotionId,
true);
if (static_cast<ledger::Result>(result) != ledger::Result::LEDGER_OK) {
return;
}

std::string grant_type = properties.type;
std::string prefix = GetGrantIdPrefix(grant_type);
RewardsNotificationService::RewardsNotificationType notification_type
= IsUGPGrant(grant_type)
? RewardsNotificationService::REWARDS_NOTIFICATION_GRANT
: RewardsNotificationService::REWARDS_NOTIFICATION_GRANT_ADS;

RewardsNotificationService::RewardsNotificationArgs args;
AddNotification(notification_type,
args,
prefix + properties.promotionId,
true);
}

void RewardsNotificationServiceImpl::OnGrantFinish(
Expand All @@ -345,11 +347,12 @@ void RewardsNotificationServiceImpl::OnReconcileComplete(
const std::string& viewing_id,
int32_t category,
const std::string& probi) {
if ((result == ledger::Result::LEDGER_OK &&
auto converted_result = static_cast<ledger::Result>(result);
if ((converted_result == ledger::Result::LEDGER_OK &&
category == ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE) ||
result == ledger::Result::LEDGER_ERROR ||
result == ledger::Result::NOT_ENOUGH_FUNDS ||
result == ledger::Result::TIP_ERROR) {
converted_result == ledger::Result::LEDGER_ERROR ||
converted_result == ledger::Result::NOT_ENOUGH_FUNDS ||
converted_result == ledger::Result::TIP_ERROR) {
RewardsNotificationService::RewardsNotificationArgs args;
args.push_back(viewing_id);
args.push_back(std::to_string(result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RewardsNotificationServiceImpl

// RewardsServiceObserver impl
void OnGrant(RewardsService* rewards_service,
unsigned int error_code,
unsigned int result,
Grant properties) override;
void OnGrantFinish(RewardsService* rewards_service,
unsigned int result,
Expand Down
23 changes: 13 additions & 10 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,9 @@ class BraveRewardsBrowserTest :

void OnWalletInitialized(brave_rewards::RewardsService* rewards_service,
uint32_t result) {
ASSERT_TRUE(result == ledger::Result::WALLET_CREATED ||
result == ledger::Result::NO_LEDGER_STATE);
const auto converted_result = static_cast<ledger::Result>(result);
ASSERT_TRUE(converted_result == ledger::Result::WALLET_CREATED ||
converted_result == ledger::Result::NO_LEDGER_STATE);
wallet_initialized_ = true;
if (wait_for_wallet_initialization_loop_)
wait_for_wallet_initialization_loop_->Quit();
Expand All @@ -1030,7 +1031,7 @@ class BraveRewardsBrowserTest :
void OnGrant(brave_rewards::RewardsService* rewards_service,
unsigned int result,
brave_rewards::Grant properties) {
ASSERT_EQ(result, ledger::Result::LEDGER_OK);
ASSERT_EQ(static_cast<ledger::Result>(result), ledger::Result::LEDGER_OK);
grant_initialized_ = true;
if (wait_for_grant_initialization_loop_)
wait_for_grant_initialization_loop_->Quit();
Expand All @@ -1047,7 +1048,7 @@ class BraveRewardsBrowserTest :
void OnGrantFinish(brave_rewards::RewardsService* rewards_service,
unsigned int result,
brave_rewards::Grant grant) {
ASSERT_EQ(result, ledger::Result::LEDGER_OK);
ASSERT_EQ(static_cast<ledger::Result>(result), ledger::Result::LEDGER_OK);
grant_finished_ = true;
grant_ = grant;
balance_ += 30.0;
Expand Down Expand Up @@ -1077,9 +1078,11 @@ class BraveRewardsBrowserTest :

UpdateContributionBalance(std::stod(amount), true);

const auto converted_result = static_cast<ledger::Result>(result);

if (category == ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE) {
ac_reconcile_completed_ = true;
ac_reconcile_status_ = result;
ac_reconcile_status_ = converted_result;
if (wait_for_ac_completed_loop_) {
wait_for_ac_completed_loop_->Quit();
}
Expand All @@ -1089,14 +1092,14 @@ class BraveRewardsBrowserTest :
category == ledger::REWARDS_CATEGORY::RECURRING_TIP) {
// Single tip tracking
tip_reconcile_completed_ = true;
tip_reconcile_status_ = result;
tip_reconcile_status_ = converted_result;
if (wait_for_tip_completed_loop_) {
wait_for_tip_completed_loop_->Quit();
}

// Multiple tips
multiple_tip_reconcile_count_++;
multiple_tip_reconcile_status_ = result;
multiple_tip_reconcile_status_ = converted_result;

if (multiple_tip_reconcile_count_ == multiple_tip_reconcile_needed_) {
multiple_tip_reconcile_completed_ = true;
Expand Down Expand Up @@ -1181,15 +1184,15 @@ class BraveRewardsBrowserTest :

std::unique_ptr<base::RunLoop> wait_for_ac_completed_loop_;
bool ac_reconcile_completed_ = false;
unsigned int ac_reconcile_status_ = ledger::LEDGER_ERROR;
ledger::Result ac_reconcile_status_ = ledger::Result::LEDGER_ERROR;
std::unique_ptr<base::RunLoop> wait_for_tip_completed_loop_;
bool tip_reconcile_completed_ = false;
unsigned int tip_reconcile_status_ = ledger::LEDGER_ERROR;
ledger::Result tip_reconcile_status_ = ledger::Result::LEDGER_ERROR;
std::unique_ptr<base::RunLoop> wait_for_multiple_tip_completed_loop_;
bool multiple_tip_reconcile_completed_ = false;
int32_t multiple_tip_reconcile_count_ = 0;
int32_t multiple_tip_reconcile_needed_ = 0;
unsigned int multiple_tip_reconcile_status_ = ledger::LEDGER_ERROR;
ledger::Result multiple_tip_reconcile_status_ = ledger::Result::LEDGER_ERROR;

std::unique_ptr<base::RunLoop> wait_for_insufficient_notification_loop_;
bool insufficient_notification_would_have_already_shown_ = false;
Expand Down
Loading

0 comments on commit f8509ef

Please sign in to comment.