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 CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
6 #define CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 6 #define CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 public base::PowerObserver, | 22 public base::PowerObserver, |
23 public base::RefCountedThreadSafe<GpuWatchdogThread> { | 23 public base::RefCountedThreadSafe<GpuWatchdogThread> { |
24 public: | 24 public: |
25 explicit GpuWatchdogThread(int timeout); | 25 explicit GpuWatchdogThread(int timeout); |
26 | 26 |
27 // Accessible on watched thread but only modified by watchdog thread. | 27 // Accessible on watched thread but only modified by watchdog thread. |
28 bool armed() const { return armed_; } | 28 bool armed() const { return armed_; } |
29 void PostAcknowledge(); | 29 void PostAcknowledge(); |
30 | 30 |
31 // Implement GpuWatchdog. | 31 // Implement GpuWatchdog. |
32 virtual void CheckArmed() override; | 32 void CheckArmed() override; |
33 | 33 |
34 // Must be called after a PowerMonitor has been created. Can be called from | 34 // Must be called after a PowerMonitor has been created. Can be called from |
35 // any thread. | 35 // any thread. |
36 void AddPowerObserver(); | 36 void AddPowerObserver(); |
37 | 37 |
38 protected: | 38 protected: |
39 virtual void Init() override; | 39 void Init() override; |
40 virtual void CleanUp() override; | 40 void CleanUp() override; |
41 | 41 |
42 private: | 42 private: |
43 friend class base::RefCountedThreadSafe<GpuWatchdogThread>; | 43 friend class base::RefCountedThreadSafe<GpuWatchdogThread>; |
44 | 44 |
45 // An object of this type intercepts the reception and completion of all tasks | 45 // An object of this type intercepts the reception and completion of all tasks |
46 // on the watched thread and checks whether the watchdog is armed. | 46 // on the watched thread and checks whether the watchdog is armed. |
47 class GpuWatchdogTaskObserver : public base::MessageLoop::TaskObserver { | 47 class GpuWatchdogTaskObserver : public base::MessageLoop::TaskObserver { |
48 public: | 48 public: |
49 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); | 49 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); |
50 virtual ~GpuWatchdogTaskObserver(); | 50 ~GpuWatchdogTaskObserver() override; |
51 | 51 |
52 // Implements MessageLoop::TaskObserver. | 52 // Implements MessageLoop::TaskObserver. |
53 virtual void WillProcessTask( | 53 void WillProcessTask(const base::PendingTask& pending_task) override; |
54 const base::PendingTask& pending_task) override; | 54 void DidProcessTask(const base::PendingTask& pending_task) override; |
55 virtual void DidProcessTask(const base::PendingTask& pending_task) override; | |
56 | 55 |
57 private: | 56 private: |
58 GpuWatchdogThread* watchdog_; | 57 GpuWatchdogThread* watchdog_; |
59 }; | 58 }; |
60 | 59 |
61 virtual ~GpuWatchdogThread(); | 60 ~GpuWatchdogThread() override; |
62 | 61 |
63 void OnAcknowledge(); | 62 void OnAcknowledge(); |
64 void OnCheck(bool after_suspend); | 63 void OnCheck(bool after_suspend); |
65 void DeliberatelyTerminateToRecoverFromHang(); | 64 void DeliberatelyTerminateToRecoverFromHang(); |
66 | 65 |
67 void OnAddPowerObserver(); | 66 void OnAddPowerObserver(); |
68 | 67 |
69 // Implement PowerObserver. | 68 // Implement PowerObserver. |
70 virtual void OnSuspend() override; | 69 void OnSuspend() override; |
71 virtual void OnResume() override; | 70 void OnResume() override; |
72 | 71 |
73 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
74 base::TimeDelta GetWatchedThreadTime(); | 73 base::TimeDelta GetWatchedThreadTime(); |
75 #endif | 74 #endif |
76 | 75 |
77 base::MessageLoop* watched_message_loop_; | 76 base::MessageLoop* watched_message_loop_; |
78 base::TimeDelta timeout_; | 77 base::TimeDelta timeout_; |
79 volatile bool armed_; | 78 volatile bool armed_; |
80 GpuWatchdogTaskObserver task_observer_; | 79 GpuWatchdogTaskObserver task_observer_; |
81 | 80 |
(...skipping 13 matching lines...) Expand all Loading... |
95 #endif | 94 #endif |
96 | 95 |
97 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; | 96 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; |
98 | 97 |
99 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); | 98 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); |
100 }; | 99 }; |
101 | 100 |
102 } // namespace content | 101 } // namespace content |
103 | 102 |
104 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 103 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
OLD | NEW |