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

Side by Side Diff: remoting/host/local_input_monitor_thread_win.cc

Issue 10447041: Fix Ctrl+Alt+Esc keyboard shortcut in Me2Me host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/local_input_monitor_thread_win.h" 5 #include "remoting/host/local_input_monitor_thread_win.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9
10 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "remoting/host/mouse_move_observer.h"
11 #include "third_party/skia/include/core/SkPoint.h"
11 12
12 using namespace remoting; 13 using namespace remoting;
13 14
14 namespace { 15 namespace {
15 LocalInputMonitorThread* g_local_input_monitor_thread = NULL; 16 LocalInputMonitorThread* g_local_input_monitor_thread = NULL;
16 base::LazyInstance<base::Lock>::Leaky g_thread_lock = LAZY_INSTANCE_INITIALIZER; 17 base::LazyInstance<base::Lock>::Leaky g_thread_lock = LAZY_INSTANCE_INITIALIZER;
17 } // namespace 18 } // namespace
18 19
19
20 LocalInputMonitorThread::LocalInputMonitorThread() 20 LocalInputMonitorThread::LocalInputMonitorThread()
21 : base::SimpleThread("LocalInputMonitor") { 21 : base::SimpleThread("LocalInputMonitor") {
22 } 22 }
23 23
24 LocalInputMonitorThread::~LocalInputMonitorThread() { 24 LocalInputMonitorThread::~LocalInputMonitorThread() {
25 DCHECK(hosts_.empty()); 25 DCHECK(observers_.empty());
26 } 26 }
27 27
28 void LocalInputMonitorThread::AddHost(ChromotingHost* host) { 28 void LocalInputMonitorThread::AddObserver(
29 base::AutoLock lock(hosts_lock_); 29 MouseMoveObserver* mouse_move_observer) {
30 hosts_.insert(host); 30 base::AutoLock lock(lock_);
31 observers_.insert(mouse_move_observer);
31 } 32 }
32 33
33 bool LocalInputMonitorThread::RemoveHost(ChromotingHost* host) { 34 bool LocalInputMonitorThread::RemoveObserver(
34 base::AutoLock lock(hosts_lock_); 35 MouseMoveObserver* mouse_move_observer) {
35 hosts_.erase(host); 36 base::AutoLock lock(lock_);
36 return hosts_.empty(); 37 observers_.erase(mouse_move_observer);
38 return observers_.empty();
37 } 39 }
38 40
39 void LocalInputMonitorThread::Stop() { 41 void LocalInputMonitorThread::Stop() {
40 CHECK(PostThreadMessage(tid(), WM_QUIT, 0, 0)); 42 CHECK(PostThreadMessage(tid(), WM_QUIT, 0, 0));
41 Join(); 43 Join();
42 } 44 }
43 45
44 void LocalInputMonitorThread::Run() { 46 void LocalInputMonitorThread::Run() {
45 extern HMODULE g_hModule; 47 extern HMODULE g_hModule;
46 HHOOK win_event_hook = SetWindowsHookEx(WH_MOUSE_LL, HandleLowLevelMouseEvent, 48 HHOOK win_event_hook = SetWindowsHookEx(WH_MOUSE_LL, HandleLowLevelMouseEvent,
(...skipping 15 matching lines...) Expand all
62 DispatchMessage(&msg); 64 DispatchMessage(&msg);
63 } 65 }
64 } 66 }
65 67
66 if (win_event_hook) { 68 if (win_event_hook) {
67 CHECK(UnhookWindowsHookEx(win_event_hook)); 69 CHECK(UnhookWindowsHookEx(win_event_hook));
68 } 70 }
69 } 71 }
70 72
71 void LocalInputMonitorThread::LocalMouseMoved(const SkIPoint& mouse_position) { 73 void LocalInputMonitorThread::LocalMouseMoved(const SkIPoint& mouse_position) {
72 base::AutoLock lock(hosts_lock_); 74 base::AutoLock lock(lock_);
73 for (ChromotingHosts::const_iterator i = hosts_.begin(); 75 for (MouseMoveObservers::const_iterator i = observers_.begin();
74 i != hosts_.end(); ++i) { 76 i != observers_.end(); ++i) {
75 (*i)->LocalMouseMoved(mouse_position); 77 (*i)->OnLocalMouseMoved(mouse_position);
76 } 78 }
77 } 79 }
78 80
79 LRESULT WINAPI LocalInputMonitorThread::HandleLowLevelMouseEvent( 81 LRESULT WINAPI LocalInputMonitorThread::HandleLowLevelMouseEvent(
80 int code, WPARAM event_type, LPARAM event_data) { 82 int code, WPARAM event_type, LPARAM event_data) {
81 if (code == HC_ACTION) { 83 if (code == HC_ACTION) {
82 if (event_type == WM_MOUSEMOVE) { 84 if (event_type == WM_MOUSEMOVE) {
83 PMSLLHOOKSTRUCT data = reinterpret_cast<PMSLLHOOKSTRUCT>(event_data); 85 PMSLLHOOKSTRUCT data = reinterpret_cast<PMSLLHOOKSTRUCT>(event_data);
84 if ((data->flags & LLMHF_INJECTED) == 0) { 86 if ((data->flags & LLMHF_INJECTED) == 0) {
85 SkIPoint mouse_position = SkIPoint::Make(data->pt.x, data->pt.y); 87 SkIPoint mouse_position = SkIPoint::Make(data->pt.x, data->pt.y);
86 // |g_local_input_monitor_thread| cannot be NULL because this function 88 // |g_local_input_monitor_thread| cannot be NULL because this function
87 // is called from within the GetMessage call running on that thread. 89 // is called from within the GetMessage call running on that thread.
88 DCHECK(g_local_input_monitor_thread); 90 DCHECK(g_local_input_monitor_thread);
89 g_local_input_monitor_thread->LocalMouseMoved(mouse_position); 91 g_local_input_monitor_thread->LocalMouseMoved(mouse_position);
90 } 92 }
91 } 93 }
92 } 94 }
93 return CallNextHookEx(NULL, code, event_type, event_data); 95 return CallNextHookEx(NULL, code, event_type, event_data);
94 } 96 }
95 97
96 98
97 void LocalInputMonitorThread::AddHostToInputMonitor(ChromotingHost* host) { 99 // static
100 void LocalInputMonitorThread::AddMouseMoveObserver(
101 MouseMoveObserver* mouse_move_observer) {
98 base::AutoLock lock(g_thread_lock.Get()); 102 base::AutoLock lock(g_thread_lock.Get());
99 if (!g_local_input_monitor_thread) { 103 if (!g_local_input_monitor_thread) {
100 g_local_input_monitor_thread = new LocalInputMonitorThread; 104 g_local_input_monitor_thread = new LocalInputMonitorThread;
101 g_local_input_monitor_thread->Start(); 105 g_local_input_monitor_thread->Start();
102 } 106 }
103 g_local_input_monitor_thread->AddHost(host); 107 g_local_input_monitor_thread->AddObserver(mouse_move_observer);
104 } 108 }
105 109
106 void LocalInputMonitorThread::RemoveHostFromInputMonitor(ChromotingHost* host) { 110 // static
111 void LocalInputMonitorThread::RemoveMouseMoveObserver(
112 MouseMoveObserver* mouse_move_observer) {
107 DCHECK(g_local_input_monitor_thread); 113 DCHECK(g_local_input_monitor_thread);
108 base::AutoLock lock(g_thread_lock.Get()); 114 base::AutoLock lock(g_thread_lock.Get());
109 if (g_local_input_monitor_thread->RemoveHost(host)) { 115 if (g_local_input_monitor_thread->RemoveObserver(mouse_move_observer)) {
110 g_local_input_monitor_thread->Stop(); 116 g_local_input_monitor_thread->Stop();
111 delete g_local_input_monitor_thread; 117 delete g_local_input_monitor_thread;
112 g_local_input_monitor_thread = NULL; 118 g_local_input_monitor_thread = NULL;
113 } 119 }
114 } 120 }
OLDNEW
« no previous file with comments | « remoting/host/local_input_monitor_thread_win.h ('k') | remoting/host/local_input_monitor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698