Skip to content

Commit

Permalink
Optimizies publisher list timers
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 24, 2020
1 parent f8305a2 commit 0ff82f9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
5 changes: 2 additions & 3 deletions components/brave_rewards/browser/static_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const std::vector<std::string> kOnlyAnonWalletCountries = {

const std::map<std::string, uint64_t> kUInt64Options = {
{ledger::kOptionPublisherListRefreshInterval,
7* base::Time::kHoursPerDay * base::Time::kSecondsPerHour}
7* base::Time::kHoursPerDay * base::Time::kSecondsPerHour}};
#else
const std::map<std::string, bool> kBoolOptions = {};

Expand All @@ -48,9 +48,8 @@ const std::vector<std::string> kOnlyAnonWalletCountries = {

const std::map<std::string, uint64_t> kUInt64Options = {
{ledger::kOptionPublisherListRefreshInterval,
3 * base::Time::kHoursPerDay * base::Time::kSecondsPerHour}
3 * base::Time::kHoursPerDay * base::Time::kSecondsPerHour}};
#endif
};

} // namespace brave_rewards

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void LedgerImpl::OnWalletInitializedInternal(
if (result == ledger::Result::LEDGER_OK ||
result == ledger::Result::WALLET_CREATED) {
initialized_ = true;
bat_publisher_->SetPublisherServerListTimer();
bat_publisher_->SetPublisherServerListTimer(GetRewardsMainEnabled());
bat_contribution_->SetReconcileTimer();
bat_promotion_->Refresh(false);
bat_contribution_->Initialize();
Expand Down Expand Up @@ -602,6 +602,7 @@ void LedgerImpl::GetExcludedList(ledger::PublisherInfoListCallback callback) {

void LedgerImpl::SetRewardsMainEnabled(bool enabled) {
bat_state_->SetRewardsMainEnabled(enabled);
bat_publisher_->SetPublisherServerListTimer(enabled);
}

void LedgerImpl::SetPublisherMinVisitTime(uint64_t duration) { // In seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ void Publisher::OnRefreshPublisherServerPublisher(
callback(status);
}

void Publisher::SetPublisherServerListTimer() {
void Publisher::SetPublisherServerListTimer(const bool rewards_enabled) {
if (!rewards_enabled) {
server_list_->ClearTimer();
return;
}

server_list_->SetTimer(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Publisher {
const std::string& publisher_key,
ledger::OnRefreshPublisherCallback callback);

void SetPublisherServerListTimer();
void SetPublisherServerListTimer(const bool rewards_enabled);

bool loadState(const std::string& data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,8 @@ void PublisherServerList::SaveBanners(
ledger_->InsertPublisherBannerList(save_list, save_callback);
}

void PublisherServerList::ClearTimer() {
server_list_timer_id_ = 0;
}

} // namespace braveledger_publisher
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class PublisherServerList {

void SetTimer(bool retry_after_error);

void ClearTimer();

private:
void OnDownload(
int response_status_code,
Expand Down

0 comments on commit 0ff82f9

Please sign in to comment.