0

Merge //base/util/timer back in to //base/timer.

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}
This commit is contained in:
Albert J. Wong
2021-07-26 17:47:49 +00:00
committed by Chromium LUCI CQ
parent 77da4f1e58
commit 276d6ff9d4
31 changed files with 78 additions and 110 deletions

@ -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",
@ -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",

@ -1658,7 +1658,7 @@ void WallpaperControllerImpl::UpdateDailyRefreshWallpaperForTesting() {
UpdateDailyRefreshWallpaper();
}
util::WallClockTimer&
base::WallClockTimer&
WallpaperControllerImpl::GetDailyRefreshTimerForTesting() {
return daily_refresh_timer_;
}

@ -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"
@ -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);
@ -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};

@ -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"

@ -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",
@ -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",

3
base/timer/OWNERS Normal file

@ -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

@ -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>
@ -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;
@ -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;
}
}
@ -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

@ -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"
@ -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
@ -36,15 +34,15 @@ 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;
@ -52,20 +50,20 @@ class WallClockTimer : public base::PowerSuspendObserver {
// 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.
@ -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();
@ -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_

@ -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>
@ -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:
@ -253,4 +253,4 @@ TEST_F(WallClockTimerTest, NonStopTickClockWithLongPause) {
EXPECT_FALSE(wall_clock_timer.IsRunning());
}
} // namespace util
} // namespace base

@ -8,7 +8,6 @@ test("base_util_unittests") {
deps = [
"enum_set:unittests",
"memory_pressure:unittests",
"timer:unittests",
"values:unittests",
"//base/test:run_all_unittests",
]

@ -1,23 +0,0 @@
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("timer") {
public = [ "wall_clock_timer.h" ]
sources = [ "wall_clock_timer.cc" ]
deps = [ "//base:base" ]
}
source_set("unittests") {
testonly = true
sources = [ "wall_clock_timer_unittest.cc" ]
deps = [
":timer",
"//base/test:test_support",
"//testing/gmock",
"//testing/gtest",
]
}

@ -1,2 +0,0 @@
grt@chromium.org
zmin@chromium.org

@ -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",

@ -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();
}
@ -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);

@ -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"
@ -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;
@ -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);
};

@ -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_;

@ -11,7 +11,7 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "base/version.h"
#include "chrome/browser/ash/settings/cros_settings.h"
#include "chrome/browser/upgrade_detector/build_state_observer.h"
@ -288,10 +288,10 @@ class MinimumVersionPolicyHandler
base::Time update_required_deadline_;
// Fires when the deadline to update the device has reached or passed.
util::WallClockTimer update_required_deadline_timer_;
base::WallClockTimer update_required_deadline_timer_;
// Fires when next update required notification is to be shown.
util::WallClockTimer notification_timer_;
base::WallClockTimer notification_timer_;
// Non-owning reference to CrosSettings. This class have shorter lifetime than
// CrosSettings.

@ -29,7 +29,7 @@ namespace policy {
namespace off_hours {
DeviceOffHoursController::DeviceOffHoursController()
: timer_(std::make_unique<util::WallClockTimer>()),
: timer_(std::make_unique<base::WallClockTimer>()),
clock_(base::DefaultClock::GetInstance()) {
auto* system_clock_client = chromeos::SystemClockClient::Get();
if (system_clock_client) {
@ -57,7 +57,7 @@ void DeviceOffHoursController::SetClockForTesting(
base::Clock* clock,
const base::TickClock* timer_clock) {
clock_ = clock;
timer_ = std::make_unique<util::WallClockTimer>(clock, timer_clock);
timer_ = std::make_unique<base::WallClockTimer>(clock, timer_clock);
}
bool DeviceOffHoursController::IsCurrentSessionAllowedOnlyForOffHours() const {

@ -13,7 +13,7 @@
#include "base/observer_list.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "chromeos/dbus/system_clock/system_clock_client.h"
#include "chromeos/policy/weekly_time/weekly_time_interval.h"
#include "components/policy/proto/chrome_device_policy.pb.h"
@ -128,7 +128,7 @@ class DeviceOffHoursController : public chromeos::SystemClockClient::Observer {
// Timer for updating device settings at the begin of next “OffHours” interval
// or at the end of current "OffHours" interval.
std::unique_ptr<util::WallClockTimer> timer_;
std::unique_ptr<base::WallClockTimer> timer_;
// Used for testing purposes, otherwise it's an instance of
// base::DefaultClock.

@ -100,7 +100,6 @@ source_set("chromeos") {
"//ash/webui/shimless_rma",
"//ash/webui/shortcut_customization_ui",
"//base",
"//base/util/timer",
"//build:branding_buildflags",
"//build:chromeos_buildflags",
"//chrome/app:command_ids",

@ -216,7 +216,7 @@ void SessionLengthLimiter::UpdateLimit() {
}
// Set a timer to log out the user when the session length limit is reached.
timer_ = std::make_unique<util::WallClockTimer>(
timer_ = std::make_unique<base::WallClockTimer>(
delegate_->GetClock() /*clock*/, nullptr /*tick_clock*/);
timer_->Start(FROM_HERE, session_stop_time, delegate_.get(),
&SessionLengthLimiter::Delegate::StopSession);

@ -12,7 +12,7 @@
#include "base/threading/thread_checker.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "components/prefs/pref_change_registrar.h"
#include "ui/base/user_activity/user_activity_observer.h"
@ -68,7 +68,7 @@ class SessionLengthLimiter : public ui::UserActivityObserver {
std::unique_ptr<Delegate> delegate_;
PrefChangeRegistrar pref_change_registrar_;
std::unique_ptr<util::WallClockTimer> timer_;
std::unique_ptr<base::WallClockTimer> timer_;
base::Time session_start_time_;
bool user_activity_seen_;

@ -4538,7 +4538,6 @@ static_library("ui") {
deps += [
"//base",
"//base/util/timer",
"//chrome/browser/ui/views",
"//components/constrained_window",
"//components/content_settings/browser/ui",

@ -8,7 +8,7 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "chrome/browser/upgrade_detector/upgrade_observer.h"
@ -194,7 +194,7 @@ class RelaunchNotificationController : public UpgradeObserver {
// A timer used either to repeatedly reshow the relaunch recommended bubble
// once the high annoyance level has been reached, or to trigger browser
// relaunch once the relaunch required dialog's deadline is reached.
util::WallClockTimer timer_;
base::WallClockTimer timer_;
// A flag to denote that the relaunch notification type policy value has been
// overridden to required. Changes to the policy value will not affect the

@ -8,7 +8,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
// Timer that handles notification title refresh for relaunch recommended
// notification. Created by RelaunchRecommendedBubbleView for Chrome desktop.
@ -41,7 +41,7 @@ class RelaunchRecommendedTimer {
const base::Time upgrade_detected_time_;
// A timer with which title refreshes are scheduled.
util::WallClockTimer refresh_timer_;
base::WallClockTimer refresh_timer_;
// Callback which triggers the actual title update on Chrome desktop.
base::RepeatingClosure callback_;

@ -8,7 +8,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
// Timer that handles notification title refresh for relaunch required
// notification. Created either by RelaunchRequiredDialogView for Chrome
@ -43,7 +43,7 @@ class RelaunchRequiredTimer {
base::Time deadline_;
// A timer with which title refreshes are scheduled.
util::WallClockTimer refresh_timer_;
base::WallClockTimer refresh_timer_;
// Callback which triggers the actual title update, which differs on Chrome
// for desktop vs for Chrome OS.

@ -526,7 +526,6 @@ source_set("unit_tests") {
"//ash/public/cpp",
"//base",
"//base/test:test_support",
"//base/util/timer",
"//chromeos",
"//chromeos/cryptohome:cryptohome",
"//chromeos/dbus:test_support",

@ -22,7 +22,7 @@ static_library("enterprise") {
deps = [
"//ash/constants",
"//base/util/timer",
"//base",
"//chromeos",
"//chromeos/cryptohome",
"//chromeos/dbus:dbus",

@ -11,7 +11,7 @@
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "chromeos/policy/weekly_time/weekly_time_interval.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/user_manager/user_manager.h"
@ -71,7 +71,7 @@ class SnapshotHoursPolicyService : public user_manager::UserManager::Observer {
const {
return intervals_;
}
const util::WallClockTimer* get_timer_for_testing() const { return &timer_; }
const base::WallClockTimer* get_timer_for_testing() const { return &timer_; }
void set_snapshot_update_end_time_for_testing(base::Time time) {
snapshot_update_end_time_ = time;
@ -135,7 +135,7 @@ class SnapshotHoursPolicyService : public user_manager::UserManager::Observer {
// Timer for updating ARC data snapshot at the begin of next interval or at
// the end of current interval.
util::WallClockTimer timer_;
base::WallClockTimer timer_;
base::WeakPtrFactory<SnapshotHoursPolicyService> weak_ptr_factory_{this};
};

@ -42,7 +42,6 @@ static_library("enterprise") {
deps = [
"//base",
"//base/util/timer",
"//build:chromeos_buildflags",
"//components/policy/core/browser",
"//components/policy/core/common",

@ -13,7 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list_types.h"
#include "base/time/time.h"
#include "base/util/timer/wall_clock_timer.h"
#include "base/timer/wall_clock_timer.h"
#include "components/enterprise/browser/reporting/real_time_report_generator.h"
#include "components/enterprise/browser/reporting/report_generator.h"
#include "components/enterprise/browser/reporting/report_uploader.h"
@ -151,7 +151,7 @@ class ReportScheduler {
policy::CloudPolicyClient* cloud_policy_client_;
util::WallClockTimer request_timer_;
base::WallClockTimer request_timer_;
std::unique_ptr<ReportUploader> report_uploader_;