| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/base/user_activity/user_activity_detector.h" | 5 #include "ui/base/user_activity/user_activity_detector.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // will be reported as user activity and turn the screen back on; too high | 46 // will be reported as user activity and turn the screen back on; too high |
| 47 // and we'll ignore legitimate activity. | 47 // and we'll ignore legitimate activity. |
| 48 const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000; | 48 const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000; |
| 49 | 49 |
| 50 UserActivityDetector::UserActivityDetector() { | 50 UserActivityDetector::UserActivityDetector() { |
| 51 CHECK(!g_instance); | 51 CHECK(!g_instance); |
| 52 g_instance = this; | 52 g_instance = this; |
| 53 | 53 |
| 54 ui::PlatformEventSource* platform_event_source = | 54 ui::PlatformEventSource* platform_event_source = |
| 55 ui::PlatformEventSource::GetInstance(); | 55 ui::PlatformEventSource::GetInstance(); |
| 56 // TODO(sad): Need a PES for mus. | 56 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 57 CHECK(platform_event_source); |
| 58 #endif |
| 57 if (platform_event_source) | 59 if (platform_event_source) |
| 58 platform_event_source->AddPlatformEventObserver(this); | 60 platform_event_source->AddPlatformEventObserver(this); |
| 59 } | 61 } |
| 60 | 62 |
| 61 UserActivityDetector::~UserActivityDetector() { | 63 UserActivityDetector::~UserActivityDetector() { |
| 62 ui::PlatformEventSource* platform_event_source = | 64 ui::PlatformEventSource* platform_event_source = |
| 63 ui::PlatformEventSource::GetInstance(); | 65 ui::PlatformEventSource::GetInstance(); |
| 66 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 67 CHECK(platform_event_source); |
| 68 #endif |
| 64 if (platform_event_source) | 69 if (platform_event_source) |
| 65 platform_event_source->RemovePlatformEventObserver(this); | 70 platform_event_source->RemovePlatformEventObserver(this); |
| 66 g_instance = nullptr; | 71 g_instance = nullptr; |
| 67 } | 72 } |
| 68 | 73 |
| 69 // static | 74 // static |
| 70 UserActivityDetector* UserActivityDetector::Get() { | 75 UserActivityDetector* UserActivityDetector::Get() { |
| 71 return g_instance; | 76 return g_instance; |
| 72 } | 77 } |
| 73 | 78 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 (now - last_observer_notification_time_).InMillisecondsF() >= | 126 (now - last_observer_notification_time_).InMillisecondsF() >= |
| 122 kNotifyIntervalMs) { | 127 kNotifyIntervalMs) { |
| 123 if (VLOG_IS_ON(1)) | 128 if (VLOG_IS_ON(1)) |
| 124 VLOG(1) << "Reporting user activity: " << GetEventDebugString(event); | 129 VLOG(1) << "Reporting user activity: " << GetEventDebugString(event); |
| 125 FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity(event)); | 130 FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity(event)); |
| 126 last_observer_notification_time_ = now; | 131 last_observer_notification_time_ = now; |
| 127 } | 132 } |
| 128 } | 133 } |
| 129 | 134 |
| 130 } // namespace ui | 135 } // namespace ui |
| OLD | NEW |