Skip to content

Commit 100ab8e

Browse files
committed
Fixes high CPU usage while Brave ads is enabled
1 parent 30990cb commit 100ab8e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

vendor/bat-native-ads/src/bat/ads/internal/ad_serving/ad_notifications/ad_notification_serving.cc

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ void AdServing::StopServingAdsAtRegularIntervals() {
9797
}
9898

9999
void AdServing::MaybeServeAd() {
100+
if (is_serving_) {
101+
return;
102+
}
103+
104+
is_serving_ = true;
105+
100106
frequency_capping::PermissionRules permission_rules;
101107
if (!permission_rules.HasPermission()) {
102108
BLOG(1, "Ad notification not served: Not allowed due to permission rules");
@@ -281,6 +287,8 @@ bool AdServing::ServeAd(
281287
}
282288

283289
void AdServing::FailedToServeAd() {
290+
is_serving_ = false;
291+
284292
NotifyFailedToServeAdNotification();
285293

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

301+
is_serving_ = false;
302+
293303
MaybeServeAdAtNextRegularInterval();
294304
}
295305

vendor/bat-native-ads/src/bat/ads/internal/ad_serving/ad_notifications/ad_notification_serving.h

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class AdServing final {
5656
void OnAdsPerHourChanged();
5757

5858
private:
59+
bool is_serving_ = false;
60+
5961
Timer timer_;
6062

6163
std::unique_ptr<EligibleAds> eligible_ads_;

vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ void AdsImpl::OnUnIdle(const int idle_time, const bool was_locked) {
214214
return;
215215
}
216216

217-
auto unidle_timestamp_diagnostics =
217+
auto last_unidle_timestamp_diagnostics =
218218
std::make_unique<LastUnIdleTimestampAdDiagnosticsEntry>();
219-
unidle_timestamp_diagnostics->SetLastUnIdleTimestamp(base::Time::Now());
219+
last_unidle_timestamp_diagnostics->SetLastUnIdleTimestamp(base::Time::Now());
220220
AdDiagnostics::Get()->SetDiagnosticsEntry(
221-
std::move(unidle_timestamp_diagnostics));
221+
std::move(last_unidle_timestamp_diagnostics));
222222

223223
MaybeUpdateIdleTimeThreshold();
224224

0 commit comments

Comments
 (0)