From 198e3b2eb157b1ec44ebb43247b7ff6a43145445 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Mon, 28 Jan 2019 06:54:41 +0100 Subject: [PATCH] Address review comments --- browser/ui/webui/brave_rewards_ui.cc | 4 ++-- .../brave_rewards/browser/content_site.h | 5 +++++ .../browser/rewards_service_impl.cc | 18 +++++++----------- .../browser/rewards_service_impl.h | 2 +- .../browser/rewards_service_observer.h | 2 +- .../include/bat/ledger/ledger.h | 4 ++-- .../include/bat/ledger/publisher_info.h | 2 +- .../bat-native-ledger/src/bat/ledger/ledger.cc | 4 ++-- vendor/bat-native-ledger/src/bat_helper.cc | 2 +- vendor/bat-native-ledger/src/bat_publishers.cc | 3 +-- vendor/bat-native-ledger/src/bat_publishers.h | 1 - vendor/bat-native-ledger/src/ledger_impl.cc | 10 +++------- vendor/bat-native-ledger/src/ledger_impl.h | 5 ++--- 13 files changed, 28 insertions(+), 34 deletions(-) diff --git a/browser/ui/webui/brave_rewards_ui.cc b/browser/ui/webui/brave_rewards_ui.cc index add41df80ef5..0d245430d7bc 100644 --- a/browser/ui/webui/brave_rewards_ui.cc +++ b/browser/ui/webui/brave_rewards_ui.cc @@ -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; @@ -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 site_list( diff --git a/components/brave_rewards/browser/content_site.h b/components/brave_rewards/browser/content_site.h index 50fbfe119e03..13e5a205d950 100644 --- a/components/brave_rewards/browser/content_site.h +++ b/components/brave_rewards/browser/content_site.h @@ -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; diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 48c284992524..6d418dc6d124 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -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 empty_list( new ledger::PublisherInfoList); - OnNormalizedPublisherListSaved(std::move(empty_list)); + OnPublisherListNormalizedSaved(std::move(empty_list)); return; } @@ -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 list) { if (!list) { LOG(ERROR) << "Problem saving normalized publishers " @@ -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); } } diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index eda1112fdc07..cb3801442064 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -340,7 +340,7 @@ class RewardsServiceImpl : public RewardsService, void SaveNormalizedPublisherList( const ledger::PublisherInfoListStruct& list) override; - void OnNormalizedPublisherListSaved( + void OnPublisherListNormalizedSaved( std::unique_ptr list); // URLFetcherDelegate impl diff --git a/components/brave_rewards/browser/rewards_service_observer.h b/components/brave_rewards/browser/rewards_service_observer.h index 7d58fc47f893..ed1967ec334a 100644 --- a/components/brave_rewards/browser/rewards_service_observer.h +++ b/components/brave_rewards/browser/rewards_service_observer.h @@ -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 diff --git a/vendor/bat-native-ledger/include/bat/ledger/ledger.h b/vendor/bat-native-ledger/include/bat/ledger/ledger.h index 507ba5efe535..e7a4707b3a0d 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -120,8 +120,8 @@ class LEDGER_EXPORT Ledger { virtual std::string URIEncode(const std::string& value) = 0; - virtual void SetPublisherInfo(std::unique_ptr publisher_info, - uint64_t window_id) = 0; + virtual void SetPublisherInfo( + std::unique_ptr publisher_info) = 0; virtual void SetActivityInfo( std::unique_ptr publisher_info) = 0; virtual void GetPublisherInfo(const std::string& publisher_key, diff --git a/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h b/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h index cc737aa67c43..3c50c5f54562 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h +++ b/vendor/bat-native-ledger/include/bat/ledger/publisher_info.h @@ -145,7 +145,7 @@ LEDGER_EXPORT struct PublisherInfoListStruct { const std::string ToJson() const; bool loadFromJson(const std::string& json); - std::vector list_; + std::vector list; }; using PublisherInfoList = std::vector; diff --git a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc index 3183fe0bd603..20eca221ee0a 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -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 { @@ -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); } } diff --git a/vendor/bat-native-ledger/src/bat_helper.cc b/vendor/bat-native-ledger/src/bat_helper.cc index ea1ac34a1643..09b6f0950ef0 100644 --- a/vendor/bat-native-ledger/src/bat_helper.cc +++ b/vendor/bat-native-ledger/src/bat_helper.cc @@ -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(); diff --git a/vendor/bat-native-ledger/src/bat_publishers.cc b/vendor/bat-native-ledger/src/bat_publishers.cc index d94957af8744..9b92e4c92f03 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.cc +++ b/vendor/bat-native-ledger/src/bat_publishers.cc @@ -313,7 +313,6 @@ void BatPublishers::onFetchFavIconDBResponse( } void BatPublishers::OnPublisherInfoSaved( - uint64_t window_id, ledger::Result result, std::unique_ptr info) { if (result != ledger::Result::LEDGER_OK || !info.get()) { @@ -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); } diff --git a/vendor/bat-native-ledger/src/bat_publishers.h b/vendor/bat-native-ledger/src/bat_publishers.h index 21ece9f23c30..7f32fbe0de68 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.h +++ b/vendor/bat-native-ledger/src/bat_publishers.h @@ -74,7 +74,6 @@ class BatPublishers : public ledger::LedgerCallbackHandler { bool getPublisherAllowVideos() const; void OnPublisherInfoSaved( - uint64_t window_id, ledger::Result result, std::unique_ptr); std::string GetBalanceReportName(ledger::ACTIVITY_MONTH month, int year); diff --git a/vendor/bat-native-ledger/src/ledger_impl.cc b/vendor/bat-native-ledger/src/ledger_impl.cc index 28d06ebc21ee..7e5db2e15470 100644 --- a/vendor/bat-native-ledger/src/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/ledger_impl.cc @@ -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 info) { - bat_publishers_->OnPublisherInfoSaved(window_id, result, std::move(info)); + bat_publishers_->OnPublisherInfoSaved(result, std::move(info)); } -void LedgerImpl::SetPublisherInfo(std::unique_ptr info, - uint64_t window_id) { +void LedgerImpl::SetPublisherInfo(std::unique_ptr info) { ledger_client_->SavePublisherInfo( std::move(info), std::bind(&LedgerImpl::OnPublisherInfoSavedInternal, this, - window_id, _1, _2)); } @@ -324,7 +321,6 @@ void LedgerImpl::SetActivityInfo(std::unique_ptr info) { std::move(info), std::bind(&LedgerImpl::OnPublisherInfoSavedInternal, this, - 0, _1, _2)); } @@ -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); } diff --git a/vendor/bat-native-ledger/src/ledger_impl.h b/vendor/bat-native-ledger/src/ledger_impl.h index eb66c0b3aeb8..c565a526b6a5 100644 --- a/vendor/bat-native-ledger/src/ledger_impl.h +++ b/vendor/bat-native-ledger/src/ledger_impl.h @@ -54,8 +54,8 @@ class LedgerImpl : public ledger::Ledger, void Initialize() override; bool CreateWallet() override; - void SetPublisherInfo(std::unique_ptr publisher_info, - uint64_t window_id = 0) override; + void SetPublisherInfo( + std::unique_ptr publisher_info) override; void SetActivityInfo( std::unique_ptr publisher_info) override; void GetPublisherInfo(const std::string& publisher_key, @@ -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 info);