| OLD | NEW |
| 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.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" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 - (bool)removeHost:(remoting::ChromotingHost*)host { | 138 - (bool)removeHost:(remoting::ChromotingHost*)host { |
| 139 base::AutoLock lock(hostsLock_); | 139 base::AutoLock lock(hostsLock_); |
| 140 hosts_.erase(host); | 140 hosts_.erase(host); |
| 141 return hosts_.empty(); | 141 return hosts_.empty(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 @end | 144 @end |
| 145 | 145 |
| 146 namespace remoting { |
| 147 |
| 146 namespace { | 148 namespace { |
| 147 | 149 |
| 148 class LocalInputMonitorMac : public remoting::LocalInputMonitor { | 150 class LocalInputMonitorMac : public LocalInputMonitor { |
| 149 public: | 151 public: |
| 150 LocalInputMonitorMac() : host_(NULL) {} | 152 LocalInputMonitorMac() : host_(NULL) {} |
| 151 virtual ~LocalInputMonitorMac(); | 153 virtual ~LocalInputMonitorMac(); |
| 152 virtual void Start(remoting::ChromotingHost* host) OVERRIDE; | 154 virtual void Start(ChromotingHost* host) OVERRIDE; |
| 153 virtual void Stop() OVERRIDE; | 155 virtual void Stop() OVERRIDE; |
| 154 | 156 |
| 155 private: | 157 private: |
| 156 remoting::ChromotingHost* host_; | 158 ChromotingHost* host_; |
| 157 DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorMac); | 159 DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorMac); |
| 158 }; | 160 }; |
| 159 | 161 |
| 160 base::LazyInstance<base::Lock>::Leaky monitor_lock = LAZY_INSTANCE_INITIALIZER; | 162 base::LazyInstance<base::Lock>::Leaky monitor_lock = LAZY_INSTANCE_INITIALIZER; |
| 161 LocalInputMonitorImpl* local_input_monitor = NULL; | 163 LocalInputMonitorImpl* local_input_monitor = NULL; |
| 162 | 164 |
| 163 } // namespace | 165 } // namespace |
| 164 | 166 |
| 165 LocalInputMonitorMac::~LocalInputMonitorMac() { | 167 LocalInputMonitorMac::~LocalInputMonitorMac() { |
| 166 Stop(); | 168 Stop(); |
| 167 } | 169 } |
| 168 | 170 |
| 169 void LocalInputMonitorMac::Start(remoting::ChromotingHost* host) { | 171 void LocalInputMonitorMac::Start(ChromotingHost* host) { |
| 170 base::AutoLock lock(monitor_lock.Get()); | 172 base::AutoLock lock(monitor_lock.Get()); |
| 171 if (!local_input_monitor) | 173 if (!local_input_monitor) |
| 172 local_input_monitor = [[LocalInputMonitorImpl alloc] init]; | 174 local_input_monitor = [[LocalInputMonitorImpl alloc] init]; |
| 173 CHECK(local_input_monitor); | 175 CHECK(local_input_monitor); |
| 174 [local_input_monitor addHost:host]; | 176 [local_input_monitor addHost:host]; |
| 175 host_ = host; | 177 host_ = host; |
| 176 } | 178 } |
| 177 | 179 |
| 178 void LocalInputMonitorMac::Stop() { | 180 void LocalInputMonitorMac::Stop() { |
| 179 base::AutoLock lock(monitor_lock.Get()); | 181 base::AutoLock lock(monitor_lock.Get()); |
| 180 if ([local_input_monitor removeHost:host_]) { | 182 if ([local_input_monitor removeHost:host_]) { |
| 181 [local_input_monitor invalidate]; | 183 [local_input_monitor invalidate]; |
| 182 [local_input_monitor release]; | 184 [local_input_monitor release]; |
| 183 local_input_monitor = nil; | 185 local_input_monitor = nil; |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 | 188 |
| 187 remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() { | 189 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create() { |
| 188 return new LocalInputMonitorMac; | 190 return scoped_ptr<LocalInputMonitor>(new LocalInputMonitorMac()); |
| 189 } | 191 } |
| 192 |
| 193 } // namespace remoting |
| OLD | NEW |