Skip to content

Commit

Permalink
Make DefaultTickClock::GetInstance return a const TickClock*.
Browse files Browse the repository at this point in the history
Now that TickClock::NowTicks is a const function, change consumers so
that they hold a const pointer to a clock.

TBR=sky@chromium.org

Bug: None
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_mojo;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I698230dfd458eb7b6d1c4566c6ed8b12db097c0e
Reviewed-on: https://chromium-review.googlesource.com/982621
Reviewed-by: Greg Thompson <grt@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547631}
  • Loading branch information
GregTho authored and Commit Bot committed Apr 3, 2018
1 parent 077b476 commit aa48ce8
Show file tree
Hide file tree
Showing 313 changed files with 1,052 additions and 525 deletions.
2 changes: 1 addition & 1 deletion ash/accessibility/touch_accessibility_enabler.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ASH_EXPORT TouchAccessibilityEnabler : public ui::EventHandler {

// When touch_accessibility_enabler gets time relative to real time during
// testing, this clock is set to the simulated clock and used.
base::TickClock* tick_clock_;
const base::TickClock* tick_clock_;

// Whether or not we currently have an event handler installed. It can
// be removed when TouchExplorationController is running.
Expand Down
2 changes: 1 addition & 1 deletion ash/metrics/task_switch_time_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TaskSwitchTimeTracker::TaskSwitchTimeTracker(const std::string& histogram_name)
base::DefaultTickClock::GetInstance()) {}

TaskSwitchTimeTracker::TaskSwitchTimeTracker(const std::string& histogram_name,
base::TickClock* tick_clock)
const base::TickClock* tick_clock)
: histogram_name_(histogram_name), tick_clock_(tick_clock) {}

TaskSwitchTimeTracker::~TaskSwitchTimeTracker() = default;
Expand Down
4 changes: 2 additions & 2 deletions ash/metrics/task_switch_time_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ASH_EXPORT TaskSwitchTimeTracker {
// This doesn't take the ownership of the clock. |tick_clock| must outlive
// TaskSwitchTimeTracker.
TaskSwitchTimeTracker(const std::string& histogram_name,
base::TickClock* tick_clock);
const base::TickClock* tick_clock);

// Returns true if |last_action_time_| has a valid value.
bool HasLastActionTime() const;
Expand All @@ -66,7 +66,7 @@ class ASH_EXPORT TaskSwitchTimeTracker {
base::TimeTicks last_action_time_ = base::TimeTicks();

// The clock used to determine the |last_action_time_|.
base::TickClock* tick_clock_;
const base::TickClock* tick_clock_;

DISALLOW_COPY_AND_ASSIGN(TaskSwitchTimeTracker);
};
Expand Down
2 changes: 1 addition & 1 deletion ash/shelf/shelf_button_pressed_metric_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ASH_EXPORT ShelfButtonPressedMetricTracker {
void ResetMinimizedData();

// Time source for performed action times.
base::TickClock* tick_clock_;
const base::TickClock* tick_clock_;

// Stores the time of the last window minimize action.
base::TimeTicks time_of_last_minimize_;
Expand Down
2 changes: 1 addition & 1 deletion ash/shelf/shelf_button_pressed_metric_tracker_test_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ShelfButtonPressedMetricTrackerTestAPI::
~ShelfButtonPressedMetricTrackerTestAPI() = default;

void ShelfButtonPressedMetricTrackerTestAPI::SetTickClock(
base::TickClock* tick_clock) {
const base::TickClock* tick_clock) {
shelf_button_pressed_metric_tracker_->tick_clock_ = tick_clock;
}

Expand Down
2 changes: 1 addition & 1 deletion ash/shelf/shelf_button_pressed_metric_tracker_test_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ShelfButtonPressedMetricTrackerTestAPI {
// Set's the |tick_clock_| on the internal ShelfButtonPressedMetricTracker.
// This doesn't take the ownership of the clock. |tick_clock| must outlive the
// ShelfButtonPressedMetricTracker instance.
void SetTickClock(base::TickClock* tick_clock);
void SetTickClock(const base::TickClock* tick_clock);

private:
ShelfButtonPressedMetricTracker* shelf_button_pressed_metric_tracker_;
Expand Down
6 changes: 4 additions & 2 deletions ash/system/power/peripheral_battery_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class ASH_EXPORT PeripheralBatteryNotifier
PeripheralBatteryNotifier();
~PeripheralBatteryNotifier() override;

void set_testing_clock(base::TickClock* clock) { testing_clock_ = clock; }
void set_testing_clock(const base::TickClock* clock) {
testing_clock_ = clock;
}

// chromeos::PowerManagerClient::Observer:
void PeripheralBatteryStatusReceived(const std::string& path,
Expand Down Expand Up @@ -87,7 +89,7 @@ class ASH_EXPORT PeripheralBatteryNotifier
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;

// Used only for helping test. Not owned and can be nullptr.
base::TickClock* testing_clock_ = nullptr;
const base::TickClock* testing_clock_ = nullptr;

std::unique_ptr<base::WeakPtrFactory<PeripheralBatteryNotifier>>
weakptr_factory_;
Expand Down
2 changes: 1 addition & 1 deletion ash/system/power/power_button_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class ASH_EXPORT PowerButtonController
LockStateController* lock_state_controller_; // Not owned.

// Time source for performed action times.
base::TickClock* tick_clock_;
const base::TickClock* tick_clock_;

// Used to interact with the display.
std::unique_ptr<PowerButtonDisplayController> display_controller_;
Expand Down
3 changes: 2 additions & 1 deletion ash/system/power/power_button_controller_test_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void PowerButtonControllerTestApi::SetPowerButtonType(
controller_->button_type_ = button_type;
}

void PowerButtonControllerTestApi::SetTickClock(base::TickClock* tick_clock) {
void PowerButtonControllerTestApi::SetTickClock(
const base::TickClock* tick_clock) {
DCHECK(tick_clock);
controller_->tick_clock_ = tick_clock;

Expand Down
2 changes: 1 addition & 1 deletion ash/system/power/power_button_controller_test_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PowerButtonControllerTestApi {

void SetPowerButtonType(PowerButtonController::ButtonType button_type);

void SetTickClock(base::TickClock* tick_clock);
void SetTickClock(const base::TickClock* tick_clock);

void SetTurnScreenOffForTap(bool turn_screen_off_for_tap);

Expand Down
2 changes: 1 addition & 1 deletion ash/system/power/power_button_display_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool IsTabletModeActive() {

PowerButtonDisplayController::PowerButtonDisplayController(
BacklightsForcedOffSetter* backlights_forced_off_setter,
base::TickClock* tick_clock)
const base::TickClock* tick_clock)
: backlights_forced_off_setter_(backlights_forced_off_setter),
backlights_forced_off_observer_(this),
tick_clock_(tick_clock),
Expand Down
4 changes: 2 additions & 2 deletions ash/system/power/power_button_display_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ASH_EXPORT PowerButtonDisplayController
public:
PowerButtonDisplayController(
BacklightsForcedOffSetter* backlights_forced_off_setter,
base::TickClock* tick_clock);
const base::TickClock* tick_clock);
~PowerButtonDisplayController() override;

bool IsScreenOn() const;
Expand Down Expand Up @@ -83,7 +83,7 @@ class ASH_EXPORT PowerButtonDisplayController
bool send_accessibility_alert_on_backlights_forced_off_change_ = false;

// Time source for performed action times.
base::TickClock* tick_clock_; // Not owned.
const base::TickClock* tick_clock_; // Not owned.

// If set, the active request passed to |backlights_forced_off_setter_| in
// order to force the backlights off.
Expand Down
2 changes: 1 addition & 1 deletion ash/system/power/power_button_screenshot_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ constexpr base::TimeDelta
PowerButtonScreenshotController::kScreenshotChordDelay;

PowerButtonScreenshotController::PowerButtonScreenshotController(
base::TickClock* tick_clock)
const base::TickClock* tick_clock)
: tick_clock_(tick_clock) {
DCHECK(tick_clock_);
// Using prepend to make sure this event handler is put in front of
Expand Down
4 changes: 2 additions & 2 deletions ash/system/power/power_button_screenshot_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ASH_EXPORT PowerButtonScreenshotController : public ui::EventHandler {
static constexpr base::TimeDelta kScreenshotChordDelay =
base::TimeDelta::FromMilliseconds(150);

explicit PowerButtonScreenshotController(base::TickClock* tick_clock);
explicit PowerButtonScreenshotController(const base::TickClock* tick_clock);
~PowerButtonScreenshotController() override;

// Returns true if power button event is consumed by |this|, otherwise false.
Expand Down Expand Up @@ -73,7 +73,7 @@ class ASH_EXPORT PowerButtonScreenshotController : public ui::EventHandler {
base::OneShotTimer volume_down_timer_;

// Time source for performed action times.
base::TickClock* tick_clock_; // Not owned.
const base::TickClock* tick_clock_; // Not owned.

DISALLOW_COPY_AND_ASSIGN(PowerButtonScreenshotController);
};
Expand Down
3 changes: 2 additions & 1 deletion ash/system/session/logout_confirmation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ void LogoutConfirmationController::OnDialogClosed() {
logout_timer_.Stop();
}

void LogoutConfirmationController::SetClockForTesting(base::TickClock* clock) {
void LogoutConfirmationController::SetClockForTesting(
const base::TickClock* clock) {
clock_ = clock;
}

Expand Down
6 changes: 3 additions & 3 deletions ash/system/session/logout_confirmation_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ASH_EXPORT LogoutConfirmationController : public SessionObserver {
LogoutConfirmationController();
~LogoutConfirmationController() override;

base::TickClock* clock() const { return clock_; }
const base::TickClock* clock() const { return clock_; }

// Shows a LogoutConfirmationDialog. If a confirmation dialog is already being
// shown, it is closed and a new one opened if |logout_time| is earlier than
Expand All @@ -57,15 +57,15 @@ class ASH_EXPORT LogoutConfirmationController : public SessionObserver {
// Overrides the internal clock for testing. This doesn't take the ownership
// of the clock. |clock| must outlive the LogoutConfirmationController
// instance.
void SetClockForTesting(base::TickClock* clock);
void SetClockForTesting(const base::TickClock* clock);
void SetLogoutClosureForTesting(const base::Closure& logout_closure);
LogoutConfirmationDialog* dialog_for_testing() const { return dialog_; }

private:
class LastWindowClosedObserver;
std::unique_ptr<LastWindowClosedObserver> last_window_closed_observer_;

base::TickClock* clock_;
const base::TickClock* clock_;
base::Closure logout_closure_;

base::TimeTicks logout_time_;
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/tablet_mode/tablet_mode_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ bool TabletModeController::CanUseUnstableLidAngle() const {
return elapsed_time >= kUnstableLidAngleDuration;
}

void TabletModeController::SetTickClockForTest(base::TickClock* tick_clock) {
void TabletModeController::SetTickClockForTest(
const base::TickClock* tick_clock) {
DCHECK(tick_clock_);
tick_clock_ = tick_clock;
}
Expand Down
4 changes: 2 additions & 2 deletions ash/wm/tablet_mode/tablet_mode_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ASH_EXPORT TabletModeController
// artificially and deterministically control the current time.
// This does not take the ownership of the tick_clock. |tick_clock| must
// outlive the TabletModeController instance.
void SetTickClockForTest(base::TickClock* tick_clock);
void SetTickClockForTest(const base::TickClock* tick_clock);

// Detect hinge rotation from base and lid accelerometers and automatically
// start / stop tablet mode.
Expand Down Expand Up @@ -226,7 +226,7 @@ class ASH_EXPORT TabletModeController
base::TimeTicks first_unstable_lid_angle_time_;

// Source for the current time in base::TimeTicks.
base::TickClock* tick_clock_;
const base::TickClock* tick_clock_;

// Set when tablet mode switch is on. This is used to force tablet mode.
bool tablet_mode_switch_is_on_ = false;
Expand Down
3 changes: 2 additions & 1 deletion base/task_scheduler/delayed_task_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
namespace base {
namespace internal {

DelayedTaskManager::DelayedTaskManager(std::unique_ptr<TickClock> tick_clock)
DelayedTaskManager::DelayedTaskManager(
std::unique_ptr<const TickClock> tick_clock)
: tick_clock_(std::move(tick_clock)) {
DCHECK(tick_clock_);
}
Expand Down
4 changes: 2 additions & 2 deletions base/task_scheduler/delayed_task_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BASE_EXPORT DelayedTaskManager {
using PostTaskNowCallback = OnceCallback<void(Task task)>;

// |tick_clock| can be specified for testing.
DelayedTaskManager(std::unique_ptr<TickClock> tick_clock =
DelayedTaskManager(std::unique_ptr<const TickClock> tick_clock =
std::make_unique<DefaultTickClock>());
~DelayedTaskManager();

Expand All @@ -57,7 +57,7 @@ class BASE_EXPORT DelayedTaskManager {
TimeDelta delay,
PostTaskNowCallback post_task_now_callback);

const std::unique_ptr<TickClock> tick_clock_;
const std::unique_ptr<const TickClock> tick_clock_;

AtomicFlag started_;

Expand Down
2 changes: 1 addition & 1 deletion base/test/scoped_task_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void ScopedTaskEnvironment::FastForwardUntilNoTasksRemain() {
mock_time_task_runner_->FastForwardUntilNoTasksRemain();
}

TickClock* ScopedTaskEnvironment::GetMockTickClock() {
const TickClock* ScopedTaskEnvironment::GetMockTickClock() {
DCHECK(mock_time_task_runner_);
return mock_time_task_runner_->GetMockTickClock();
}
Expand Down
2 changes: 1 addition & 1 deletion base/test/scoped_task_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ScopedTaskEnvironment {

// Returns a TickClock whose time is updated by
// FastForward(By|UntilNoTasksRemain).
TickClock* GetMockTickClock();
const TickClock* GetMockTickClock();
std::unique_ptr<TickClock> DeprecatedGetMockTickClock();

private:
Expand Down
3 changes: 2 additions & 1 deletion base/test/scoped_task_environment_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ TEST_F(ScopedTaskEnvironmentTest, FastForwardAdvanceTickClock) {
ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, base::DoNothing(),
kLongTaskDelay);

base::TickClock* tick_clock = scoped_task_environment.GetMockTickClock();
const base::TickClock* tick_clock =
scoped_task_environment.GetMockTickClock();
base::TimeTicks tick_clock_ref = tick_clock->NowTicks();

// Make sure that |FastForwardBy| advances the clock.
Expand Down
2 changes: 1 addition & 1 deletion base/test/test_mock_time_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ std::unique_ptr<TickClock> TestMockTimeTaskRunner::DeprecatedGetMockTickClock()
return std::make_unique<LegacyMockTickClock>(this);
}

TickClock* TestMockTimeTaskRunner::GetMockTickClock() const {
const TickClock* TestMockTimeTaskRunner::GetMockTickClock() const {
DCHECK(thread_checker_.CalledOnValidThread());
return &mock_clock_;
}
Expand Down
2 changes: 1 addition & 1 deletion base/test/test_mock_time_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class TestMockTimeTaskRunner : public SingleThreadTaskRunner,
// TODO(tzik): Replace Remove DeprecatedGetMockTickClock() after updating all
// callers to use non-owning TickClock.
std::unique_ptr<TickClock> DeprecatedGetMockTickClock() const;
TickClock* GetMockTickClock() const;
const TickClock* GetMockTickClock() const;

base::circular_deque<TestPendingTask> TakePendingTasks();
bool HasPendingTask() const;
Expand Down
9 changes: 4 additions & 5 deletions base/time/default_tick_clock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "base/time/default_tick_clock.h"

#include "base/lazy_instance.h"
#include "base/no_destructor.h"

namespace base {

Expand All @@ -15,10 +15,9 @@ TimeTicks DefaultTickClock::NowTicks() const {
}

// static
DefaultTickClock* DefaultTickClock::GetInstance() {
static LazyInstance<DefaultTickClock>::Leaky instance =
LAZY_INSTANCE_INITIALIZER;
return instance.Pointer();
const DefaultTickClock* DefaultTickClock::GetInstance() {
static const base::NoDestructor<DefaultTickClock> default_tick_clock;
return default_tick_clock.get();
}

} // namespace base
3 changes: 1 addition & 2 deletions base/time/default_tick_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define BASE_TIME_DEFAULT_TICK_CLOCK_H_

#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/time/tick_clock.h"

namespace base {
Expand All @@ -20,7 +19,7 @@ class BASE_EXPORT DefaultTickClock : public TickClock {
TimeTicks NowTicks() const override;

// Returns a shared instance of DefaultTickClock. This is thread-safe.
static DefaultTickClock* GetInstance();
static const DefaultTickClock* GetInstance();
};

} // namespace base
Expand Down
6 changes: 4 additions & 2 deletions base/timer/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class BaseTimerTaskInternal {
Timer::Timer(bool retain_user_task, bool is_repeating)
: Timer(retain_user_task, is_repeating, nullptr) {}

Timer::Timer(bool retain_user_task, bool is_repeating, TickClock* tick_clock)
Timer::Timer(bool retain_user_task,
bool is_repeating,
const TickClock* tick_clock)
: scheduled_task_(nullptr),
is_repeating_(is_repeating),
retain_user_task_(retain_user_task),
Expand All @@ -85,7 +87,7 @@ Timer::Timer(const Location& posted_from,
TimeDelta delay,
const base::Closure& user_task,
bool is_repeating,
TickClock* tick_clock)
const TickClock* tick_clock)
: scheduled_task_(nullptr),
posted_from_(posted_from),
delay_(delay),
Expand Down
Loading

0 comments on commit aa48ce8

Please sign in to comment.