Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(897)

Unified Diff: third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc

Issue 2476973002: [scheduler] Report background timer throttling intervention. (Closed)
Patch Set: base::Optional<base::Callback> -> base::Callback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc b/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
index f7ba68c71c706abc2f5cb8692294400ea498420e..d2403b3bc5b226e736c948f5eecf4fe69b778ace 100644
--- a/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
+++ b/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
@@ -5,6 +5,7 @@
#include "platform/scheduler/renderer/web_view_scheduler_impl.h"
#include "base/logging.h"
+#include "base/strings/stringprintf.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/scheduler/base/virtual_time_domain.h"
#include "platform/scheduler/child/scheduler_tqm_delegate.h"
@@ -19,6 +20,10 @@ namespace scheduler {
namespace {
const double kBackgroundBudgetAsCPUFraction = .01;
+// Given that we already align timers to 1Hz, do not report throttling if
+// it is under 3s.
+constexpr base::TimeDelta kMinimalBackgroundThrottlingDurationToReport =
+ base::TimeDelta::FromSeconds(3);
} // namespace
@@ -36,6 +41,7 @@ WebViewSchedulerImpl::WebViewSchedulerImpl(
have_seen_loading_task_(false),
virtual_time_(false),
is_audio_playing_(false),
+ reported_background_throttling_since_navigation_(false),
background_time_budget_pool_(nullptr) {
renderer_scheduler->AddWebViewScheduler(this);
@@ -106,6 +112,10 @@ void WebViewSchedulerImpl::Unregister(WebFrameSchedulerImpl* frame_scheduler) {
frame_schedulers_.erase(frame_scheduler);
}
+void WebViewSchedulerImpl::OnNavigation() {
+ reported_background_throttling_since_navigation_ = false;
+}
+
void WebViewSchedulerImpl::ReportIntervention(const std::string& message) {
intervention_reporter_->ReportIntervention(WebString::fromUTF8(message));
}
@@ -198,5 +208,25 @@ bool WebViewSchedulerImpl::IsAudioPlaying() const {
return is_audio_playing_;
}
+void WebViewSchedulerImpl::OnThrottlingReported(
+ base::TimeDelta throttling_duration) {
+ if (throttling_duration < kMinimalBackgroundThrottlingDurationToReport)
+ return;
+
+ if (reported_background_throttling_since_navigation_)
+ return;
+ reported_background_throttling_since_navigation_ = true;
+
+ std::string message = base::StringPrintf(
+ "Timer tasks have taken too much time while the page was in the "
+ "background. "
+ "As a result, they have been deferred for %.3f seconds. "
+ "See https://www.chromestatus.com/feature/6172836527865856 "
+ "for more details",
+ throttling_duration.InSecondsF());
+
+ intervention_reporter_->ReportIntervention(WebString::fromUTF8(message));
+}
+
} // namespace scheduler
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698