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

Side by Side Diff: ui/wm/core/user_activity_detector.cc

Issue 693643004: Make UserActivityDetector a singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@athena_do_not_use_ash45
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « ui/wm/core/user_activity_detector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm/core/user_activity_detector.h" 5 #include "ui/wm/core/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 "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/wm/core/user_activity_observer.h" 11 #include "ui/wm/core/user_activity_observer.h"
12 12
13 namespace wm { 13 namespace wm {
14 14
15 namespace { 15 namespace {
16 16
17 UserActivityDetector* g_instance = nullptr;
18
17 // Returns a string describing |event|. 19 // Returns a string describing |event|.
18 std::string GetEventDebugString(const ui::Event* event) { 20 std::string GetEventDebugString(const ui::Event* event) {
19 std::string details = base::StringPrintf( 21 std::string details = base::StringPrintf(
20 "type=%d name=%s flags=%d time=%" PRId64, 22 "type=%d name=%s flags=%d time=%" PRId64,
21 event->type(), event->name().c_str(), event->flags(), 23 event->type(), event->name().c_str(), event->flags(),
22 event->time_stamp().InMilliseconds()); 24 event->time_stamp().InMilliseconds());
23 25
24 if (event->IsKeyEvent()) { 26 if (event->IsKeyEvent()) {
25 details += base::StringPrintf(" key_code=%d", 27 details += base::StringPrintf(" key_code=%d",
26 static_cast<const ui::KeyEvent*>(event)->key_code()); 28 static_cast<const ui::KeyEvent*>(event)->key_code());
(...skipping 10 matching lines...) Expand all
37 } // namespace 39 } // namespace
38 40
39 const int UserActivityDetector::kNotifyIntervalMs = 200; 41 const int UserActivityDetector::kNotifyIntervalMs = 200;
40 42
41 // Too low and mouse events generated at the tail end of reconfiguration 43 // Too low and mouse events generated at the tail end of reconfiguration
42 // will be reported as user activity and turn the screen back on; too high 44 // will be reported as user activity and turn the screen back on; too high
43 // and we'll ignore legitimate activity. 45 // and we'll ignore legitimate activity.
44 const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000; 46 const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000;
45 47
46 UserActivityDetector::UserActivityDetector() { 48 UserActivityDetector::UserActivityDetector() {
49 CHECK(!g_instance);
50 g_instance = this;
47 } 51 }
48 52
49 UserActivityDetector::~UserActivityDetector() { 53 UserActivityDetector::~UserActivityDetector() {
54 g_instance = nullptr;
55 }
56
57 // static
58 UserActivityDetector* UserActivityDetector::Get() {
59 return g_instance;
50 } 60 }
51 61
52 bool UserActivityDetector::HasObserver(UserActivityObserver* observer) const { 62 bool UserActivityDetector::HasObserver(UserActivityObserver* observer) const {
53 return observers_.HasObserver(observer); 63 return observers_.HasObserver(observer);
54 } 64 }
55 65
56 void UserActivityDetector::AddObserver(UserActivityObserver* observer) { 66 void UserActivityDetector::AddObserver(UserActivityObserver* observer) {
57 observers_.AddObserver(observer); 67 observers_.AddObserver(observer);
58 } 68 }
59 69
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 (now - last_observer_notification_time_).InMillisecondsF() >= 113 (now - last_observer_notification_time_).InMillisecondsF() >=
104 kNotifyIntervalMs) { 114 kNotifyIntervalMs) {
105 if (VLOG_IS_ON(1)) 115 if (VLOG_IS_ON(1))
106 VLOG(1) << "Reporting user activity: " << GetEventDebugString(event); 116 VLOG(1) << "Reporting user activity: " << GetEventDebugString(event);
107 FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity(event)); 117 FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity(event));
108 last_observer_notification_time_ = now; 118 last_observer_notification_time_ = now;
109 } 119 }
110 } 120 }
111 121
112 } // namespace wm 122 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/user_activity_detector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698