summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/ash.gyp23
-rw-r--r--ash/shell.cc17
-rw-r--r--ash/shell.h5
-rw-r--r--ash/wm/user_activity_detector.cc63
-rw-r--r--ash/wm/user_activity_detector.h61
-rw-r--r--ash/wm/user_activity_observer.h31
-rw-r--r--chrome/browser/chromeos/chrome_browser_main_chromeos.cc7
-rw-r--r--chrome/browser/chromeos/chrome_browser_main_chromeos.h2
-rw-r--r--chrome/browser/chromeos/power/user_activity_notifier.cc40
-rw-r--r--chrome/browser/chromeos/power/user_activity_notifier.h34
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chromeos/dbus/mock_power_manager_client.h1
-rw-r--r--chromeos/dbus/power_manager_client.cc15
-rw-r--r--chromeos/dbus/power_manager_client.h5
14 files changed, 287 insertions, 19 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index d829a59..89c7e01 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -224,16 +224,6 @@
'wm/partial_screenshot_event_filter.h',
'wm/partial_screenshot_view.cc',
'wm/partial_screenshot_view.h',
- 'wm/shelf_auto_hide_behavior.h',
- 'wm/slow_animation_event_filter.cc',
- 'wm/slow_animation_event_filter.h',
- 'wm/system_gesture_event_filter.cc',
- 'wm/system_gesture_event_filter.h',
- 'wm/system_modal_container_layout_manager.cc',
- 'wm/system_modal_container_layout_manager.h',
- 'wm/system_modal_container_event_filter.cc',
- 'wm/system_modal_container_event_filter.h',
- 'wm/system_modal_container_event_filter_delegate.h',
'wm/power_button_controller.cc',
'wm/power_button_controller.h',
'wm/property_util.cc',
@@ -253,14 +243,27 @@
'wm/shadow_controller.h',
'wm/shadow_types.cc',
'wm/shadow_types.h',
+ 'wm/shelf_auto_hide_behavior.h',
'wm/shelf_layout_manager.cc',
'wm/shelf_layout_manager.h',
+ 'wm/slow_animation_event_filter.cc',
+ 'wm/slow_animation_event_filter.h',
'wm/stacking_controller.cc',
'wm/stacking_controller.h',
'wm/status_area_layout_manager.cc',
'wm/status_area_layout_manager.h',
+ 'wm/system_gesture_event_filter.cc',
+ 'wm/system_gesture_event_filter.h',
+ 'wm/system_modal_container_event_filter.cc',
+ 'wm/system_modal_container_event_filter.h',
+ 'wm/system_modal_container_event_filter_delegate.h',
+ 'wm/system_modal_container_layout_manager.cc',
+ 'wm/system_modal_container_layout_manager.h',
'wm/toplevel_window_event_filter.cc',
'wm/toplevel_window_event_filter.h',
+ 'wm/user_activity_detector.cc',
+ 'wm/user_activity_detector.h',
+ 'wm/user_activity_observer.h',
'wm/video_detector.cc',
'wm/video_detector.h',
'wm/visibility_controller.cc',
diff --git a/ash/shell.cc b/ash/shell.cc
index 6857519..1da2922 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -54,6 +54,7 @@
#include "ash/wm/system_gesture_event_filter.h"
#include "ash/wm/system_modal_container_layout_manager.h"
#include "ash/wm/toplevel_window_event_filter.h"
+#include "ash/wm/user_activity_detector.h"
#include "ash/wm/video_detector.h"
#include "ash/wm/visibility_controller.h"
#include "ash/wm/window_cycle_controller.h"
@@ -588,6 +589,7 @@ Shell::~Shell() {
aura::Env::GetInstance()->cursor_manager()->set_delegate(NULL);
// Please keep in same order as in Init() because it's easy to miss one.
+ RemoveEnvEventFilter(user_activity_detector_.get());
RemoveEnvEventFilter(key_rewriter_filter_.get());
RemoveEnvEventFilter(partial_screenshot_filter_.get());
RemoveEnvEventFilter(input_method_filter_.get());
@@ -730,24 +732,25 @@ void Shell::Init() {
#endif
shell_context_menu_.reset(new internal::ShellContextMenu);
- // KeyRewriterEventFilter must be the first one.
+ // The order in which event filters are added is significant.
DCHECK(!GetEnvEventFilterCount());
+ user_activity_detector_.reset(new UserActivityDetector);
+ AddEnvEventFilter(user_activity_detector_.get());
+
+ DCHECK_EQ(1U, GetEnvEventFilterCount());
key_rewriter_filter_.reset(new internal::KeyRewriterEventFilter);
AddEnvEventFilter(key_rewriter_filter_.get());
- // PartialScreenshotEventFilter must be the second one to capture key
- // events when the taking partial screenshot UI is there.
- DCHECK_EQ(1U, GetEnvEventFilterCount());
+ DCHECK_EQ(2U, GetEnvEventFilterCount());
partial_screenshot_filter_.reset(new internal::PartialScreenshotEventFilter);
AddEnvEventFilter(partial_screenshot_filter_.get());
AddShellObserver(partial_screenshot_filter_.get());
- // InputMethodEventFilter must be the third one. It has to be added before
- // AcceleratorFilter.
- DCHECK_EQ(2U, GetEnvEventFilterCount());
+ DCHECK_EQ(3U, GetEnvEventFilterCount());
input_method_filter_.reset(new aura::shared::InputMethodEventFilter());
input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
AddEnvEventFilter(input_method_filter_.get());
+
#if !defined(OS_MACOSX)
accelerator_filter_.reset(new internal::AcceleratorFilter);
AddEnvEventFilter(accelerator_filter_.get());
diff --git a/ash/shell.h b/ash/shell.h
index d73d85c..b470705 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -70,6 +70,7 @@ class ShellDelegate;
class ShellObserver;
class SystemTrayDelegate;
class SystemTray;
+class UserActivityDetector;
class UserWallpaperDelegate;
class VideoDetector;
class WindowCycleController;
@@ -248,6 +249,9 @@ class ASH_EXPORT Shell : aura::CursorDelegate {
PowerButtonController* power_button_controller() {
return power_button_controller_.get();
}
+ UserActivityDetector* user_activity_detector() {
+ return user_activity_detector_.get();
+ }
VideoDetector* video_detector() {
return video_detector_.get();
}
@@ -396,6 +400,7 @@ class ASH_EXPORT Shell : aura::CursorDelegate {
scoped_ptr<internal::VisibilityController> visibility_controller_;
scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
scoped_ptr<PowerButtonController> power_button_controller_;
+ scoped_ptr<UserActivityDetector> user_activity_detector_;
scoped_ptr<VideoDetector> video_detector_;
scoped_ptr<WindowCycleController> window_cycle_controller_;
scoped_ptr<internal::FocusCycler> focus_cycler_;
diff --git a/ash/wm/user_activity_detector.cc b/ash/wm/user_activity_detector.cc
new file mode 100644
index 0000000..536419b
--- /dev/null
+++ b/ash/wm/user_activity_detector.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 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/wm/user_activity_detector.h"
+
+#include "ash/wm/user_activity_observer.h"
+
+namespace ash {
+
+const double UserActivityDetector::kNotifyIntervalSec = 1.0;
+
+UserActivityDetector::UserActivityDetector() {
+}
+
+UserActivityDetector::~UserActivityDetector() {
+}
+
+void UserActivityDetector::AddObserver(UserActivityObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+bool UserActivityDetector::PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) {
+ MaybeNotify();
+ return false;
+}
+
+bool UserActivityDetector::PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) {
+ MaybeNotify();
+ return false;
+}
+
+ui::TouchStatus UserActivityDetector::PreHandleTouchEvent(
+ aura::Window* target,
+ aura::TouchEvent* event) {
+ MaybeNotify();
+ return ui::TOUCH_STATUS_UNKNOWN;
+}
+
+ui::GestureStatus UserActivityDetector::PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) {
+ MaybeNotify();
+ return ui::GESTURE_STATUS_UNKNOWN;
+}
+
+void UserActivityDetector::MaybeNotify() {
+ base::TimeTicks now = base::TimeTicks::Now();
+ if (last_observer_notification_time_.is_null() ||
+ (now - last_observer_notification_time_).InSecondsF() >=
+ kNotifyIntervalSec) {
+ FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity());
+ last_observer_notification_time_ = now;
+ }
+}
+
+} // namespace ash
diff --git a/ash/wm/user_activity_detector.h b/ash/wm/user_activity_detector.h
new file mode 100644
index 0000000..e8dbe38
--- /dev/null
+++ b/ash/wm/user_activity_detector.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 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 ASH_WM_USER_ACTIVITY_DETECTOR_H_
+#define ASH_WM_USER_ACTIVITY_DETECTOR_H_
+#pragma once
+
+#include "ash/ash_export.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/observer_list.h"
+#include "base/time.h"
+#include "ui/aura/event_filter.h"
+
+namespace ash {
+
+class UserActivityObserver;
+
+// Watches for input events and notifies observers that the user is active.
+class ASH_EXPORT UserActivityDetector : public aura::EventFilter {
+ public:
+ // Minimum amount of time between notifications to observers that a video is
+ // playing.
+ static const double kNotifyIntervalSec;
+
+ UserActivityDetector();
+ virtual ~UserActivityDetector();
+
+ void AddObserver(UserActivityObserver* observer);
+ void RemoveObserver(UserActivityObserver* observer);
+
+ // aura::EventFilter implementation.
+ virtual bool PreHandleKeyEvent(
+ aura::Window* target,
+ aura::KeyEvent* event) OVERRIDE;
+ virtual bool PreHandleMouseEvent(
+ aura::Window* target,
+ aura::MouseEvent* event) OVERRIDE;
+ virtual ui::TouchStatus PreHandleTouchEvent(
+ aura::Window* target,
+ aura::TouchEvent* event) OVERRIDE;
+ virtual ui::GestureStatus PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) OVERRIDE;
+
+ private:
+ // Notifies observers if enough time has passed since the last notification.
+ void MaybeNotify();
+
+ ObserverList<UserActivityObserver> observers_;
+
+ // Last time at which we notified observers that the user was active.
+ base::TimeTicks last_observer_notification_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserActivityDetector);
+};
+
+} // namespace ash
+
+#endif // ASH_WM_USER_ACTIVITY_DETECTOR_H_
diff --git a/ash/wm/user_activity_observer.h b/ash/wm/user_activity_observer.h
new file mode 100644
index 0000000..29889b9
--- /dev/null
+++ b/ash/wm/user_activity_observer.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2012 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 ASH_WM_USER_ACTIVITY_OBSERVER_H_
+#define ASH_WM_USER_ACTIVITY_OBSERVER_H_
+#pragma once
+
+#include "ash/ash_export.h"
+#include "base/basictypes.h"
+
+namespace ash {
+
+// Interface for classes that want to be notified about user activity.
+// Implementations should register themselves with UserActivityDetector.
+class ASH_EXPORT UserActivityObserver {
+ public:
+ // Invoked periodically while the user is active (i.e. generating input
+ // events).
+ virtual void OnUserActivity() = 0;
+
+ protected:
+ UserActivityObserver() {}
+ virtual ~UserActivityObserver() {}
+
+ DISALLOW_COPY_AND_ASSIGN(UserActivityObserver);
+};
+
+} // namespace ash
+
+#endif // ASH_WM_USER_ACTIVITY_OBSERVER_H_
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
index 8d38e8e..f5218df 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
@@ -48,6 +48,7 @@
#include "chrome/browser/chromeos/power/resume_observer.h"
#include "chrome/browser/chromeos/power/screen_dimming_observer.h"
#include "chrome/browser/chromeos/power/screen_lock_observer.h"
+#include "chrome/browser/chromeos/power/user_activity_notifier.h"
#include "chrome/browser/chromeos/power/video_activity_notifier.h"
#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "chrome/browser/chromeos/system_key_event_listener.h"
@@ -451,6 +452,7 @@ void ChromeBrowserMainPartsChromeos::PostBrowserStart() {
// These are dependent on the ash::Shell singleton already having been
// initialized.
power_button_observer_.reset(new chromeos::PowerButtonObserver);
+ user_activity_notifier_.reset(new chromeos::UserActivityNotifier);
video_activity_notifier_.reset(new chromeos::VideoActivityNotifier);
screen_dimming_observer_.reset(new chromeos::ScreenDimmingObserver);
@@ -500,8 +502,9 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
chromeos::WebSocketProxyController::Shutdown();
- // Let VideoActivityNotifier unregister itself as an observer of the
- // ash::Shell singleton before the shell is destroyed.
+ // Let classes unregister themselves as observers of the ash::Shell singleton
+ // before the shell is destroyed.
+ user_activity_notifier_.reset();
video_activity_notifier_.reset();
// Detach D-Bus clients before DBusThreadManager is shut down.
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h
index 8890380..f924966 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h
@@ -17,6 +17,7 @@ class ResumeObserver;
class ScreenDimmingObserver;
class ScreenLockObserver;
class SessionManagerObserver;
+class UserActivityNotifier;
class VideoActivityNotifier;
} // namespace chromeos
@@ -56,6 +57,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux {
scoped_ptr<chromeos::SessionManagerObserver> session_manager_observer_;
scoped_ptr<chromeos::PowerButtonObserver> power_button_observer_;
scoped_ptr<chromeos::PowerStateOverride> power_state_override_;
+ scoped_ptr<chromeos::UserActivityNotifier> user_activity_notifier_;
scoped_ptr<chromeos::VideoActivityNotifier> video_activity_notifier_;
scoped_ptr<chromeos::ScreenDimmingObserver> screen_dimming_observer_;
scoped_ptr<policy::NetworkConfigurationUpdater> network_config_updater_;
diff --git a/chrome/browser/chromeos/power/user_activity_notifier.cc b/chrome/browser/chromeos/power/user_activity_notifier.cc
new file mode 100644
index 0000000..7daa77a1
--- /dev/null
+++ b/chrome/browser/chromeos/power/user_activity_notifier.cc
@@ -0,0 +1,40 @@
+// Copyright (c) 2012 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 "chrome/browser/chromeos/power/user_activity_notifier.h"
+
+#include "ash/shell.h"
+#include "ash/wm/user_activity_detector.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/power_manager_client.h"
+
+namespace {
+
+// Minimum number of seconds between notifications.
+const int kNotifyIntervalSec = 5;
+
+} // namespace
+
+namespace chromeos {
+
+UserActivityNotifier::UserActivityNotifier() {
+ ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this);
+}
+
+UserActivityNotifier::~UserActivityNotifier() {
+ ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this);
+}
+
+void UserActivityNotifier::OnUserActivity() {
+ base::TimeTicks now = base::TimeTicks::Now();
+ // InSeconds() truncates rather than rounding, so it's fine for this
+ // comparison.
+ if (last_notify_time_.is_null() ||
+ (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) {
+ DBusThreadManager::Get()->GetPowerManagerClient()->NotifyUserActivity(now);
+ last_notify_time_ = now;
+ }
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/power/user_activity_notifier.h b/chrome/browser/chromeos/power/user_activity_notifier.h
new file mode 100644
index 0000000..56fa3f3
--- /dev/null
+++ b/chrome/browser/chromeos/power/user_activity_notifier.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_POWER_USER_ACTIVITY_NOTIFIER_H_
+#define CHROME_BROWSER_CHROMEOS_POWER_USER_ACTIVITY_NOTIFIER_H_
+#pragma once
+
+#include "ash/wm/user_activity_observer.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/time.h"
+
+namespace chromeos {
+
+// Notifies the power manager when the user is active.
+class UserActivityNotifier : public ash::UserActivityObserver {
+ public:
+ UserActivityNotifier();
+ virtual ~UserActivityNotifier();
+
+ // ash::UserActivityObserver implementation.
+ virtual void OnUserActivity() OVERRIDE;
+
+ private:
+ // Last time that the power manager was notified.
+ base::TimeTicks last_notify_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserActivityNotifier);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_POWER_USER_ACTIVITY_NOTIFIER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index b48380fb..066a871 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -804,6 +804,8 @@
'browser/chromeos/power/screen_dimming_observer.h',
'browser/chromeos/power/screen_lock_observer.cc',
'browser/chromeos/power/screen_lock_observer.h',
+ 'browser/chromeos/power/user_activity_notifier.cc',
+ 'browser/chromeos/power/user_activity_notifier.h',
'browser/chromeos/power/video_activity_notifier.cc',
'browser/chromeos/power/video_activity_notifier.h',
'browser/chromeos/preferences.cc',
diff --git a/chromeos/dbus/mock_power_manager_client.h b/chromeos/dbus/mock_power_manager_client.h
index fc32e34..4a29e21 100644
--- a/chromeos/dbus/mock_power_manager_client.h
+++ b/chromeos/dbus/mock_power_manager_client.h
@@ -31,6 +31,7 @@ class MockPowerManagerClient : public PowerManagerClient {
MOCK_METHOD1(CalculateIdleTime, void(const CalculateIdleTimeCallback&));
MOCK_METHOD1(RequestIdleNotification, void(int64));
MOCK_METHOD0(RequestActiveNotification, void(void));
+ MOCK_METHOD1(NotifyUserActivity, void(const base::TimeTicks&));
MOCK_METHOD1(NotifyVideoActivity, void(const base::TimeTicks&));
MOCK_METHOD4(RequestPowerStateOverrides,
void(uint32,
diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc
index e3090de..5c712fd 100644
--- a/chromeos/dbus/power_manager_client.cc
+++ b/chromeos/dbus/power_manager_client.cc
@@ -255,6 +255,19 @@ class PowerManagerClientImpl : public PowerManagerClient {
RequestIdleNotification(0);
}
+ virtual void NotifyUserActivity(
+ const base::TimeTicks& last_activity_time) OVERRIDE {
+ dbus::MethodCall method_call(
+ power_manager::kPowerManagerInterface,
+ power_manager::kHandleUserActivityMethod);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendInt64(last_activity_time.ToInternalValue());
+ power_manager_proxy_->CallMethod(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ dbus::ObjectProxy::EmptyResponseCallback());
+ }
+
virtual void NotifyVideoActivity(
const base::TimeTicks& last_activity_time) OVERRIDE {
dbus::MethodCall method_call(
@@ -714,6 +727,8 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
virtual void RequestIdleNotification(int64 threshold) OVERRIDE {}
virtual void RequestActiveNotification() OVERRIDE {}
+ virtual void NotifyUserActivity(
+ const base::TimeTicks& last_activity_time) OVERRIDE {}
virtual void NotifyVideoActivity(
const base::TimeTicks& last_activity_time) OVERRIDE {}
virtual void RequestPowerStateOverrides(
diff --git a/chromeos/dbus/power_manager_client.h b/chromeos/dbus/power_manager_client.h
index d172c93..cced783 100644
--- a/chromeos/dbus/power_manager_client.h
+++ b/chromeos/dbus/power_manager_client.h
@@ -172,6 +172,11 @@ class CHROMEOS_EXPORT PowerManagerClient {
// NOTE: Like the previous request, this will also get triggered exactly once.
virtual void RequestActiveNotification() = 0;
+ // Notifies the power manager that the user is active (i.e. generating input
+ // events).
+ virtual void NotifyUserActivity(
+ const base::TimeTicks& last_activity_time) = 0;
+
// Notifies the power manager that a video is currently playing.
virtual void NotifyVideoActivity(
const base::TimeTicks& last_activity_time) = 0;