Commit 5a103d4a authored by Kyle Qian's avatar Kyle Qian Committed by Commit Bot

Implement SystemClock for CrOS Nearby.

This CL includes a concrete implementation for the abstract class
SystemClock defined in the Nearby library.

SystemClock currently contains a single method elapsedRealtime(),
which is expected to return time in milliseconds since boot, including
time spent in states such as suspension (closed lid). The
implementation in this CL, however, does not include time spent in
suspension due to a current limitation of the POSIX implementation of
base::TimeTicks::Now(). See https://crbug.com/166153 for info.

Because the actual Nearby library has yet to be merged into the CrOS
directory, this CL includes stand-in Nearby abstract classes under
the temporary directory //chromeos/components/nearby/library.
This directory will be removed after the Nearby library gets imported
to //third_party.

Bug: 861813
Change-Id: I194880c75c4a8ba3afa37b6b3c916485c065f20f
Reviewed-on: https://chromium-review.googlesource.com/1150822Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: Kyle Qian <kyleqian@google.com>
Cr-Commit-Position: refs/heads/master@{#579255}
parent c1420b2c
......@@ -11,6 +11,8 @@ static_library("nearby") {
"hash_utils_impl.cc",
"hash_utils_impl.h",
"settable_future_impl.h",
"system_clock_impl.cc",
"system_clock_impl.h",
"thread_utils_impl.cc",
"thread_utils_impl.h",
]
......
......@@ -12,6 +12,7 @@ static_library("library") {
"future.h",
"hash_utils.h",
"settable_future.h",
"system_clock.h",
"thread_utils.h",
]
......
// Copyright (c) 2018 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.
#ifndef CHROMEOS_COMPONENTS_NEARBY_LIBRARY_SYSTEM_CLOCK_H_
#define CHROMEOS_COMPONENTS_NEARBY_LIBRARY_SYSTEM_CLOCK_H_
#include <cstdint>
namespace location {
namespace nearby {
class SystemClock {
public:
virtual ~SystemClock() {}
// Returns the time since the system was booted, and includes deep sleep. This
// clock should be guaranteed to be monotonic, and should continue to tick
// even when the CPU is in power saving modes.
virtual std::int64_t elapsedRealtime() = 0;
};
} // namespace nearby
} // namespace location
#endif // CHROMEOS_COMPONENTS_NEARBY_LIBRARY_SYSTEM_CLOCK_H_
// Copyright (c) 2018 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.
#include "chromeos/components/nearby/system_clock_impl.h"
#include "base/sys_info.h"
namespace chromeos {
namespace nearby {
SystemClockImpl::SystemClockImpl() = default;
SystemClockImpl::~SystemClockImpl() = default;
int64_t SystemClockImpl::elapsedRealtime() {
// TODO(kyleqian): The POSIX implementation of base::SysInfo::Uptime()
// currently does not include time spent suspended. See
// https://crbug.com/166153.
return base::SysInfo::Uptime().InMilliseconds();
}
} // namespace nearby
} // namespace chromeos
// Copyright (c) 2018 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.
#ifndef CHROMEOS_COMPONENTS_NEARBY_SYSTEM_CLOCK_IMPL_H_
#define CHROMEOS_COMPONENTS_NEARBY_SYSTEM_CLOCK_IMPL_H_
#include "base/macros.h"
#include "chromeos/components/nearby/library/system_clock.h"
namespace chromeos {
namespace nearby {
// Concrete location::nearby::SystemClock implementation.
class SystemClockImpl : public location::nearby::SystemClock {
public:
SystemClockImpl();
~SystemClockImpl() override;
private:
// location::nearby::SystemClock:
int64_t elapsedRealtime() override;
DISALLOW_COPY_AND_ASSIGN(SystemClockImpl);
};
} // namespace nearby
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_NEARBY_SYSTEM_CLOCK_IMPL_H_
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