Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: content/gpu/gpu_watchdog_thread.h

Issue 22289002: Added suspend/resume detection to the GpuWatchdogThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Derp. Null references are bad. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/gpu/gpu_main.cc ('k') | content/gpu/gpu_watchdog_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/power_monitor/power_observer.h"
11 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "content/common/gpu/gpu_watchdog.h" 14 #include "content/common/gpu/gpu_watchdog.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 // A thread that intermitently sends tasks to a group of watched message loops 18 // 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 // and deliberately crashes if one of them does not respond after a timeout.
19 class GpuWatchdogThread : public base::Thread, 20 class GpuWatchdogThread : public base::Thread,
20 public GpuWatchdog, 21 public GpuWatchdog,
22 public base::PowerObserver,
21 public base::RefCountedThreadSafe<GpuWatchdogThread> { 23 public base::RefCountedThreadSafe<GpuWatchdogThread> {
22 public: 24 public:
23 explicit GpuWatchdogThread(int timeout); 25 explicit GpuWatchdogThread(int timeout);
24 26
25 // Accessible on watched thread but only modified by watchdog thread. 27 // Accessible on watched thread but only modified by watchdog thread.
26 bool armed() const { return armed_; } 28 bool armed() const { return armed_; }
27 void PostAcknowledge(); 29 void PostAcknowledge();
28 30
29 // Implement GpuWatchdog. 31 // Implement GpuWatchdog.
30 virtual void CheckArmed() OVERRIDE; 32 virtual void CheckArmed() OVERRIDE;
31 33
34 // Must be called after a PowerMonitor has been created. Can be called from
35 // any thread.
36 void AddPowerObserver();
37
32 protected: 38 protected:
33 virtual void Init() OVERRIDE; 39 virtual void Init() OVERRIDE;
34 virtual void CleanUp() OVERRIDE; 40 virtual void CleanUp() OVERRIDE;
35 41
36 private: 42 private:
37 friend class base::RefCountedThreadSafe<GpuWatchdogThread>; 43 friend class base::RefCountedThreadSafe<GpuWatchdogThread>;
38 44
39 // 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
40 // on the watched thread and checks whether the watchdog is armed. 46 // on the watched thread and checks whether the watchdog is armed.
41 class GpuWatchdogTaskObserver : public base::MessageLoop::TaskObserver { 47 class GpuWatchdogTaskObserver : public base::MessageLoop::TaskObserver {
42 public: 48 public:
43 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog); 49 explicit GpuWatchdogTaskObserver(GpuWatchdogThread* watchdog);
44 virtual ~GpuWatchdogTaskObserver(); 50 virtual ~GpuWatchdogTaskObserver();
45 51
46 // Implements MessageLoop::TaskObserver. 52 // Implements MessageLoop::TaskObserver.
47 virtual void WillProcessTask( 53 virtual void WillProcessTask(
48 const base::PendingTask& pending_task) OVERRIDE; 54 const base::PendingTask& pending_task) OVERRIDE;
49 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE; 55 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE;
50 56
51 private: 57 private:
52 GpuWatchdogThread* watchdog_; 58 GpuWatchdogThread* watchdog_;
53 }; 59 };
54 60
55 virtual ~GpuWatchdogThread(); 61 virtual ~GpuWatchdogThread();
56 62
57 void OnAcknowledge(); 63 void OnAcknowledge();
58 void OnCheck(bool after_suspend); 64 void OnCheck(bool after_suspend);
59 void DeliberatelyTerminateToRecoverFromHang(); 65 void DeliberatelyTerminateToRecoverFromHang();
60 66
67 void OnAddPowerObserver();
68
69 // Implement PowerObserver.
70 virtual void OnSuspend() OVERRIDE;
71 virtual void OnResume() OVERRIDE;
72
61 #if defined(OS_WIN) 73 #if defined(OS_WIN)
62 base::TimeDelta GetWatchedThreadTime(); 74 base::TimeDelta GetWatchedThreadTime();
63 #endif 75 #endif
64 76
65 base::MessageLoop* watched_message_loop_; 77 base::MessageLoop* watched_message_loop_;
66 base::TimeDelta timeout_; 78 base::TimeDelta timeout_;
67 volatile bool armed_; 79 volatile bool armed_;
68 GpuWatchdogTaskObserver task_observer_; 80 GpuWatchdogTaskObserver task_observer_;
69 81
70 #if defined(OS_WIN) 82 #if defined(OS_WIN)
71 void* watched_thread_handle_; 83 void* watched_thread_handle_;
72 base::TimeDelta arm_cpu_time_; 84 base::TimeDelta arm_cpu_time_;
73 #endif 85 #endif
74 86
75 // Time after which it's assumed that the computer has been suspended since 87 // Time after which it's assumed that the computer has been suspended since
76 // the task was posted. 88 // the task was posted.
77 base::Time suspension_timeout_; 89 base::Time suspension_timeout_;
78 90
79 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_; 91 base::WeakPtrFactory<GpuWatchdogThread> weak_factory_;
80 92
93 bool suspended_;
94
81 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread); 95 DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread);
82 }; 96 };
83 97
84 } // namespace content 98 } // namespace content
85 99
86 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_ 100 #endif // CONTENT_GPU_GPU_WATCHDOG_THREAD_H_
OLDNEW
« no previous file with comments | « content/gpu/gpu_main.cc ('k') | content/gpu/gpu_watchdog_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698