Chromium Code Reviews| Index: ash/mus/user_activity_forwarder.cc |
| diff --git a/ash/mus/user_activity_forwarder.cc b/ash/mus/user_activity_forwarder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2df1368189af15dca9d848b5f828d3ccc709e90a |
| --- /dev/null |
| +++ b/ash/mus/user_activity_forwarder.cc |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2017 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 "ash/mus/user_activity_forwarder.h" |
| + |
| +#include <cmath> |
| + |
| +#include "services/service_manager/public/cpp/connector.h" |
| +#include "services/ui/public/interfaces/constants.mojom.h" |
| +#include "ui/base/user_activity/user_activity_detector.h" |
| + |
| +namespace ash { |
| +namespace mus { |
| + |
| +UserActivityForwarder::UserActivityForwarder( |
| + service_manager::Connector* connector, |
| + ui::UserActivityDetector* detector) |
| + : user_activity_observer_binding_(this), user_activity_detector_(detector) { |
| + DCHECK(detector); |
| + |
| + // |connector| is null in some tests. |
| + if (connector) { |
| + // Round UserActivityDetector's notification interval up to the nearest |
| + // second (the granularity exposed by UserActivityMonitor). |
| + const uint32_t kNotifyIntervalSec = static_cast<uint32_t>( |
|
sadrul
2017/01/18 22:10:58
constexpr?
Daniel Erat
2017/01/19 01:56:24
i tried this initially, but the UserActivityDetect
|
| + ceil(ui::UserActivityDetector::kNotifyIntervalMs / 1000.0)); |
| + |
| + connector->BindInterface(ui::mojom::kServiceName, &user_activity_monitor_); |
| + user_activity_monitor_->AddUserActivityObserver( |
| + kNotifyIntervalSec, |
| + user_activity_observer_binding_.CreateInterfacePtrAndBind()); |
| + } |
| +} |
| + |
| +UserActivityForwarder::~UserActivityForwarder() {} |
| + |
| +void UserActivityForwarder::OnUserActivity() { |
| + user_activity_detector_->HandleExternalUserActivity(); |
| +} |
| + |
| +} // namespace mus |
| +} // namespace ash |