Skip to content

Fixes high CPU usage while Brave ads is enabled #10372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ void AdServing::StopServingAdsAtRegularIntervals() {
}

void AdServing::MaybeServeAd() {
if (is_serving_) {
return;
}

is_serving_ = true;

frequency_capping::PermissionRules permission_rules;
if (!permission_rules.HasPermission()) {
BLOG(1, "Ad notification not served: Not allowed due to permission rules");
Expand Down Expand Up @@ -281,6 +287,8 @@ bool AdServing::ServeAd(
}

void AdServing::FailedToServeAd() {
is_serving_ = false;

NotifyFailedToServeAdNotification();

RetryServingAdAtNextInterval();
Expand All @@ -290,6 +298,8 @@ void AdServing::ServedAd(
const CreativeAdNotificationInfo& creative_ad_notification) {
eligible_ads_->SetLastServedAd(creative_ad_notification);

is_serving_ = false;

MaybeServeAdAtNextRegularInterval();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class AdServing final {
void OnAdsPerHourChanged();

private:
bool is_serving_ = false;

Timer timer_;

std::unique_ptr<EligibleAds> eligible_ads_;
Expand Down
6 changes: 3 additions & 3 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ void AdsImpl::OnUnIdle(const int idle_time, const bool was_locked) {
return;
}

auto unidle_timestamp_diagnostics =
auto last_unidle_timestamp_diagnostics =
std::make_unique<LastUnIdleTimestampAdDiagnosticsEntry>();
unidle_timestamp_diagnostics->SetLastUnIdleTimestamp(base::Time::Now());
last_unidle_timestamp_diagnostics->SetLastUnIdleTimestamp(base::Time::Now());
AdDiagnostics::Get()->SetDiagnosticsEntry(
std::move(unidle_timestamp_diagnostics));
std::move(last_unidle_timestamp_diagnostics));

MaybeUpdateIdleTimeThreshold();

Expand Down