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

Side by Side Diff: media/base/user_input_monitor.cc

Issue 23190045: Switch ObserverList::size() to ObserverList::might_have_observers() Pt.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/notification_service_impl.cc ('k') | net/dns/mdns_client_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "media/base/user_input_monitor.h" 5 #include "media/base/user_input_monitor.h"
6 6
7 #include "third_party/skia/include/core/SkPoint.h" 7 #include "third_party/skia/include/core/SkPoint.h"
8 8
9 namespace media { 9 namespace media {
10 10
(...skipping 15 matching lines...) Expand all
26 mouse_listeners_.AddObserver(listener); 26 mouse_listeners_.AddObserver(listener);
27 if (!monitoring_mouse_) { 27 if (!monitoring_mouse_) {
28 StartMouseMonitoring(); 28 StartMouseMonitoring();
29 monitoring_mouse_ = true; 29 monitoring_mouse_ = true;
30 DVLOG(2) << "Started mouse monitoring."; 30 DVLOG(2) << "Started mouse monitoring.";
31 } 31 }
32 } 32 }
33 void UserInputMonitor::RemoveMouseListener(MouseEventListener* listener) { 33 void UserInputMonitor::RemoveMouseListener(MouseEventListener* listener) {
34 base::AutoLock auto_lock(lock_); 34 base::AutoLock auto_lock(lock_);
35 mouse_listeners_.RemoveObserver(listener); 35 mouse_listeners_.RemoveObserver(listener);
36 if (mouse_listeners_.size() == 0) { 36 if (!mouse_listeners_.might_have_observers()) {
37 StopMouseMonitoring(); 37 StopMouseMonitoring();
38 monitoring_mouse_ = false; 38 monitoring_mouse_ = false;
39 DVLOG(2) << "Stopped mouse monitoring."; 39 DVLOG(2) << "Stopped mouse monitoring.";
40 } 40 }
41 } 41 }
42 void UserInputMonitor::AddKeyStrokeListener(KeyStrokeListener* listener) { 42 void UserInputMonitor::AddKeyStrokeListener(KeyStrokeListener* listener) {
43 base::AutoLock auto_lock(lock_); 43 base::AutoLock auto_lock(lock_);
44 key_stroke_listeners_.AddObserver(listener); 44 key_stroke_listeners_.AddObserver(listener);
45 if (!monitoring_keyboard_) { 45 if (!monitoring_keyboard_) {
46 StartKeyboardMonitoring(); 46 StartKeyboardMonitoring();
47 monitoring_keyboard_ = true; 47 monitoring_keyboard_ = true;
48 DVLOG(2) << "Started keyboard monitoring."; 48 DVLOG(2) << "Started keyboard monitoring.";
49 } 49 }
50 } 50 }
51 void UserInputMonitor::RemoveKeyStrokeListener(KeyStrokeListener* listener) { 51 void UserInputMonitor::RemoveKeyStrokeListener(KeyStrokeListener* listener) {
52 base::AutoLock auto_lock(lock_); 52 base::AutoLock auto_lock(lock_);
53 key_stroke_listeners_.RemoveObserver(listener); 53 key_stroke_listeners_.RemoveObserver(listener);
54 if (key_stroke_listeners_.size() == 0) { 54 if (!key_stroke_listeners_.might_have_observers()) {
55 StopKeyboardMonitoring(); 55 StopKeyboardMonitoring();
56 monitoring_keyboard_ = false; 56 monitoring_keyboard_ = false;
57 DVLOG(2) << "Stopped keyboard monitoring."; 57 DVLOG(2) << "Stopped keyboard monitoring.";
58 } 58 }
59 } 59 }
60 60
61 UserInputMonitor::UserInputMonitor() 61 UserInputMonitor::UserInputMonitor()
62 : monitoring_mouse_(false), monitoring_keyboard_(false) {} 62 : monitoring_mouse_(false), monitoring_keyboard_(false) {}
63 63
64 void UserInputMonitor::OnMouseEvent(const SkIPoint& position) { 64 void UserInputMonitor::OnMouseEvent(const SkIPoint& position) {
(...skipping 13 matching lines...) Expand all
78 DVLOG(6) << "Key stroke detected."; 78 DVLOG(6) << "Key stroke detected.";
79 FOR_EACH_OBSERVER(KeyStrokeListener, key_stroke_listeners_, OnKeyStroke()); 79 FOR_EACH_OBSERVER(KeyStrokeListener, key_stroke_listeners_, OnKeyStroke());
80 } else { 80 } else {
81 DCHECK_EQ(ui::ET_KEY_RELEASED, event); 81 DCHECK_EQ(ui::ET_KEY_RELEASED, event);
82 DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end()); 82 DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end());
83 pressed_keys_.erase(key_code); 83 pressed_keys_.erase(key_code);
84 } 84 }
85 } 85 }
86 86
87 } // namespace media 87 } // namespace media
OLDNEW
« no previous file with comments | « content/browser/notification_service_impl.cc ('k') | net/dns/mdns_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698