OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/power/user_activity_notifier.h" | 5 #include "ash/system/chromeos/power/user_activity_notifier.h" |
6 | 6 |
7 #include "ash/shell.h" | |
8 #include "ash/wm/user_activity_detector.h" | |
9 #include "chromeos/dbus/dbus_thread_manager.h" | 7 #include "chromeos/dbus/dbus_thread_manager.h" |
10 #include "chromeos/dbus/power_manager_client.h" | 8 #include "chromeos/dbus/power_manager_client.h" |
11 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
12 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
13 #include "ui/events/keycodes/keyboard_codes_posix.h" | 11 #include "ui/events/keycodes/keyboard_codes_posix.h" |
| 12 #include "ui/wm/core/user_activity_detector.h" |
14 | 13 |
15 namespace ash { | 14 namespace ash { |
16 namespace internal { | 15 namespace internal { |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 // Minimum number of seconds between notifications. | 19 // Minimum number of seconds between notifications. |
21 const int kNotifyIntervalSec = 5; | 20 const int kNotifyIntervalSec = 5; |
22 | 21 |
23 // Returns a UserActivityType describing |event|. | 22 // Returns a UserActivityType describing |event|. |
(...skipping 13 matching lines...) Expand all Loading... |
37 return power_manager::USER_ACTIVITY_VOLUME_MUTE_KEY_PRESS; | 36 return power_manager::USER_ACTIVITY_VOLUME_MUTE_KEY_PRESS; |
38 case ui::VKEY_VOLUME_UP: | 37 case ui::VKEY_VOLUME_UP: |
39 return power_manager::USER_ACTIVITY_VOLUME_UP_KEY_PRESS; | 38 return power_manager::USER_ACTIVITY_VOLUME_UP_KEY_PRESS; |
40 default: | 39 default: |
41 return power_manager::USER_ACTIVITY_OTHER; | 40 return power_manager::USER_ACTIVITY_OTHER; |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 } // namespace | 44 } // namespace |
46 | 45 |
47 UserActivityNotifier::UserActivityNotifier(UserActivityDetector* detector) | 46 UserActivityNotifier::UserActivityNotifier(::wm::UserActivityDetector* detector) |
48 : detector_(detector) { | 47 : detector_(detector) { |
49 detector_->AddObserver(this); | 48 detector_->AddObserver(this); |
50 } | 49 } |
51 | 50 |
52 UserActivityNotifier::~UserActivityNotifier() { | 51 UserActivityNotifier::~UserActivityNotifier() { |
53 detector_->RemoveObserver(this); | 52 detector_->RemoveObserver(this); |
54 } | 53 } |
55 | 54 |
56 void UserActivityNotifier::OnUserActivity(const ui::Event* event) { | 55 void UserActivityNotifier::OnUserActivity(const ui::Event* event) { |
57 base::TimeTicks now = base::TimeTicks::Now(); | 56 base::TimeTicks now = base::TimeTicks::Now(); |
58 // InSeconds() truncates rather than rounding, so it's fine for this | 57 // InSeconds() truncates rather than rounding, so it's fine for this |
59 // comparison. | 58 // comparison. |
60 if (last_notify_time_.is_null() || | 59 if (last_notify_time_.is_null() || |
61 (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) { | 60 (now - last_notify_time_).InSeconds() >= kNotifyIntervalSec) { |
62 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 61 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
63 NotifyUserActivity(GetUserActivityTypeForEvent(event)); | 62 NotifyUserActivity(GetUserActivityTypeForEvent(event)); |
64 last_notify_time_ = now; | 63 last_notify_time_ = now; |
65 } | 64 } |
66 } | 65 } |
67 | 66 |
68 } // namespace internal | 67 } // namespace internal |
69 } // namespace ash | 68 } // namespace ash |
OLD | NEW |