Index: third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h |
diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h b/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h |
index 5456885502643b75ed5433ce35bdb1e43dc2d110..fcf22f3026bd7261f797579dfc5eded43d033c09 100644 |
--- a/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h |
+++ b/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ |
-#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ |
+#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTLER_H_ |
+#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTLER_H_ |
#include <set> |
#include <unordered_map> |
@@ -16,11 +16,19 @@ |
#include "platform/scheduler/base/time_domain.h" |
#include "public/platform/WebViewScheduler.h" |
+namespace base { |
+namespace trace_event { |
+class TracedValue; |
+} |
+} |
+ |
namespace blink { |
namespace scheduler { |
+class BudgetPool; |
class RendererSchedulerImpl; |
class ThrottledTimeDomain; |
+class TimeBudgetPool; |
// The job of the TaskQueueThrottler is to control when tasks posted on |
// throttled queues get run. The TaskQueueThrottler: |
@@ -46,117 +54,6 @@ class ThrottledTimeDomain; |
// This class is main-thread only. |
class BLINK_PLATFORM_EXPORT TaskQueueThrottler : public TimeDomain::Observer { |
public: |
- // TimeBudgetPool represents a group of task queues which share a limit |
- // on execution time. This limit applies when task queues are already |
- // throttled by TaskQueueThrottler. |
- class BLINK_PLATFORM_EXPORT TimeBudgetPool { |
- public: |
- ~TimeBudgetPool(); |
- |
- // Throttle task queues from this time budget pool if tasks are running |
- // for more than |cpu_percentage| per cent of wall time. |
- // This function does not affect internal time budget level. |
- void SetTimeBudgetRecoveryRate(base::TimeTicks now, double cpu_percentage); |
- |
- // Adds |queue| to given pool. If the pool restriction does not allow |
- // a task to be run immediately and |queue| is throttled, |queue| becomes |
- // disabled. |
- void AddQueue(base::TimeTicks now, TaskQueue* queue); |
- |
- // Removes |queue| from given pool. If it is throttled, it does not |
- // become enabled immediately, but a call to |PumpThrottledTasks| |
- // is scheduled. |
- void RemoveQueue(base::TimeTicks now, TaskQueue* queue); |
- |
- void RecordTaskRunTime(base::TimeTicks start_time, |
- base::TimeTicks end_time); |
- |
- // Enables this time budget pool. Queues from this pool will be |
- // throttled based on their run time. |
- void EnableThrottling(LazyNow* now); |
- |
- // Disables with time budget pool. Queues from this pool will not be |
- // throttled based on their run time. A call to |PumpThrottledTasks| |
- // will be scheduled to enable this queues back again and respect |
- // timer alignment. Internal budget level will not regenerate with time. |
- void DisableThrottling(LazyNow* now); |
- |
- bool IsThrottlingEnabled() const; |
- |
- // Increase budget level by given value. This function DOES NOT unblock |
- // queues even if they are allowed to run with increased budget level. |
- void GrantAdditionalBudget(base::TimeTicks now, |
- base::TimeDelta budget_level); |
- |
- const char* Name() const; |
- |
- // Set callback which will be called every time when this budget pool |
- // is throttled. Throttling duration (time until the queue is allowed |
- // to run again) is passed as a parameter to callback. |
- void SetReportingCallback( |
- base::Callback<void(base::TimeDelta)> reporting_callback); |
- |
- // All queues should be removed before calling Close(). |
- void Close(); |
- |
- private: |
- friend class TaskQueueThrottler; |
- |
- FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, TimeBudgetPool); |
- |
- TimeBudgetPool(const char* name, |
- TaskQueueThrottler* task_queue_throttler, |
- base::TimeTicks now, |
- base::Optional<base::TimeDelta> max_budget_level, |
- base::Optional<base::TimeDelta> max_throttling_duration); |
- |
- bool HasEnoughBudgetToRun(base::TimeTicks now); |
- base::TimeTicks GetNextAllowedRunTime(); |
- |
- // Advances |last_checkpoint_| to |now| if needed and recalculates |
- // budget level. |
- void Advance(base::TimeTicks now); |
- |
- // Returns state for tracing. |
- void AsValueInto(base::trace_event::TracedValue* state, |
- base::TimeTicks now) const; |
- |
- // Disable all associated throttled queues. |
- void BlockThrottledQueues(base::TimeTicks now); |
- |
- // Increase |current_budget_level_| to satisfy max throttling duration |
- // condition if necessary. |
- // Decrease |current_budget_level_| to satisfy max budget level |
- // condition if necessary. |
- void EnforceBudgetLevelRestrictions(); |
- |
- const char* name_; // NOT OWNED |
- |
- TaskQueueThrottler* task_queue_throttler_; |
- |
- // Max budget level which we can accrue. |
- // Tasks will be allowed to run for this time before being throttled |
- // after a very long period of inactivity. |
- base::Optional<base::TimeDelta> max_budget_level_; |
- // Max throttling duration places a lower limit on time budget level, |
- // ensuring that one long task does not cause extremely long throttling. |
- // Note that this is not the guarantee that every task will run |
- // after desired run time + max throttling duration, but a guarantee |
- // that at least one task will be run every max_throttling_duration. |
- base::Optional<base::TimeDelta> max_throttling_duration_; |
- |
- base::TimeDelta current_budget_level_; |
- base::TimeTicks last_checkpoint_; |
- double cpu_percentage_; |
- bool is_enabled_; |
- |
- std::unordered_set<TaskQueue*> associated_task_queues_; |
- |
- base::Callback<void(base::TimeDelta)> reporting_callback_; |
- |
- DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool); |
- }; |
- |
// TODO(altimin): Do not pass tracing category as const char*, |
// hard-code string instead. |
TaskQueueThrottler(RendererSchedulerImpl* renderer_scheduler, |
@@ -213,6 +110,9 @@ class BLINK_PLATFORM_EXPORT TaskQueueThrottler : public TimeDomain::Observer { |
base::TimeTicks now) const; |
private: |
+ friend class BudgetPool; |
Sami
2017/03/08 16:18:01
I guess these will be removed later?
altimin
2017/03/08 16:50:33
Yep, the comment in the patch description.
|
+ friend class TimeBudgetPool; |
+ |
struct Metadata { |
Metadata() : throttling_ref_count(0), time_budget_pool(nullptr) {} |
@@ -259,7 +159,7 @@ class BLINK_PLATFORM_EXPORT TaskQueueThrottler : public TimeDomain::Observer { |
base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; |
bool allow_throttling_; |
- std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>> |
+ std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> |
time_budget_pools_; |
base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; |
@@ -270,4 +170,4 @@ class BLINK_PLATFORM_EXPORT TaskQueueThrottler : public TimeDomain::Observer { |
} // namespace scheduler |
} // namespace blink |
-#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_H_ |
+#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTLER_H_ |