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/linux/x11_util.h" | 5 #include "remoting/host/linux/x11_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 | 8 |
9 namespace remoting { | 9 namespace remoting { |
10 | 10 |
11 static ScopedXErrorHandler* g_handler = NULL; | 11 static ScopedXErrorHandler* g_handler = nullptr; |
12 | 12 |
13 ScopedXErrorHandler::ScopedXErrorHandler(const Handler& handler): | 13 ScopedXErrorHandler::ScopedXErrorHandler(const Handler& handler): |
14 handler_(handler), | 14 handler_(handler), |
15 ok_(true) { | 15 ok_(true) { |
16 // This is a poor-man's check for incorrect usage. It doesn't handle the case | 16 // This is a poor-man's check for incorrect usage. It doesn't handle the case |
17 // where a mix of ScopedXErrorHandler and raw XSetErrorHandler calls are used, | 17 // where a mix of ScopedXErrorHandler and raw XSetErrorHandler calls are used, |
18 // and it disallows nested ScopedXErrorHandlers on the same thread, despite | 18 // and it disallows nested ScopedXErrorHandlers on the same thread, despite |
19 // these being perfectly safe. | 19 // these being perfectly safe. |
20 DCHECK(g_handler == NULL); | 20 DCHECK(g_handler == nullptr); |
21 g_handler = this; | 21 g_handler = this; |
22 previous_handler_ = XSetErrorHandler(HandleXErrors); | 22 previous_handler_ = XSetErrorHandler(HandleXErrors); |
23 } | 23 } |
24 | 24 |
25 ScopedXErrorHandler::~ScopedXErrorHandler() { | 25 ScopedXErrorHandler::~ScopedXErrorHandler() { |
26 g_handler = NULL; | 26 g_handler = nullptr; |
27 XSetErrorHandler(previous_handler_); | 27 XSetErrorHandler(previous_handler_); |
28 } | 28 } |
29 | 29 |
30 namespace { | 30 namespace { |
31 void IgnoreXErrors(Display* display, XErrorEvent* error) {} | 31 void IgnoreXErrors(Display* display, XErrorEvent* error) {} |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 // Static | 34 // Static |
35 ScopedXErrorHandler::Handler ScopedXErrorHandler::Ignore() { | 35 ScopedXErrorHandler::Handler ScopedXErrorHandler::Ignore() { |
36 return base::Bind(IgnoreXErrors); | 36 return base::Bind(IgnoreXErrors); |
37 } | 37 } |
38 | 38 |
39 int ScopedXErrorHandler::HandleXErrors(Display* display, XErrorEvent* error) { | 39 int ScopedXErrorHandler::HandleXErrors(Display* display, XErrorEvent* error) { |
40 DCHECK(g_handler != NULL); | 40 DCHECK(g_handler != nullptr); |
41 g_handler->ok_ = false; | 41 g_handler->ok_ = false; |
42 g_handler->handler_.Run(display, error); | 42 g_handler->handler_.Run(display, error); |
43 return 0; | 43 return 0; |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 ScopedXGrabServer::ScopedXGrabServer(Display* display) | 47 ScopedXGrabServer::ScopedXGrabServer(Display* display) |
48 : display_(display) { | 48 : display_(display) { |
49 XGrabServer(display_); | 49 XGrabServer(display_); |
50 } | 50 } |
51 | 51 |
52 ScopedXGrabServer::~ScopedXGrabServer() { | 52 ScopedXGrabServer::~ScopedXGrabServer() { |
53 XUngrabServer(display_); | 53 XUngrabServer(display_); |
54 XFlush(display_); | 54 XFlush(display_); |
55 } | 55 } |
56 | 56 |
57 } // namespace remoting | 57 } // namespace remoting |
OLD | NEW |