update_engine: Use clock and fake clock from SystemState
No need to pass clock and fake clock anywhere anymore. This CL makes it
to just use those objects available from SystemState and
FakeSystemState.
BUG=b:171829801
TEST=cros_workon_make --board reef --test update_engine
Change-Id: I9a3cf6dd2057620c11b862d3317b83489c76f3ca
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2546625
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/common/clock.cc b/common/clock.cc
index 05c495c..0821a56 100644
--- a/common/clock.cc
+++ b/common/clock.cc
@@ -20,11 +20,11 @@
namespace chromeos_update_engine {
-base::Time Clock::GetWallclockTime() {
+base::Time Clock::GetWallclockTime() const {
return base::Time::Now();
}
-base::Time Clock::GetMonotonicTime() {
+base::Time Clock::GetMonotonicTime() const {
struct timespec now_ts;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &now_ts) != 0) {
// Avoid logging this as an error as call-sites may call this very
@@ -40,7 +40,7 @@
return base::Time::FromTimeVal(now_tv);
}
-base::Time Clock::GetBootTime() {
+base::Time Clock::GetBootTime() const {
struct timespec now_ts;
if (clock_gettime(CLOCK_BOOTTIME, &now_ts) != 0) {
// Avoid logging this as an error as call-sites may call this very
diff --git a/common/clock.h b/common/clock.h
index 2f373a7..4021fa1 100644
--- a/common/clock.h
+++ b/common/clock.h
@@ -24,13 +24,11 @@
// Implements a clock.
class Clock : public ClockInterface {
public:
- Clock() {}
+ Clock() = default;
- base::Time GetWallclockTime() override;
-
- base::Time GetMonotonicTime() override;
-
- base::Time GetBootTime() override;
+ base::Time GetWallclockTime() const override;
+ base::Time GetMonotonicTime() const override;
+ base::Time GetBootTime() const override;
private:
DISALLOW_COPY_AND_ASSIGN(Clock);
diff --git a/common/clock_interface.h b/common/clock_interface.h
index 2228983..176505d 100644
--- a/common/clock_interface.h
+++ b/common/clock_interface.h
@@ -32,21 +32,21 @@
virtual ~ClockInterface() = default;
// Gets the current time e.g. similar to base::Time::Now().
- virtual base::Time GetWallclockTime() = 0;
+ virtual base::Time GetWallclockTime() const = 0;
// Returns monotonic time since some unspecified starting point. It
// is not increased when the system is sleeping nor is it affected
// by NTP or the user changing the time.
//
// (This is a simple wrapper around clock_gettime(2) / CLOCK_MONOTONIC_RAW.)
- virtual base::Time GetMonotonicTime() = 0;
+ virtual base::Time GetMonotonicTime() const = 0;
// Returns monotonic time since some unspecified starting point. It
// is increased when the system is sleeping but it's not affected
// by NTP or the user changing the time.
//
// (This is a simple wrapper around clock_gettime(2) / CLOCK_BOOTTIME.)
- virtual base::Time GetBootTime() = 0;
+ virtual base::Time GetBootTime() const = 0;
};
} // namespace chromeos_update_engine
diff --git a/common/fake_clock.h b/common/fake_clock.h
index 165ec4d..9c47b57 100644
--- a/common/fake_clock.h
+++ b/common/fake_clock.h
@@ -26,11 +26,11 @@
public:
FakeClock() {}
- base::Time GetWallclockTime() override { return wallclock_time_; }
+ base::Time GetWallclockTime() const override { return wallclock_time_; }
- base::Time GetMonotonicTime() override { return monotonic_time_; }
+ base::Time GetMonotonicTime() const override { return monotonic_time_; }
- base::Time GetBootTime() override { return boot_time_; }
+ base::Time GetBootTime() const override { return boot_time_; }
void SetWallclockTime(const base::Time& time) { wallclock_time_ = time; }
diff --git a/common/system_state.h b/common/system_state.h
index dc40d36..29b897b 100644
--- a/common/system_state.h
+++ b/common/system_state.h
@@ -21,6 +21,8 @@
#include <base/logging.h>
+#include "update_engine/common/clock_interface.h"
+
namespace chromeos_update_manager {
class UpdateManager;
@@ -39,7 +41,6 @@
// any circular references in header file inclusion. Hence forward-declaring
// the required classes.
class BootControlInterface;
-class ClockInterface;
class ConnectionManagerInterface;
class DlcServiceInterface;
class HardwareInterface;
diff --git a/common/utils.cc b/common/utils.cc
index c8924b1..ac9fa9c 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -52,7 +52,6 @@
#include <base/strings/stringprintf.h>
#include <brillo/data_encoding.h>
-#include "update_engine/common/clock_interface.h"
#include "update_engine/common/constants.h"
#include "update_engine/common/platform_constants.h"
#include "update_engine/common/prefs_interface.h"