[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gfx / x / x11_error_tracker.cc
blob859e71824a3e4876fce27623a89b6613c38dfb4d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gfx/x/x11_error_tracker.h"
7 #include "base/logging.h"
8 #include "ui/gfx/x/x11_types.h"
10 namespace {
12 unsigned char g_x11_error_code = 0;
13 static gfx::X11ErrorTracker* g_handler = NULL;
15 int X11ErrorHandler(Display* display, XErrorEvent* error) {
16 g_x11_error_code = error->error_code;
17 return 0;
20 } // namespace
22 namespace gfx {
24 X11ErrorTracker::X11ErrorTracker() {
25 // This is a poor-man's check for incorrect usage. It disallows nested
26 // X11ErrorTracker instances on the same thread.
27 DCHECK(g_handler == NULL);
28 g_handler = this;
29 XSync(GetXDisplay(), False);
30 old_handler_ = XSetErrorHandler(X11ErrorHandler);
31 g_x11_error_code = 0;
34 X11ErrorTracker::~X11ErrorTracker() {
35 g_handler = NULL;
36 XSetErrorHandler(old_handler_);
39 bool X11ErrorTracker::FoundNewError() {
40 XSync(GetXDisplay(), False);
41 unsigned char error = g_x11_error_code;
42 g_x11_error_code = 0;
43 return error != 0;
46 } // namespace gfx