Commit aaa47c0d authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[scheduler] Make scheduler mostly conform to Blink style

After patch 954622 blink style checker started checking scheduler code.
Make scheduler code mostly conform to this standard.

Add exception for readability/control_flow as in many places scheduler
code is easier to read without it.

R=dcheng@chromium.org
CC=tkent@chromium.org

Change-Id: I167ad10f089f56fd3e86d41f2a6aa07b23801557
Reviewed-on: https://chromium-review.googlesource.com/964641
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543689}
parent 3b82f40b
...@@ -58,7 +58,7 @@ TaskQueueImpl::~TaskQueueImpl() { ...@@ -58,7 +58,7 @@ TaskQueueImpl::~TaskQueueImpl() {
// contains a strong reference to this TaskQueueImpl and the // contains a strong reference to this TaskQueueImpl and the
// TaskQueueManagerImpl destructor calls UnregisterTaskQueue on all task // TaskQueueManagerImpl destructor calls UnregisterTaskQueue on all task
// queues. // queues.
DCHECK(any_thread().task_queue_manager == nullptr) DCHECK(!any_thread().task_queue_manager)
<< "UnregisterTaskQueue must be called first!"; << "UnregisterTaskQueue must be called first!";
DCHECK(main_thread_only().on_task_started_handler.is_null()); DCHECK(main_thread_only().on_task_started_handler.is_null());
DCHECK(main_thread_only().on_task_completed_handler.is_null()); DCHECK(main_thread_only().on_task_completed_handler.is_null());
...@@ -993,9 +993,10 @@ void TaskQueueImpl::OnTaskCompleted( ...@@ -993,9 +993,10 @@ void TaskQueueImpl::OnTaskCompleted(
base::TimeTicks start, base::TimeTicks start,
base::TimeTicks end, base::TimeTicks end,
base::Optional<base::TimeDelta> thread_time) { base::Optional<base::TimeDelta> thread_time) {
if (!main_thread_only().on_task_completed_handler.is_null()) if (!main_thread_only().on_task_completed_handler.is_null()) {
main_thread_only().on_task_completed_handler.Run(task, start, end, main_thread_only().on_task_completed_handler.Run(task, start, end,
thread_time); thread_time);
}
} }
bool TaskQueueImpl::RequiresTaskTiming() const { bool TaskQueueImpl::RequiresTaskTiming() const {
......
...@@ -465,11 +465,12 @@ void TaskQueueManagerImpl::NotifyDidProcessTask( ...@@ -465,11 +465,12 @@ void TaskQueueManagerImpl::NotifyDidProcessTask(
{ {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
"TaskQueueManager.QueueOnTaskCompleted"); "TaskQueueManager.QueueOnTaskCompleted");
if (task_start_time_sec && task_end_time_sec) if (task_start_time_sec && task_end_time_sec) {
executing_task.task_queue->OnTaskCompleted( executing_task.task_queue->OnTaskCompleted(
executing_task.pending_task, executing_task.task_start_time, executing_task.pending_task, executing_task.task_start_time,
time_after_task->Now(), time_after_task->Now(),
task_end_thread_time - executing_task.task_start_thread_time); task_end_thread_time - executing_task.task_start_thread_time);
}
} }
if (task_start_time_sec && task_end_time_sec && if (task_start_time_sec && task_end_time_sec &&
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORKER_CONTROLLER_H_ #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_THREAD_CONTROLLER_H_
#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORKER_CONTROLLER_H_ #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_THREAD_CONTROLLER_H_
#include "base/location.h" #include "base/location.h"
#include "base/run_loop.h" #include "base/run_loop.h"
...@@ -91,4 +91,4 @@ class PLATFORM_EXPORT ThreadController { ...@@ -91,4 +91,4 @@ class PLATFORM_EXPORT ThreadController {
} // namespace scheduler } // namespace scheduler
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORKER_CONTROLLER_H_ #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_THREAD_CONTROLLER_H_
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORKER_CONTROLLER_IMPL_H_ #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_THREAD_CONTROLLER_IMPL_H_
#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORKER_CONTROLLER_IMPL_H_ #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_THREAD_CONTROLLER_IMPL_H_
#include "platform/scheduler/base/thread_controller.h" #include "platform/scheduler/base/thread_controller.h"
...@@ -129,4 +129,4 @@ class PLATFORM_EXPORT ThreadControllerImpl ...@@ -129,4 +129,4 @@ class PLATFORM_EXPORT ThreadControllerImpl
} // namespace scheduler } // namespace scheduler
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_WORKER_CONTROLLER_IMPL_H_ #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_THREAD_CONTROLLER_IMPL_H_
...@@ -93,13 +93,11 @@ IdleHelper::IdlePeriodState IdleHelper::ComputeNewLongIdlePeriodState( ...@@ -93,13 +93,11 @@ IdleHelper::IdlePeriodState IdleHelper::ComputeNewLongIdlePeriodState(
if (long_idle_period_duration >= if (long_idle_period_duration >=
base::TimeDelta::FromMilliseconds(kMinimumIdlePeriodDurationMillis)) { base::TimeDelta::FromMilliseconds(kMinimumIdlePeriodDurationMillis)) {
*next_long_idle_period_delay_out = long_idle_period_duration; *next_long_idle_period_delay_out = long_idle_period_duration;
if (!idle_queue_->HasTaskToRunImmediately()) { if (!idle_queue_->HasTaskToRunImmediately())
return IdlePeriodState::kInLongIdlePeriodPaused; return IdlePeriodState::kInLongIdlePeriodPaused;
} else if (long_idle_period_duration == max_long_idle_period_duration) { if (long_idle_period_duration == max_long_idle_period_duration)
return IdlePeriodState::kInLongIdlePeriodWithMaxDeadline; return IdlePeriodState::kInLongIdlePeriodWithMaxDeadline;
} else { return IdlePeriodState::kInLongIdlePeriod;
return IdlePeriodState::kInLongIdlePeriod;
}
} else { } else {
// If we can't start the idle period yet then try again after wake-up. // If we can't start the idle period yet then try again after wake-up.
*next_long_idle_period_delay_out = base::TimeDelta::FromMilliseconds( *next_long_idle_period_delay_out = base::TimeDelta::FromMilliseconds(
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_PAGE_VISIBILITY_STATE_H_ #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_PAGE_VISIBILITY_STATE_H_
#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_PAGE_VISIBILITY_STATE_H_ #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_PAGE_VISIBILITY_STATE_H_
namespace blink { namespace blink {
namespace scheduler { namespace scheduler {
...@@ -16,4 +16,4 @@ const char* PageVisibilityStateToString(PageVisibilityState visibility); ...@@ -16,4 +16,4 @@ const char* PageVisibilityStateToString(PageVisibilityState visibility);
} // namespace scheduler } // namespace scheduler
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_PAGE_VISIBILITY_STATE_H_ #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_PAGE_VISIBILITY_STATE_H_
...@@ -15,5 +15,5 @@ void PollableThreadSafeFlag::SetWhileLocked(bool value) { ...@@ -15,5 +15,5 @@ void PollableThreadSafeFlag::SetWhileLocked(bool value) {
} }
bool PollableThreadSafeFlag::IsSet() const { bool PollableThreadSafeFlag::IsSet() const {
return base::subtle::Acquire_Load(&flag_) != false; return base::subtle::Acquire_Load(&flag_);
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_WEB_SCHEDULER_H_ #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_WEB_SCHEDULER_H_
#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_WEB_SCHEDULER_H_ #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_WEB_SCHEDULER_H_
#include <memory> #include <memory>
#include "base/location.h" #include "base/location.h"
...@@ -100,4 +100,4 @@ class PLATFORM_EXPORT WebScheduler { ...@@ -100,4 +100,4 @@ class PLATFORM_EXPORT WebScheduler {
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_WEB_SCHEDULER_H_ #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_WEB_SCHEDULER_H_
...@@ -91,14 +91,11 @@ base::Optional<base::TimeTicks> CPUTimeBudgetPool::GetTimeTasksCanRunUntil( ...@@ -91,14 +91,11 @@ base::Optional<base::TimeTicks> CPUTimeBudgetPool::GetTimeTasksCanRunUntil(
base::TimeTicks CPUTimeBudgetPool::GetNextAllowedRunTime( base::TimeTicks CPUTimeBudgetPool::GetNextAllowedRunTime(
base::TimeTicks desired_run_time) const { base::TimeTicks desired_run_time) const {
if (!is_enabled_ || current_budget_level_->InMicroseconds() >= 0) { if (!is_enabled_ || current_budget_level_->InMicroseconds() >= 0)
return last_checkpoint_; return last_checkpoint_;
} else { // Subtract because current_budget is negative.
// Subtract because current_budget is negative. return last_checkpoint_ +
return last_checkpoint_ + (-current_budget_level_ + min_budget_level_to_run_) / cpu_percentage_;
(-current_budget_level_ + min_budget_level_to_run_) /
cpu_percentage_;
}
} }
void CPUTimeBudgetPool::RecordTaskRunTime(TaskQueue* queue, void CPUTimeBudgetPool::RecordTaskRunTime(TaskQueue* queue,
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_METRICS_H_ #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_FRAME_STATUS_H_
#define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_METRICS_H_ #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_FRAME_STATUS_H_
#include "platform/PlatformExport.h" #include "platform/PlatformExport.h"
...@@ -82,4 +82,4 @@ PLATFORM_EXPORT FrameStatus GetFrameStatus(WebFrameScheduler* frame_scheduler); ...@@ -82,4 +82,4 @@ PLATFORM_EXPORT FrameStatus GetFrameStatus(WebFrameScheduler* frame_scheduler);
} // namespace scheduler } // namespace scheduler
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_METRICS_H_ #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_FRAME_STATUS_H_
...@@ -93,15 +93,11 @@ bool UserModel::IsGestureExpectedSoonImpl( ...@@ -93,15 +93,11 @@ bool UserModel::IsGestureExpectedSoonImpl(
const base::TimeTicks now, const base::TimeTicks now,
base::TimeDelta* prediction_valid_duration) const { base::TimeDelta* prediction_valid_duration) const {
if (is_gesture_active_) { if (is_gesture_active_) {
if (IsGestureExpectedToContinue(now, prediction_valid_duration)) { if (IsGestureExpectedToContinue(now, prediction_valid_duration))
return false; return false;
} else { *prediction_valid_duration =
// If a gesture is not expected to continue then we expect a subsequent base::TimeDelta::FromMilliseconds(kExpectSubsequentGestureMillis);
// gesture soon. return true;
*prediction_valid_duration =
base::TimeDelta::FromMilliseconds(kExpectSubsequentGestureMillis);
return true;
}
} else { } else {
// If we've have a finished a gesture then a subsequent gesture is deemed // If we've have a finished a gesture then a subsequent gesture is deemed
// likely. // likely.
......
...@@ -462,9 +462,10 @@ void WebFrameSchedulerImpl::AsValueInto( ...@@ -462,9 +462,10 @@ void WebFrameSchedulerImpl::AsValueInto(
state->SetString("loading_control_task_queue", state->SetString("loading_control_task_queue",
PointerToString(loading_control_task_queue_.get())); PointerToString(loading_control_task_queue_.get()));
} }
if (throttleable_task_queue_) if (throttleable_task_queue_) {
state->SetString("throttleable_task_queue", state->SetString("throttleable_task_queue",
PointerToString(throttleable_task_queue_.get())); PointerToString(throttleable_task_queue_.get()));
}
if (deferrable_task_queue_) { if (deferrable_task_queue_) {
state->SetString("deferrable_task_queue", state->SetString("deferrable_task_queue",
PointerToString(deferrable_task_queue_.get())); PointerToString(deferrable_task_queue_.get()));
......
...@@ -64,7 +64,7 @@ void LazySchedulerMessageLoopDelegateForTests::RestoreDefaultTaskRunner() { ...@@ -64,7 +64,7 @@ void LazySchedulerMessageLoopDelegateForTests::RestoreDefaultTaskRunner() {
} }
bool LazySchedulerMessageLoopDelegateForTests::HasMessageLoop() const { bool LazySchedulerMessageLoopDelegateForTests::HasMessageLoop() const {
return message_loop_ != nullptr; return !!message_loop_;
} }
bool LazySchedulerMessageLoopDelegateForTests::PostDelayedTask( bool LazySchedulerMessageLoopDelegateForTests::PostDelayedTask(
......
...@@ -77,13 +77,13 @@ ThreadCPUThrottler::ThrottlingThread::ThrottlingThread(double rate) ...@@ -77,13 +77,13 @@ ThreadCPUThrottler::ThrottlingThread::ThrottlingThread(double rate)
: throttled_thread_handle_(base::PlatformThread::CurrentHandle()) { : throttled_thread_handle_(base::PlatformThread::CurrentHandle()) {
#endif #endif
SetThrottlingRate(rate); SetThrottlingRate(rate);
CHECK(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 1) == 0); CHECK_EQ(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 1), 0);
Start(); Start();
} }
ThreadCPUThrottler::ThrottlingThread::~ThrottlingThread() { ThreadCPUThrottler::ThrottlingThread::~ThrottlingThread() {
Stop(); Stop();
CHECK(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 0) == 1); CHECK_EQ(base::subtle::NoBarrier_AtomicExchange(&thread_exists_, 0), 1);
} }
void ThreadCPUThrottler::ThrottlingThread::SetThrottlingRate(double rate) { void ThreadCPUThrottler::ThrottlingThread::SetThrottlingRate(double rate) {
......
...@@ -27,13 +27,11 @@ void ExpectNotTraced() { ...@@ -27,13 +27,11 @@ void ExpectNotTraced() {
} }
const char* SignOfInt(int value) { const char* SignOfInt(int value) {
if (value > 0) { if (value > 0)
return "positive"; return "positive";
} else if (value < 0) { if (value < 0)
return "negative"; return "negative";
} else { return "zero";
return "zero";
}
} }
class TraceableStateForTest class TraceableStateForTest
...@@ -86,10 +84,10 @@ TEST(TracingHelperTest, TraceableStateOperators) { ...@@ -86,10 +84,10 @@ TEST(TracingHelperTest, TraceableStateOperators) {
x = 1; x = 1;
EXPECT_EQ(0, y - x); EXPECT_EQ(0, y - x);
EXPECT_EQ(2, x + y); EXPECT_EQ(2, x + y);
EXPECT_TRUE(x == y); EXPECT_EQ(x, y);
EXPECT_FALSE(x != y); EXPECT_FALSE(x != y);
EXPECT_TRUE((x + y) != 3); EXPECT_NE(x + y, 3);
EXPECT_TRUE((2 - y + 1 + x) == 3); EXPECT_EQ(2 - y + 1 + x, 3);
x = 3; x = 3;
y = 2; y = 2;
int z = x = y; int z = x = y;
......
...@@ -142,7 +142,8 @@ _PATH_RULES_SPECIFIER = [ ...@@ -142,7 +142,8 @@ _PATH_RULES_SPECIFIER = [
# Blink style. # Blink style.
'Source/platform/scheduler', 'Source/platform/scheduler',
'public/platform/scheduler'], 'public/platform/scheduler'],
['-readability/parameter_name']) ['-readability/parameter_name',
'-readability/control_flow'])
] ]
......
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