Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jan 29, 2019
1 parent 05d6293 commit 198e3b2
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 34 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 @@ -137,7 +137,7 @@ class RewardsDOMHandler : public WebUIMessageHandler,
brave_rewards::RewardsService* rewards_service,
bool rewards_main_enabled) override;

void OnNormalizedPublisherList(
void OnPublisherListNormalized(
brave_rewards::RewardsService* rewards_service,
brave_rewards::ContentSiteList list) override;

Expand Down Expand Up @@ -897,7 +897,7 @@ void RewardsDOMHandler::OnRewardsMainEnabled(
}


void RewardsDOMHandler::OnNormalizedPublisherList(
void RewardsDOMHandler::OnPublisherListNormalized(
brave_rewards::RewardsService* rewards_service,
brave_rewards::ContentSiteList list) {
std::unique_ptr<brave_rewards::ContentSiteList> site_list(
Expand Down
5 changes: 5 additions & 0 deletions components/brave_rewards/browser/content_site.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ struct ContentSite {
ContentSite(const ContentSite& properties);
~ContentSite();

// DESC sort
bool operator<(const ContentSite& other) const {
return percentage > other.percentage;
}

std::string id;
double percentage;
bool verified;
Expand Down
18 changes: 7 additions & 11 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2375,10 +2375,10 @@ SaveNormalizedPublisherListOnFileTaskRunner(PublisherInfoDatabase* backend,
void RewardsServiceImpl::SaveNormalizedPublisherList(
const ledger::PublisherInfoListStruct& list) {

if (list.list_.size() == 0) {
if (list.list.size() == 0) {
std::unique_ptr<ledger::PublisherInfoList> empty_list(
new ledger::PublisherInfoList);
OnNormalizedPublisherListSaved(std::move(empty_list));
OnPublisherListNormalizedSaved(std::move(empty_list));
return;
}

Expand All @@ -2387,16 +2387,12 @@ void RewardsServiceImpl::SaveNormalizedPublisherList(
FROM_HERE,
base::Bind(&SaveNormalizedPublisherListOnFileTaskRunner,
publisher_info_backend_.get(),
list.list_),
base::Bind(&RewardsServiceImpl::OnNormalizedPublisherListSaved,
list.list),
base::Bind(&RewardsServiceImpl::OnPublisherListNormalizedSaved,
AsWeakPtr()));
}

bool sortPublisherByPercentage(ContentSite a, ContentSite b) {
return a.percentage > b.percentage;
}

void RewardsServiceImpl::OnNormalizedPublisherListSaved(
void RewardsServiceImpl::OnPublisherListNormalizedSaved(
std::unique_ptr<ledger::PublisherInfoList> list) {
if (!list) {
LOG(ERROR) << "Problem saving normalized publishers "
Expand All @@ -2409,10 +2405,10 @@ void RewardsServiceImpl::OnNormalizedPublisherListSaved(
site_list.push_back(PublisherInfoToContentSite(publisher));
}

sort(site_list.begin(), site_list.end(), sortPublisherByPercentage);
sort(site_list.begin(), site_list.end());

for (auto& observer : observers_) {
observer.OnNormalizedPublisherList(this, site_list);
observer.OnPublisherListNormalized(this, site_list);
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class RewardsServiceImpl : public RewardsService,
void SaveNormalizedPublisherList(
const ledger::PublisherInfoListStruct& list) override;

void OnNormalizedPublisherListSaved(
void OnPublisherListNormalizedSaved(
std::unique_ptr<ledger::PublisherInfoList> list);

// URLFetcherDelegate impl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RewardsServiceObserver : public base::CheckedObserver {
virtual void OnPendingContributionSaved(
brave_rewards::RewardsService* rewards_service,
int result) {};
virtual void OnNormalizedPublisherList(
virtual void OnPublisherListNormalized(
RewardsService* rewards_service,
brave_rewards::ContentSiteList list) {};
// DO NOT ADD ANY MORE METHODS HERE UNLESS IT IS A BROADCAST NOTIFICATION
Expand Down
4 changes: 2 additions & 2 deletions vendor/bat-native-ledger/include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class LEDGER_EXPORT Ledger {

virtual std::string URIEncode(const std::string& value) = 0;

virtual void SetPublisherInfo(std::unique_ptr<PublisherInfo> publisher_info,
uint64_t window_id) = 0;
virtual void SetPublisherInfo(
std::unique_ptr<PublisherInfo> publisher_info) = 0;
virtual void SetActivityInfo(
std::unique_ptr<PublisherInfo> publisher_info) = 0;
virtual void GetPublisherInfo(const std::string& publisher_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ LEDGER_EXPORT struct PublisherInfoListStruct {
const std::string ToJson() const;
bool loadFromJson(const std::string& json);

std::vector<PublisherInfo> list_;
std::vector<PublisherInfo> list;
};

using PublisherInfoList = std::vector<PublisherInfo>;
Expand Down
4 changes: 2 additions & 2 deletions vendor/bat-native-ledger/src/bat/ledger/ledger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ PublisherInfoListStruct::PublisherInfoListStruct () {}
PublisherInfoListStruct::~PublisherInfoListStruct () {}
PublisherInfoListStruct::PublisherInfoListStruct (
const ledger::PublisherInfoListStruct &properties) {
list_ = properties.list_;
list = properties.list;
}

const std::string PublisherInfoListStruct::ToJson() const {
Expand Down Expand Up @@ -777,7 +777,7 @@ bool PublisherInfoListStruct::loadFromJson(const std::string& json) {

PublisherInfo contribution;
contribution.loadFromJson(sb.GetString());
list_.push_back(contribution);
list.push_back(contribution);
}
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ledger/src/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ static bool ignore_ = false;

writer.String("list");
writer.StartArray();
for (const auto& publisher : publishers.list_) {
for (const auto& publisher : publishers.list) {
saveToJson(writer, publisher);
}
writer.EndArray();
Expand Down
3 changes: 1 addition & 2 deletions vendor/bat-native-ledger/src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ void BatPublishers::onFetchFavIconDBResponse(
}

void BatPublishers::OnPublisherInfoSaved(
uint64_t window_id,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info) {
if (result != ledger::Result::LEDGER_OK || !info.get()) {
Expand Down Expand Up @@ -400,7 +399,7 @@ void BatPublishers::onSetPanelExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude,
ledger::VisitData visit_data;
std::string publisherKey = publisher_info->id;

ledger_->SetPublisherInfo(std::move(publisher_info), windowId);
ledger_->SetPublisherInfo(std::move(publisher_info));

OnExcludedSitesChanged(publisherKey);
}
Expand Down
1 change: 0 additions & 1 deletion vendor/bat-native-ledger/src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
bool getPublisherAllowVideos() const;

void OnPublisherInfoSaved(
uint64_t window_id,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo>);
std::string GetBalanceReportName(ledger::ACTIVITY_MONTH month, int year);
Expand Down
10 changes: 3 additions & 7 deletions vendor/bat-native-ledger/src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,16 @@ std::string LedgerImpl::URIEncode(const std::string& value) {
}

void LedgerImpl::OnPublisherInfoSavedInternal(
uint64_t window_id,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info) {
bat_publishers_->OnPublisherInfoSaved(window_id, result, std::move(info));
bat_publishers_->OnPublisherInfoSaved(result, std::move(info));
}

void LedgerImpl::SetPublisherInfo(std::unique_ptr<ledger::PublisherInfo> info,
uint64_t window_id) {
void LedgerImpl::SetPublisherInfo(std::unique_ptr<ledger::PublisherInfo> info) {
ledger_client_->SavePublisherInfo(
std::move(info),
std::bind(&LedgerImpl::OnPublisherInfoSavedInternal,
this,
window_id,
_1,
_2));
}
Expand All @@ -324,7 +321,6 @@ void LedgerImpl::SetActivityInfo(std::unique_ptr<ledger::PublisherInfo> info) {
std::move(info),
std::bind(&LedgerImpl::OnPublisherInfoSavedInternal,
this,
0,
_1,
_2));
}
Expand Down Expand Up @@ -1137,7 +1133,7 @@ bool LedgerImpl::HasSufficientBalanceToReconcile() {
void LedgerImpl::SaveNormalizedPublisherList(
const ledger::PublisherInfoList& normalized_list) {
ledger::PublisherInfoListStruct list;
list.list_ = normalized_list;
list.list = normalized_list;
ledger_client_->SaveNormalizedPublisherList(list);
}

Expand Down
5 changes: 2 additions & 3 deletions vendor/bat-native-ledger/src/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class LedgerImpl : public ledger::Ledger,
void Initialize() override;
bool CreateWallet() override;

void SetPublisherInfo(std::unique_ptr<ledger::PublisherInfo> publisher_info,
uint64_t window_id = 0) override;
void SetPublisherInfo(
std::unique_ptr<ledger::PublisherInfo> publisher_info) override;
void SetActivityInfo(
std::unique_ptr<ledger::PublisherInfo> publisher_info) override;
void GetPublisherInfo(const std::string& publisher_key,
Expand Down Expand Up @@ -345,7 +345,6 @@ class LedgerImpl : public ledger::Ledger,
uint64_t retryRequestSetup(uint64_t min_time, uint64_t max_time);

void OnPublisherInfoSavedInternal(
uint64_t window_id,
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info);

Expand Down

0 comments on commit 198e3b2

Please sign in to comment.