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 #ifndef CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 5 #ifndef GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ |
6 #define CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 6 #define GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/power_monitor/power_observer.h" | 12 #include "base/power_monitor/power_observer.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "gpu/gpu_export.h" | |
16 #include "gpu/ipc/service/gpu_watchdog.h" | 17 #include "gpu/ipc/service/gpu_watchdog.h" |
17 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
18 | 19 |
19 #if defined(USE_X11) | 20 #if defined(USE_X11) |
20 extern "C" { | 21 extern "C" { |
21 #include <X11/Xlib.h> | 22 #include <X11/Xlib.h> |
22 #include <X11/Xatom.h> | 23 #include <X11/Xatom.h> |
23 } | 24 } |
24 #include <sys/poll.h> | 25 #include <sys/poll.h> |
25 #include "ui/base/x/x11_util.h" // nogncheck | 26 #include "ui/base/x/x11_util.h" // nogncheck |
26 #include "ui/gfx/x/x11_types.h" // nogncheck | 27 #include "ui/gfx/x/x11_types.h" // nogncheck |
27 #endif | 28 #endif // defined(USE_X11) |
28 | 29 |
29 namespace content { | 30 namespace gpu { |
30 | 31 |
31 // A thread that intermitently sends tasks to a group of watched message loops | 32 // A thread that intermitently sends tasks to a group of watched message loops |
32 // and deliberately crashes if one of them does not respond after a timeout. | 33 // and deliberately crashes if one of them does not respond after a timeout. |
33 class GpuWatchdogThread : public base::Thread, | 34 class GPU_EXPORT GpuWatchdogThread |
34 public gpu::GpuWatchdog, | 35 : public base::Thread, |
35 public base::PowerObserver, | 36 NON_EXPORTED_BASE(public GpuWatchdog), |
sadrul
2016/08/28 13:01:58
There's no other subclass of GpuWatchdog, and now
Fady Samuel
2016/08/29 16:41:37
Since this isn't used in tests, this seems like a
sadrul
2016/08/29 20:00:32
Done.
| |
36 public base::RefCountedThreadSafe<GpuWatchdogThread> { | 37 public base::PowerObserver, |
38 public base::RefCountedThreadSafe<GpuWatchdogThread> { | |
37 public: | 39 public: |
38 explicit GpuWatchdogThread(int timeout); | 40 static scoped_refptr<GpuWatchdogThread> Create(); |
39 | 41 |
40 // Accessible on watched thread but only modified by watchdog thread. | 42 // Accessible on watched thread but only modified by watchdog thread. |
41 bool armed() const { return armed_; } | 43 bool armed() const { return armed_; } |
42 void PostAcknowledge(); | 44 void PostAcknowledge(); |
43 | 45 |
44 // Implement gpu::GpuWatchdog. | 46 // Implement GpuWatchdog. |
45 void CheckArmed() override; | 47 void CheckArmed() override; |
46 | 48 |
47 // Must be called after a PowerMonitor has been created. Can be called from | 49 // Must be called after a PowerMonitor has been created. Can be called from |
48 // any thread. | 50 // any thread. |
49 void AddPowerObserver(); | 51 void AddPowerObserver(); |
50 | 52 |
51 protected: | 53 protected: |
52 void Init() override; | 54 void Init() override; |
53 void CleanUp() override; | 55 void CleanUp() override; |
54 | 56 |
55 private: | 57 private: |
56 friend class base::RefCountedThreadSafe<GpuWatchdogThread>; | 58 friend class base::RefCountedThreadSafe<GpuWatchdogThread>; |
57 | 59 |
58 // An object of this type intercepts the reception and completion of all tasks | 60 // An object of this type intercepts the reception and completion of all tasks |
59 // on the watched thread and checks whether the watchdog is armed. | 61 // on the watched thread and checks whether the watchdog is armed. |
60 class GpuWatchdogTaskObserver : public base::MessageLoop::TaskObserver { | 62 class GpuWatchdogTaskObserver : public base::MessageLoop::TaskObserver { |
61 public: | 63 public: |
62 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); | 64 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); |
63 ~GpuWatchdogTaskObserver() override; | 65 ~GpuWatchdogTaskObserver() override; |
64 | 66 |
65 // Implements MessageLoop::TaskObserver. | 67 // Implements MessageLoop::TaskObserver. |
66 void WillProcessTask(const base::PendingTask& pending_task) override; | 68 void WillProcessTask(const base::PendingTask& pending_task) override; |
67 void DidProcessTask(const base::PendingTask& pending_task) override; | 69 void DidProcessTask(const base::PendingTask& pending_task) override; |
68 | 70 |
69 private: | 71 private: |
70 GpuWatchdogThread* watchdog_; | 72 GpuWatchdogThread* watchdog_; |
71 }; | 73 }; |
72 | 74 |
75 GpuWatchdogThread(); | |
73 ~GpuWatchdogThread() override; | 76 ~GpuWatchdogThread() override; |
74 | 77 |
75 void OnAcknowledge(); | 78 void OnAcknowledge(); |
76 void OnCheck(bool after_suspend); | 79 void OnCheck(bool after_suspend); |
77 void DeliberatelyTerminateToRecoverFromHang(); | 80 void DeliberatelyTerminateToRecoverFromHang(); |
78 #if defined(USE_X11) | 81 #if defined(USE_X11) |
79 void SetupXServer(); | 82 void SetupXServer(); |
80 void SetupXChangeProp(); | 83 void SetupXChangeProp(); |
81 bool MatchXEventAtom(XEvent* event); | 84 bool MatchXEventAtom(XEvent* event); |
82 #endif | 85 #endif |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 XAtom atom_; | 140 XAtom atom_; |
138 FILE* tty_file_; | 141 FILE* tty_file_; |
139 int host_tty_; | 142 int host_tty_; |
140 #endif | 143 #endif |
141 | 144 |
142 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; | 145 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; |
143 | 146 |
144 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); | 147 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); |
145 }; | 148 }; |
146 | 149 |
147 } // namespace content | 150 } // namespace gpu |
148 | 151 |
149 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 152 #endif // GPU_IPC_SERVICE_GPU_WATCHDOG_THREAD_H_ |
OLD | NEW |