Commit e5154663 authored by Michael Lippautz's avatar Michael Lippautz Committed by Chromium LUCI CQ

ContentCaptureTask: Remove dynamic allocation of timer task

A past refactoring translated `unique_ptr<TaskRunnerTimer>` to
`Member<DisallowNewWrapper<HeapTaskRunnerTimer>>` to preserve
semantics. Inline HeapTaskRunnerTimer which avoids a dynamic
allocation.

Change-Id: Id3c788c3dedab1dbf3022e0d8ebe5dfca47235b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2640373
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845772}
parent c61c894f
...@@ -46,7 +46,12 @@ void ContentCaptureTask::TaskDelay::IncreaseDelayExponent() { ...@@ -46,7 +46,12 @@ void ContentCaptureTask::TaskDelay::IncreaseDelayExponent() {
ContentCaptureTask::ContentCaptureTask(LocalFrame& local_frame_root, ContentCaptureTask::ContentCaptureTask(LocalFrame& local_frame_root,
TaskSession& task_session) TaskSession& task_session)
: local_frame_root_(&local_frame_root), task_session_(&task_session) { : local_frame_root_(&local_frame_root),
task_session_(&task_session),
delay_task_(
local_frame_root_->GetTaskRunner(TaskType::kInternalContentCapture),
this,
&ContentCaptureTask::Run) {
base::TimeDelta task_short_delay; base::TimeDelta task_short_delay;
base::TimeDelta task_long_delay; base::TimeDelta task_long_delay;
...@@ -268,23 +273,14 @@ void ContentCaptureTask::ScheduleInternal(ScheduleReason reason) { ...@@ -268,23 +273,14 @@ void ContentCaptureTask::ScheduleInternal(ScheduleReason reason) {
base::TimeDelta delay = GetAndAdjustDelay(reason); base::TimeDelta delay = GetAndAdjustDelay(reason);
// Return if the current task is about to run soon. // Return if the current task is about to run soon.
if (delay_task_ && delay_task_->Value().IsActive() && if (delay_task_.IsActive() && delay_task_.NextFireInterval() < delay) {
delay_task_->Value().NextFireInterval() < delay) {
return; return;
} }
if (!delay_task_) { if (delay_task_.IsActive())
scoped_refptr<base::SingleThreadTaskRunner> task_runner = delay_task_.Stop();
local_frame_root_->GetTaskRunner(TaskType::kInternalContentCapture);
delay_task_ = MakeGarbageCollected<
DisallowNewWrapper<HeapTaskRunnerTimer<ContentCaptureTask>>>(
task_runner, this, &ContentCaptureTask::Run);
}
if (delay_task_->Value().IsActive())
delay_task_->Value().Stop();
delay_task_->Value().StartOneShot(delay, FROM_HERE); delay_task_.StartOneShot(delay, FROM_HERE);
TRACE_EVENT_INSTANT1("content_capture", "ScheduleTask", TRACE_EVENT_INSTANT1("content_capture", "ScheduleTask",
TRACE_EVENT_SCOPE_THREAD, "reason", reason); TRACE_EVENT_SCOPE_THREAD, "reason", reason);
if (histogram_reporter_) { if (histogram_reporter_) {
...@@ -309,17 +305,16 @@ bool ContentCaptureTask::ShouldPause() { ...@@ -309,17 +305,16 @@ bool ContentCaptureTask::ShouldPause() {
} }
void ContentCaptureTask::CancelTask() { void ContentCaptureTask::CancelTask() {
if (delay_task_ && delay_task_->Value().IsActive()) if (delay_task_.IsActive())
delay_task_->Value().Stop(); delay_task_.Stop();
} }
void ContentCaptureTask::ClearDocumentSessionsForTesting() { void ContentCaptureTask::ClearDocumentSessionsForTesting() {
task_session_->ClearDocumentSessionsForTesting(); task_session_->ClearDocumentSessionsForTesting();
} }
base::TimeDelta ContentCaptureTask::GetTaskNextFireIntervalForTesting() const { base::TimeDelta ContentCaptureTask::GetTaskNextFireIntervalForTesting() const {
return delay_task_ && delay_task_->Value().IsActive() return delay_task_.IsActive() ? delay_task_.NextFireInterval()
? delay_task_->Value().NextFireInterval() : base::TimeDelta();
: base::TimeDelta();
} }
void ContentCaptureTask::CancelTaskForTesting() { void ContentCaptureTask::CancelTaskForTesting() {
......
...@@ -143,8 +143,7 @@ class CORE_EXPORT ContentCaptureTask ...@@ -143,8 +143,7 @@ class CORE_EXPORT ContentCaptureTask
Member<LocalFrame> local_frame_root_; Member<LocalFrame> local_frame_root_;
Member<TaskSession> task_session_; Member<TaskSession> task_session_;
Member<DisallowNewWrapper<HeapTaskRunnerTimer<ContentCaptureTask>>> HeapTaskRunnerTimer<ContentCaptureTask> delay_task_;
delay_task_;
TaskState task_state_ = TaskState::kStop; TaskState task_state_ = TaskState::kStop;
std::unique_ptr<TaskDelay> task_delay_; std::unique_ptr<TaskDelay> task_delay_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment