| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "content/common/gpu/gpu_watchdog.h" | 14 #include "content/common/gpu/gpu_watchdog.h" |
| 15 | 15 |
| 16 // A thread that intermitently sends tasks to a group of watched message loops | 16 // A thread that intermitently sends tasks to a group of watched message loops |
| 17 // and deliberately crashes if one of them does not respond after a timeout. | 17 // and deliberately crashes if one of them does not respond after a timeout. |
| 18 class GpuWatchdogThread : public base::Thread, | 18 class GpuWatchdogThread : public base::Thread, |
| 19 public GpuWatchdog, | 19 public GpuWatchdog, |
| 20 public base::RefCountedThreadSafe<GpuWatchdogThread> { | 20 public base::RefCountedThreadSafe<GpuWatchdogThread> { |
| 21 public: | 21 public: |
| 22 explicit GpuWatchdogThread(int timeout); | 22 explicit GpuWatchdogThread(int timeout); |
| 23 virtual ~GpuWatchdogThread(); | 23 virtual ~GpuWatchdogThread(); |
| 24 | 24 |
| 25 // Accessible on watched thread but only modified by watchdog thread. | 25 // Accessible on watched thread but only modified by watchdog thread. |
| 26 bool armed() const { return armed_; } | 26 bool armed() const { return armed_; } |
| 27 void PostAcknowledge(); | 27 void PostAcknowledge(); |
| 28 | 28 |
| 29 // Implement GpuWatchdog. | 29 // Implement GpuWatchdog. |
| 30 virtual void CheckArmed(); | 30 virtual void CheckArmed() OVERRIDE; |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 virtual void Init(); | 33 virtual void Init() OVERRIDE; |
| 34 virtual void CleanUp(); | 34 virtual void CleanUp() OVERRIDE; |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 | 37 |
| 38 // An object of this type intercepts the reception and completion of all tasks | 38 // An object of this type intercepts the reception and completion of all tasks |
| 39 // on the watched thread and checks whether the watchdog is armed. | 39 // on the watched thread and checks whether the watchdog is armed. |
| 40 class GpuWatchdogTaskObserver : public MessageLoop::TaskObserver { | 40 class GpuWatchdogTaskObserver : public MessageLoop::TaskObserver { |
| 41 public: | 41 public: |
| 42 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); | 42 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); |
| 43 virtual ~GpuWatchdogTaskObserver(); | 43 virtual ~GpuWatchdogTaskObserver(); |
| 44 | 44 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 69 | 69 |
| 70 base::Time arm_absolute_time_; | 70 base::Time arm_absolute_time_; |
| 71 | 71 |
| 72 typedef ScopedRunnableMethodFactory<GpuWatchdogThread> MethodFactory; | 72 typedef ScopedRunnableMethodFactory<GpuWatchdogThread> MethodFactory; |
| 73 scoped_ptr<MethodFactory> method_factory_; | 73 scoped_ptr<MethodFactory> method_factory_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); | 75 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ | 78 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ |
| OLD | NEW |