Skip to content

Commit

Permalink
Merge //base/util/timer back in to //base/timer.
Browse files Browse the repository at this point in the history
This is part of merging all of //base/util back into //base.

Bug: 1227210
Change-Id: Ia083d140e8a2ae584a64792f5ca78d741d99260a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3012060
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Reviewed-by: Greg Thompson <grt@chromium.org>
Reviewed-by: Owen Min <zmin@chromium.org>
Auto-Submit: Albert J. Wong <ajwong@chromium.org>
Owners-Override: Wez <wez@chromium.org>
Commit-Queue: Albert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905324}
  • Loading branch information
awong-chromium authored and Chromium LUCI CQ committed Jul 26, 2021
1 parent 77da4f1 commit 276d6ff
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 110 deletions.
2 changes: 0 additions & 2 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,6 @@ component("ash") {
"//base",
"//base:i18n",
"//base/third_party/dynamic_annotations",
"//base/util/timer",
"//base/util/values:values_util",
"//build:branding_buildflags",
"//cc",
Expand Down Expand Up @@ -2496,7 +2495,6 @@ test("ash_unittests") {
"//ash/system/machine_learning:user_settings_event_proto",
"//base",
"//base/test:test_support",
"//base/util/timer:timer",
"//base/util/values:values_util",
"//build:branding_buildflags",
"//chromeos:test_support",
Expand Down
2 changes: 1 addition & 1 deletion ash/wallpaper/wallpaper_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ void WallpaperControllerImpl::UpdateDailyRefreshWallpaperForTesting() {
UpdateDailyRefreshWallpaper();
}

util::WallClockTimer&
base::WallClockTimer&
WallpaperControllerImpl::GetDailyRefreshTimerForTesting() {
return daily_refresh_timer_;
}
Expand Down
6 changes: 3 additions & 3 deletions ash/wallpaper/wallpaper_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "components/account_id/account_id.h"
#include "components/prefs/pref_change_registrar.h"
#include "ui/compositor/compositor_lock.h"
Expand Down Expand Up @@ -359,7 +359,7 @@ class ASH_EXPORT WallpaperControllerImpl

// Exposed for testing.
void UpdateDailyRefreshWallpaperForTesting();
util::WallClockTimer& GetDailyRefreshTimerForTesting();
base::WallClockTimer& GetDailyRefreshTimerForTesting();

private:
FRIEND_TEST_ALL_PREFIXES(WallpaperControllerTest, BasicReparenting);
Expand Down Expand Up @@ -726,7 +726,7 @@ class ASH_EXPORT WallpaperControllerImpl
// May be null in tests.
PrefService* local_state_ = nullptr;

util::WallClockTimer daily_refresh_timer_;
base::WallClockTimer daily_refresh_timer_;

base::WeakPtrFactory<WallpaperControllerImpl> weak_factory_{this};

Expand Down
1 change: 0 additions & 1 deletion ash/wallpaper/wallpaper_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time_override.h"
#include "base/util/timer/wall_clock_timer.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/scoped_user_manager.h"
Expand Down
3 changes: 3 additions & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ component("base") {
"timer/lap_timer.h",
"timer/timer.cc",
"timer/timer.h",
"timer/wall_clock_timer.cc",
"timer/wall_clock_timer.h",
"token.cc",
"token.h",
"trace_event/base_tracing.h",
Expand Down Expand Up @@ -3170,6 +3172,7 @@ test("base_unittests") {
"timer/lap_timer_unittest.cc",
"timer/mock_timer_unittest.cc",
"timer/timer_unittest.cc",
"timer/wall_clock_timer_unittest.cc",
"token_unittest.cc",
"tools_sanity_unittest.cc",
"traits_bag_unittest.cc",
Expand Down
3 changes: 3 additions & 0 deletions base/timer/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
per-file wall_clock_timer.cc=grt@chromium.org,zmin@chromium.org
per-file wall_clock_timer.h=grt@chromium.org,zmin@chromium.org
per-file wall_clock_timer_unittest.cc=grt@chromium.org,zmin@chromium.org
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"

#include <utility>

Expand All @@ -12,21 +12,19 @@
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"

namespace util {
namespace base {

WallClockTimer::WallClockTimer() = default;
WallClockTimer::WallClockTimer(const base::Clock* clock,
const base::TickClock* tick_clock)
: timer_(tick_clock),
clock_(clock ? clock : base::DefaultClock::GetInstance()) {}
WallClockTimer::WallClockTimer(const Clock* clock, const TickClock* tick_clock)
: timer_(tick_clock), clock_(clock ? clock : DefaultClock::GetInstance()) {}

WallClockTimer::~WallClockTimer() {
RemoveObserver();
}

void WallClockTimer::Start(const base::Location& posted_from,
base::Time desired_run_time,
base::OnceClosure user_task) {
void WallClockTimer::Start(const Location& posted_from,
Time desired_run_time,
OnceClosure user_task) {
user_task_ = std::move(user_task);
posted_from_ = posted_from;
desired_run_time_ = desired_run_time;
Expand All @@ -53,14 +51,14 @@ void WallClockTimer::OnResume() {

void WallClockTimer::AddObserver() {
if (!observer_added_) {
base::PowerMonitor::AddPowerSuspendObserver(this);
PowerMonitor::AddPowerSuspendObserver(this);
observer_added_ = true;
}
}

void WallClockTimer::RemoveObserver() {
if (observer_added_) {
base::PowerMonitor::RemovePowerSuspendObserver(this);
PowerMonitor::RemovePowerSuspendObserver(this);
observer_added_ = false;
}
}
Expand All @@ -71,8 +69,8 @@ void WallClockTimer::RunUserTask() {
std::exchange(user_task_, {}).Run();
}

base::Time WallClockTimer::Now() const {
Time WallClockTimer::Now() const {
return clock_->Now();
}

} // namespace util
} // namespace base
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_UTIL_TIMER_WALL_CLOCK_TIMER_H_
#define BASE_UTIL_TIMER_WALL_CLOCK_TIMER_H_
#ifndef BASE_TIMER_WALL_CLOCK_TIMER_H_
#define BASE_TIMER_WALL_CLOCK_TIMER_H_

#include "base/base_export.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
Expand All @@ -16,9 +17,6 @@
namespace base {
class Clock;
class TickClock;
} // namespace base

namespace util {

// WallClockTimer is based on OneShotTimer and provides a simple timer API
// which is mostly similar to OneShotTimer's API. The main difference is that
Expand All @@ -36,36 +34,36 @@ namespace util {
// destructor.
// - The destructor may be called from any sequence when the timer is not
// running and there is no scheduled task active.
class WallClockTimer : public base::PowerSuspendObserver {
class BASE_EXPORT WallClockTimer : public PowerSuspendObserver {
public:
// Constructs a timer. Start() must be called later to start the timer.
// If |clock| is provided, it's used instead of
// base::DefaultClock::GetInstance() to calulate timer's delay.
// If |tick_clock| is provided, it's used instead of base::TimeTicks::Now() to
// get base::TimeTicks when scheduling tasks.
// DefaultClock::GetInstance() to calulate timer's delay. If |tick_clock|
// is provided, it's used instead of TimeTicks::Now() to get TimeTicks when
// scheduling tasks.
WallClockTimer();
WallClockTimer(const base::Clock* clock, const base::TickClock* tick_clock);
WallClockTimer(const Clock* clock, const TickClock* tick_clock);
WallClockTimer(const WallClockTimer&) = delete;
WallClockTimer& operator=(const WallClockTimer&) = delete;

~WallClockTimer() override;

// Starts the timer to run at the given |desired_run_time|. If the timer is
// already running, it will be replaced to call the given |user_task|.
virtual void Start(const base::Location& posted_from,
base::Time desired_run_time,
base::OnceClosure user_task);
virtual void Start(const Location& posted_from,
Time desired_run_time,
OnceClosure user_task);

// Starts the timer to run at the given |desired_run_time|. If the timer is
// already running, it will be replaced to call a task formed from
// |receiver|->*|method|.
template <class Receiver>
void Start(const base::Location& posted_from,
base::Time desired_run_time,
void Start(const Location& posted_from,
Time desired_run_time,
Receiver* receiver,
void (Receiver::*method)()) {
Start(posted_from, desired_run_time,
base::BindOnce(method, base::Unretained(receiver)));
BindOnce(method, Unretained(receiver)));
}

// Stops the timer. It is a no-op if the timer is not running.
Expand All @@ -74,10 +72,10 @@ class WallClockTimer : public base::PowerSuspendObserver {
// Returns true if the timer is running.
bool IsRunning() const;

// base::PowerSuspendObserver:
// PowerSuspendObserver:
void OnResume() override;

base::Time desired_run_time() const { return desired_run_time_; }
Time desired_run_time() const { return desired_run_time_; }

private:
void AddObserver();
Expand All @@ -88,25 +86,25 @@ class WallClockTimer : public base::PowerSuspendObserver {
void RunUserTask();

// Returns the current time count.
base::Time Now() const;
Time Now() const;

bool observer_added_ = false;

// Location in user code.
base::Location posted_from_;
Location posted_from_;

// The desired run time of |user_task_|.
base::Time desired_run_time_;
Time desired_run_time_;

base::OnceClosure user_task_;
OnceClosure user_task_;

// Timer which should notify to run task in the period while system awake
base::OneShotTimer timer_;
OneShotTimer timer_;

// The clock used to calculate the run time for scheduled tasks.
const base::Clock* const clock_ = base::DefaultClock::GetInstance();
const Clock* const clock_ = DefaultClock::GetInstance();
};

} // namespace util
} // namespace base

#endif // BASE_UTIL_TIMER_WALL_CLOCK_TIMER_H_
#endif // BASE_TIMER_WALL_CLOCK_TIMER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"

#include <memory>
#include <utility>
Expand All @@ -14,7 +14,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace util {
namespace base {

class WallClockTimerTest : public ::testing::Test {
protected:
Expand Down Expand Up @@ -253,4 +253,4 @@ TEST_F(WallClockTimerTest, NonStopTickClockWithLongPause) {
EXPECT_FALSE(wall_clock_timer.IsRunning());
}

} // namespace util
} // namespace base
1 change: 0 additions & 1 deletion base/util/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ test("base_util_unittests") {
deps = [
"enum_set:unittests",
"memory_pressure:unittests",
"timer:unittests",
"values:unittests",
"//base/test:run_all_unittests",
]
Expand Down
23 changes: 0 additions & 23 deletions base/util/timer/BUILD.gn

This file was deleted.

2 changes: 0 additions & 2 deletions base/util/timer/OWNERS

This file was deleted.

1 change: 0 additions & 1 deletion chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4255,7 +4255,6 @@ static_library("browser") {
":cart_db_content_proto",
":theme_properties",
"//base/util/memory_pressure",
"//base/util/timer",
"//chrome/app:command_ids",
"//chrome/app/theme:chrome_unscaled_resources_grit",
"//chrome/app/vector_icons",
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ash/login/signin/offline_signin_limiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void OfflineSigninLimiter::SignedIn(UserContext::AuthFlow auth_flow) {
UpdateLockScreenLimit();
}

util::WallClockTimer* OfflineSigninLimiter::GetTimerForTesting() {
base::WallClockTimer* OfflineSigninLimiter::GetTimerForTesting() {
return offline_signin_limit_timer_.get();
}

Expand All @@ -127,9 +127,9 @@ OfflineSigninLimiter::OfflineSigninLimiter(Profile* profile,
const base::Clock* clock)
: profile_(profile),
clock_(clock ? clock : base::DefaultClock::GetInstance()),
offline_signin_limit_timer_(std::make_unique<util::WallClockTimer>()),
offline_signin_limit_timer_(std::make_unique<base::WallClockTimer>()),
offline_lock_screen_signin_limit_timer_(
std::make_unique<util::WallClockTimer>()) {}
std::make_unique<base::WallClockTimer>()) {}

OfflineSigninLimiter::~OfflineSigninLimiter() {
base::PowerMonitor::RemovePowerSuspendObserver(this);
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/ash/login/signin/offline_signin_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/macros.h"
#include "base/power_monitor/power_observer.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "chromeos/login/auth/user_context.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
Expand All @@ -36,7 +36,7 @@ class OfflineSigninLimiter : public KeyedService,
// the type of authentication flow that the user went through.
void SignedIn(UserContext::AuthFlow auth_flow);

util::WallClockTimer* GetTimerForTesting();
base::WallClockTimer* GetTimerForTesting();

// KeyedService:
void Shutdown() override;
Expand Down Expand Up @@ -90,9 +90,9 @@ class OfflineSigninLimiter : public KeyedService,

PrefChangeRegistrar pref_change_registrar_;

std::unique_ptr<util::WallClockTimer> offline_signin_limit_timer_;
std::unique_ptr<base::WallClockTimer> offline_signin_limit_timer_;

std::unique_ptr<util::WallClockTimer> offline_lock_screen_signin_limit_timer_;
std::unique_ptr<base::WallClockTimer> offline_lock_screen_signin_limit_timer_;

DISALLOW_COPY_AND_ASSIGN(OfflineSigninLimiter);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class OfflineSigninLimiterTest : public testing::Test {
user_manager::ScopedUserManager user_manager_enabler_;

std::unique_ptr<TestingProfile> profile_;
util::WallClockTimer* timer_; // Not owned.
base::WallClockTimer* timer_; // Not owned.

OfflineSigninLimiter* limiter_; // Owned.
base::test::ScopedPowerMonitorTestSource test_power_monitor_source_;
Expand Down
Loading

0 comments on commit 276d6ff

Please sign in to comment.