OLD | NEW |
1 // Copyright (c) 2011 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.h" | 5 #include "remoting/host/local_input_monitor.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 LocalInputMonitorMac() : host_(NULL) {} | 150 LocalInputMonitorMac() : host_(NULL) {} |
151 virtual ~LocalInputMonitorMac(); | 151 virtual ~LocalInputMonitorMac(); |
152 virtual void Start(remoting::ChromotingHost* host) OVERRIDE; | 152 virtual void Start(remoting::ChromotingHost* host) OVERRIDE; |
153 virtual void Stop() OVERRIDE; | 153 virtual void Stop() OVERRIDE; |
154 | 154 |
155 private: | 155 private: |
156 remoting::ChromotingHost* host_; | 156 remoting::ChromotingHost* host_; |
157 DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorMac); | 157 DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorMac); |
158 }; | 158 }; |
159 | 159 |
160 base::LazyInstance<base::Lock, | 160 base::LazyInstance<base::Lock>::Leaky monitor_lock = LAZY_INSTANCE_INITIALIZER; |
161 base::LeakyLazyInstanceTraits<base::Lock> > | |
162 monitor_lock = LAZY_INSTANCE_INITIALIZER; | |
163 LocalInputMonitorImpl* local_input_monitor = NULL; | 161 LocalInputMonitorImpl* local_input_monitor = NULL; |
164 | 162 |
165 } // namespace | 163 } // namespace |
166 | 164 |
167 LocalInputMonitorMac::~LocalInputMonitorMac() { | 165 LocalInputMonitorMac::~LocalInputMonitorMac() { |
168 Stop(); | 166 Stop(); |
169 } | 167 } |
170 | 168 |
171 void LocalInputMonitorMac::Start(remoting::ChromotingHost* host) { | 169 void LocalInputMonitorMac::Start(remoting::ChromotingHost* host) { |
172 base::AutoLock lock(monitor_lock.Get()); | 170 base::AutoLock lock(monitor_lock.Get()); |
173 if (!local_input_monitor) | 171 if (!local_input_monitor) |
174 local_input_monitor = [[LocalInputMonitorImpl alloc] init]; | 172 local_input_monitor = [[LocalInputMonitorImpl alloc] init]; |
175 CHECK(local_input_monitor); | 173 CHECK(local_input_monitor); |
176 [local_input_monitor addHost:host]; | 174 [local_input_monitor addHost:host]; |
177 host_ = host; | 175 host_ = host; |
178 } | 176 } |
179 | 177 |
180 void LocalInputMonitorMac::Stop() { | 178 void LocalInputMonitorMac::Stop() { |
181 base::AutoLock lock(monitor_lock.Get()); | 179 base::AutoLock lock(monitor_lock.Get()); |
182 if ([local_input_monitor removeHost:host_]) { | 180 if ([local_input_monitor removeHost:host_]) { |
183 [local_input_monitor invalidate]; | 181 [local_input_monitor invalidate]; |
184 [local_input_monitor release]; | 182 [local_input_monitor release]; |
185 local_input_monitor = nil; | 183 local_input_monitor = nil; |
186 } | 184 } |
187 } | 185 } |
188 | 186 |
189 remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() { | 187 remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() { |
190 return new LocalInputMonitorMac; | 188 return new LocalInputMonitorMac; |
191 } | 189 } |
OLD | NEW |