[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / gpu / gpu_watchdog_thread.h
blob37acfe4926b028d0a899fdaecc6207c0cde6cad4
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_GPU_GPU_WATCHDOG_THREAD_H_
6 #define CONTENT_GPU_GPU_WATCHDOG_THREAD_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop.h"
11 #include "base/threading/thread.h"
12 #include "base/time.h"
13 #include "content/common/gpu/gpu_watchdog.h"
15 namespace content {
17 // A thread that intermitently sends tasks to a group of watched message loops
18 // and deliberately crashes if one of them does not respond after a timeout.
19 class GpuWatchdogThread : public base::Thread,
20 public GpuWatchdog,
21 public base::RefCountedThreadSafe<GpuWatchdogThread> {
22 public:
23 explicit GpuWatchdogThread(int timeout);
25 // Accessible on watched thread but only modified by watchdog thread.
26 bool armed() const { return armed_; }
27 void PostAcknowledge();
29 // Implement GpuWatchdog.
30 virtual void CheckArmed() OVERRIDE;
32 protected:
33 virtual void Init() OVERRIDE;
34 virtual void CleanUp() OVERRIDE;
36 private:
37 friend class base::RefCountedThreadSafe<GpuWatchdogThread>;
39 // An object of this type intercepts the reception and completion of all tasks
40 // on the watched thread and checks whether the watchdog is armed.
41 class GpuWatchdogTaskObserver : public MessageLoop::TaskObserver {
42 public:
43 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog);
44 virtual ~GpuWatchdogTaskObserver();
46 // Implements MessageLoop::TaskObserver.
47 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE;
48 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE;
50 private:
51 GpuWatchdogThread* watchdog_;
54 virtual ~GpuWatchdogThread();
56 void OnAcknowledge();
57 void OnCheck();
58 void DeliberatelyTerminateToRecoverFromHang();
60 #if defined(OS_WIN)
61 base::TimeDelta GetWatchedThreadTime();
62 #endif
64 MessageLoop* watched_message_loop_;
65 base::TimeDelta timeout_;
66 volatile bool armed_;
67 GpuWatchdogTaskObserver task_observer_;
69 #if defined(OS_WIN)
70 void* watched_thread_handle_;
71 base::TimeDelta arm_cpu_time_;
72 #endif
74 base::Time arm_absolute_time_;
76 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_;
78 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread);
81 } // namespace content
83 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_