Skip to content

Commit

Permalink
Merge pull request #3615 from brave/system-options
Browse files Browse the repository at this point in the history
Adds client static values
  • Loading branch information
NejcZdovc authored Oct 8, 2019
2 parents e948c45 + 8c9e1bb commit d6c7cdc
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 3 deletions.
54 changes: 54 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,60 @@ void RewardsServiceImpl::ClearState(const std::string& name) {
profile_->GetPrefs()->ClearPref(pref_prefix + name);
}

bool RewardsServiceImpl::GetBooleanOption(const std::string& name) const {
DCHECK(!name.empty());

const auto it = kBoolOptions.find(name);
DCHECK(it != kBoolOptions.end());

return kBoolOptions.at(name);
}

int RewardsServiceImpl::GetIntegerOption(const std::string& name) const {
DCHECK(!name.empty());

const auto it = kIntegerOptions.find(name);
DCHECK(it != kIntegerOptions.end());

return kIntegerOptions.at(name);
}

double RewardsServiceImpl::GetDoubleOption(const std::string& name) const {
DCHECK(!name.empty());

const auto it = kDoubleOptions.find(name);
DCHECK(it != kDoubleOptions.end());

return kDoubleOptions.at(name);
}

std::string RewardsServiceImpl::GetStringOption(const std::string& name) const {
DCHECK(!name.empty());

const auto it = kStringOptions.find(name);
DCHECK(it != kStringOptions.end());

return kStringOptions.at(name);
}

int64_t RewardsServiceImpl::GetInt64Option(const std::string& name) const {
DCHECK(!name.empty());

const auto it = kInt64Options.find(name);
DCHECK(it != kInt64Options.end());

return kInt64Options.at(name);
}

uint64_t RewardsServiceImpl::GetUint64Option(const std::string& name) const {
DCHECK(!name.empty());

const auto it = kUInt64Options.find(name);
DCHECK(it != kUInt64Options.end());

return kUInt64Options.at(name);
}

void RewardsServiceImpl::KillTimer(uint32_t timer_id) {
if (timers_.find(timer_id) == timers_.end())
return;
Expand Down
7 changes: 7 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ class RewardsServiceImpl : public RewardsService,
uint64_t GetUint64State(const std::string& name) const override;
void ClearState(const std::string& name) override;

bool GetBooleanOption(const std::string& name) const override;
int GetIntegerOption(const std::string& name) const override;
double GetDoubleOption(const std::string& name) const override;
std::string GetStringOption(const std::string& name) const override;
int64_t GetInt64Option(const std::string& name) const override;
uint64_t GetUint64Option(const std::string& name) const override;


void KillTimer(uint32_t timer_id) override;

Expand Down
21 changes: 18 additions & 3 deletions components/brave_rewards/browser/static_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@
#ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_STATIC_VALUES_H_
#define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_STATIC_VALUES_H_

#include <stdint.h>

#include <map>
#include <string>
#include <vector>

namespace brave_rewards {

const std::vector<std::string> kOnlyAnonWalletCountries ={
"JP" // ID: 19024
};
const std::vector<std::string> kOnlyAnonWalletCountries = {
"JP" // ID: 19024
};

const std::map<std::string, bool> kBoolOptions = {};

const std::map<std::string, int> kIntegerOptions = {};

const std::map<std::string, double> kDoubleOptions = {};

const std::map<std::string, std::string> kStringOptions = {};

const std::map<std::string, int64_t> kInt64Options = {};

const std::map<std::string, uint64_t> kUInt64Options = {};

} // namespace brave_rewards

Expand Down
40 changes: 40 additions & 0 deletions components/services/bat_ledger/bat_ledger_client_mojo_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,46 @@ void BatLedgerClientMojoProxy::ClearState(const std::string& name) {
bat_ledger_client_->ClearState(name);
}

bool BatLedgerClientMojoProxy::GetBooleanOption(const std::string& name) const {
bool value;
bat_ledger_client_->GetBooleanOption(name, &value);
return value;
}

int BatLedgerClientMojoProxy::GetIntegerOption(const std::string& name) const {
int value;
bat_ledger_client_->GetIntegerOption(name, &value);
return value;
}

double BatLedgerClientMojoProxy::GetDoubleOption(
const std::string& name) const {
double value;
bat_ledger_client_->GetDoubleOption(name, &value);
return value;
}

std::string BatLedgerClientMojoProxy::GetStringOption(
const std::string& name) const {
std::string value;
bat_ledger_client_->GetStringOption(name, &value);
return value;
}

int64_t BatLedgerClientMojoProxy::GetInt64Option(
const std::string& name) const {
int64_t value;
bat_ledger_client_->GetInt64Option(name, &value);
return value;
}

uint64_t BatLedgerClientMojoProxy::GetUint64Option(
const std::string& name) const {
uint64_t value;
bat_ledger_client_->GetUint64Option(name, &value);
return value;
}

void BatLedgerClientMojoProxy::SetConfirmationsIsReady(const bool is_ready) {
if (!Connected())
return;
Expand Down
6 changes: 6 additions & 0 deletions components/services/bat_ledger/bat_ledger_client_mojo_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
uint64_t GetUint64State(const std::string& name) const override;
void ClearState(const std::string& name) override;

bool GetBooleanOption(const std::string& name) const override;
int GetIntegerOption(const std::string& name) const override;
double GetDoubleOption(const std::string& name) const override;
std::string GetStringOption(const std::string& name) const override;
int64_t GetInt64Option(const std::string& name) const override;
uint64_t GetUint64Option(const std::string& name) const override;

void SetConfirmationsIsReady(const bool is_ready) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,42 @@ void LedgerClientMojoProxy::ClearState(const std::string& name) {
ledger_client_->ClearState(name);
}

void LedgerClientMojoProxy::GetBooleanOption(
const std::string& name,
GetBooleanOptionCallback callback) {
std::move(callback).Run(ledger_client_->GetBooleanOption(name));
}

void LedgerClientMojoProxy::GetIntegerOption(
const std::string& name,
GetIntegerOptionCallback callback) {
std::move(callback).Run(ledger_client_->GetIntegerOption(name));
}

void LedgerClientMojoProxy::GetDoubleOption(
const std::string& name,
GetDoubleOptionCallback callback) {
std::move(callback).Run(ledger_client_->GetDoubleOption(name));
}

void LedgerClientMojoProxy::GetStringOption(
const std::string& name,
GetStringOptionCallback callback) {
std::move(callback).Run(ledger_client_->GetStringOption(name));
}

void LedgerClientMojoProxy::GetInt64Option(
const std::string& name,
GetInt64OptionCallback callback) {
std::move(callback).Run(ledger_client_->GetInt64Option(name));
}

void LedgerClientMojoProxy::GetUint64Option(
const std::string& name,
GetUint64OptionCallback callback) {
std::move(callback).Run(ledger_client_->GetUint64Option(name));
}

void LedgerClientMojoProxy::SetConfirmationsIsReady(const bool is_ready) {
ledger_client_->SetConfirmationsIsReady(is_ready);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient,
GetUint64StateCallback callback) override;
void ClearState(const std::string& name) override;

void GetBooleanOption(
const std::string& name,
GetBooleanOptionCallback callback) override;
void GetIntegerOption(
const std::string& name,
GetIntegerOptionCallback callback) override;
void GetDoubleOption(
const std::string& name,
GetDoubleOptionCallback callback) override;
void GetStringOption(
const std::string& name,
GetStringOptionCallback callback) override;
void GetInt64Option(
const std::string& name,
GetInt64OptionCallback callback) override;
void GetUint64Option(
const std::string& name,
GetUint64OptionCallback callback) override;

void SetConfirmationsIsReady(const bool is_ready) override;

void ConfirmationsTransactionHistoryDidChange() override;
Expand Down
13 changes: 13 additions & 0 deletions components/services/bat_ledger/public/interfaces/bat_ledger.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ interface BatLedgerClient {
SetUint64State(string name, uint64 value);
ClearState(string name);

[Sync]
GetBooleanOption(string name) => (bool value);
[Sync]
GetIntegerOption(string name) => (int32 value);
[Sync]
GetDoubleOption(string name) => (double value);
[Sync]
GetStringOption(string name) => (string value);
[Sync]
GetInt64Option(string name) => (int64 value);
[Sync]
GetUint64Option(string name) => (uint64 value);

SetConfirmationsIsReady(bool is_ready);
ConfirmationsTransactionHistoryDidChange();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,24 @@ class MockConfirmationsClient : public ConfirmationsClient {
MOCK_METHOD1(ClearState, void(
const std::string& name));

MOCK_CONST_METHOD1(GetBooleanOption, bool(
const std::string& name));

MOCK_CONST_METHOD1(GetIntegerOption, int(
const std::string& name));

MOCK_CONST_METHOD1(GetDoubleOption, double(
const std::string& name));

MOCK_CONST_METHOD1(GetStringOption, std::string(
const std::string& name));

MOCK_CONST_METHOD1(GetInt64Option, int64_t(
const std::string& name));

MOCK_CONST_METHOD1(GetUint64Option, uint64_t(
const std::string& name));

MOCK_METHOD1(GetExternalWallets, void(
ledger::GetExternalWalletsCallback callback));

Expand Down
8 changes: 8 additions & 0 deletions vendor/bat-native-ledger/include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ class LEDGER_EXPORT LedgerClient {
virtual uint64_t GetUint64State(const std::string& name) const = 0;
virtual void ClearState(const std::string& name) = 0;

// Use option getter to get client specific static value
virtual bool GetBooleanOption(const std::string& name) const = 0;
virtual int GetIntegerOption(const std::string& name) const = 0;
virtual double GetDoubleOption(const std::string& name) const = 0;
virtual std::string GetStringOption(const std::string& name) const = 0;
virtual int64_t GetInt64Option(const std::string& name) const = 0;
virtual uint64_t GetUint64Option(const std::string& name) const = 0;

virtual void SetConfirmationsIsReady(const bool is_ready) = 0;

virtual void ConfirmationsTransactionHistoryDidChange() = 0;
Expand Down
24 changes: 24 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,30 @@ void LedgerImpl::ClearState(const std::string& name) {
ledger_client_->ClearState(name);
}

bool LedgerImpl::GetBooleanOption(const std::string& name) const {
return ledger_client_->GetBooleanOption(name);
}

int LedgerImpl::GetIntegerOption(const std::string& name) const {
return ledger_client_->GetIntegerOption(name);
}

double LedgerImpl::GetDoubleOption(const std::string& name) const {
return ledger_client_->GetDoubleOption(name);
}

std::string LedgerImpl::GetStringOption(const std::string& name) const {
return ledger_client_->GetStringOption(name);
}

int64_t LedgerImpl::GetInt64Option(const std::string& name) const {
return ledger_client_->GetInt64Option(name);
}

uint64_t LedgerImpl::GetUint64Option(const std::string& name) const {
return ledger_client_->GetUint64Option(name);
}

void LedgerImpl::SetTransferFee(
const std::string& wallet_type,
ledger::TransferFeePtr transfer_fee) {
Expand Down
12 changes: 12 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,18 @@ class LedgerImpl : public ledger::Ledger,

void ClearState(const std::string& name);

bool GetBooleanOption(const std::string& name) const;

int GetIntegerOption(const std::string& name) const;

double GetDoubleOption(const std::string& name) const;

std::string GetStringOption(const std::string& name) const;

int64_t GetInt64Option(const std::string& name) const;

uint64_t GetUint64Option(const std::string& name) const;

void SetTransferFee(
const std::string& wallet_type,
ledger::TransferFeePtr transfer_fee);
Expand Down
31 changes: 31 additions & 0 deletions vendor/brave-ios/Ledger/BATBraveLedger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,37 @@ - (void)clearState:(const std::string&)name
[self savePrefs];
}

- (bool)getBooleanOption:(const std::string&)name
{
// TODO implement
return true;
}
- (int)getIntegerOption:(const std::string&)name
{
// TODO implement
return 0;
}
- (double)getDoubleOption:(const std::string&)name
{
// TODO implement
return 0.0;
}
- (std::string)getStringOption:(const std::string&)name
{
// TODO implement
return "";
}
- (int64_t)getInt64Option:(const std::string&)name
{
// TODO implement
return 0;
}
- (uint64_t)getUint64Option:(const std::string&)name
{
// TODO implement
return 0;
}

#pragma mark - Ads & Confirmations

- (void)confirmAd:(NSString *)info
Expand Down
6 changes: 6 additions & 0 deletions vendor/brave-ios/Ledger/Generated/NativeLedgerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ class NativeLedgerClient : public ledger::LedgerClient {
void SetTransferFee(const std::string& wallet_type, ledger::TransferFeePtr transfer_fee) override;
ledger::TransferFeeList GetTransferFees(const std::string& wallet_type) override;
void RemoveTransferFee(const std::string& wallet_type, const std::string& id) override;
bool GetBooleanOption(const std::string& name) const override;
int GetIntegerOption(const std::string& name) const override;
double GetDoubleOption(const std::string& name) const override;
std::string GetStringOption(const std::string& name) const override;
int64_t GetInt64Option(const std::string& name) const override;
uint64_t GetUint64Option(const std::string& name) const override;
};
Loading

0 comments on commit d6c7cdc

Please sign in to comment.