Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1068)

Unified Diff: ash/mus/user_activity_forwarder.cc

Issue 2639703004: mus: Forward user activity from window server to detector. (Closed)
Patch Set: avoid dereferencing null connector in mash_unittests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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>(
+ 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();
+}
James Cook 2017/01/18 17:01:38 If this class sticks around, could it get a trivia
Daniel Erat 2017/01/18 18:54:20 hmm. is there any way to exercise the calls to Bin
James Cook 2017/01/18 20:17:32 I don't know how to exercise the BindInterface bit
+
+} // namespace mus
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698