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 "chrome/browser/chrome_browser_main_extra_parts_x11.h" | 5 #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/debugger.h" | 8 #include "base/debug/debugger.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 12 #include "chrome/browser/lifetime/application_lifetime.h" |
11 #include "chrome/common/chrome_result_codes.h" | 13 #include "chrome/common/chrome_result_codes.h" |
12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
13 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
14 #include "ui/base/x/x11_util_internal.h" | 16 #include "ui/base/x/x11_util_internal.h" |
15 | 17 |
16 using content::BrowserThread; | 18 using content::BrowserThread; |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // Indicates that we're currently responding to an IO error (by shutting down). | 22 // Indicates that we're currently responding to an IO error (by shutting down). |
21 bool g_in_x11_io_error_handler = false; | 23 bool g_in_x11_io_error_handler = false; |
22 | 24 |
23 // Number of seconds to wait for UI thread to get an IO error if we get it on | 25 // Number of seconds to wait for UI thread to get an IO error if we get it on |
24 // the background thread. | 26 // the background thread. |
25 const int kWaitForUIThreadSeconds = 10; | 27 const int kWaitForUIThreadSeconds = 10; |
26 | 28 |
27 int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { | 29 int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { |
28 if (!g_in_x11_io_error_handler) | 30 if (!g_in_x11_io_error_handler) |
29 base::MessageLoop::current()->PostTask( | 31 base::ThreadTaskRunnerHandle::Get()->PostTask( |
30 FROM_HERE, | 32 FROM_HERE, base::Bind(&ui::LogErrorEventDescription, d, *error)); |
31 base::Bind(&ui::LogErrorEventDescription, d, *error)); | |
32 return 0; | 33 return 0; |
33 } | 34 } |
34 | 35 |
35 | 36 |
36 // This function is used to help us diagnose crash dumps that happen | 37 // This function is used to help us diagnose crash dumps that happen |
37 // during the shutdown process. | 38 // during the shutdown process. |
38 NOINLINE void WaitingForUIThreadToHandleIOError() { | 39 NOINLINE void WaitingForUIThreadToHandleIOError() { |
39 // Ensure function isn't optimized away. | 40 // Ensure function isn't optimized away. |
40 asm(""); | 41 asm(""); |
41 sleep(kWaitForUIThreadSeconds); | 42 sleep(kWaitForUIThreadSeconds); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // if X exits before us. | 90 // if X exits before us. |
90 ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); | 91 ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); |
91 } | 92 } |
92 | 93 |
93 void ChromeBrowserMainExtraPartsX11::PostMainMessageLoopRun() { | 94 void ChromeBrowserMainExtraPartsX11::PostMainMessageLoopRun() { |
94 // Unset the X11 error handlers. The X11 error handlers log the errors using a | 95 // Unset the X11 error handlers. The X11 error handlers log the errors using a |
95 // |PostTask()| on the message-loop. But since the message-loop is in the | 96 // |PostTask()| on the message-loop. But since the message-loop is in the |
96 // process of terminating, this can cause errors. | 97 // process of terminating, this can cause errors. |
97 ui::SetX11ErrorHandlers(X11EmptyErrorHandler, X11EmptyIOErrorHandler); | 98 ui::SetX11ErrorHandlers(X11EmptyErrorHandler, X11EmptyIOErrorHandler); |
98 } | 99 } |
OLD | NEW |