system_idle_cache.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chromeos/lacros/system_idle_cache.h"
  5. #include "chromeos/lacros/lacros_service.h"
  6. namespace chromeos {
  7. SystemIdleCache::SystemIdleCache() : is_fallback_(true) {}
  8. SystemIdleCache::SystemIdleCache(const crosapi::mojom::IdleInfo& info)
  9. : is_fallback_(false), info_(info.Clone()) {}
  10. SystemIdleCache::~SystemIdleCache() = default;
  11. void SystemIdleCache::Start() {
  12. DCHECK(!is_fallback_);
  13. auto* lacros_service = chromeos::LacrosService::Get();
  14. CHECK(lacros_service->IsAvailable<crosapi::mojom::IdleService>());
  15. lacros_service->GetRemote<crosapi::mojom::IdleService>()->AddIdleInfoObserver(
  16. receiver_.BindNewPipeAndPassRemoteWithVersion());
  17. }
  18. base::TimeDelta SystemIdleCache::auto_lock_delay() const {
  19. return is_fallback_ ? base::TimeDelta() : info_->auto_lock_delay;
  20. }
  21. base::TimeTicks SystemIdleCache::last_activity_time() const {
  22. return is_fallback_ ? base::TimeTicks::Now() : info_->last_activity_time;
  23. }
  24. bool SystemIdleCache::is_locked() const {
  25. return is_fallback_ ? false : info_->is_locked;
  26. }
  27. void SystemIdleCache::OnIdleInfoChanged(crosapi::mojom::IdleInfoPtr info) {
  28. info_ = std::move(info);
  29. }
  30. } // namespace chromeos