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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "content/gpu/gpu_watchdog_thread.h" | 9 #include "content/gpu/gpu_watchdog_thread.h" |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/power_monitor/power_monitor.h" | 16 #include "base/power_monitor/power_monitor.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 #include "content/public/common/result_codes.h" | 20 #include "content/public/common/result_codes.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 namespace { | 23 namespace { |
24 const int64 kCheckPeriodMs = 2000; | |
25 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
26 const base::FilePath::CharType | 25 const base::FilePath::CharType |
27 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active"); | 26 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active"); |
28 #endif | 27 #endif |
29 #if defined(USE_X11) | 28 #if defined(USE_X11) |
30 const unsigned char text[20] = "check"; | 29 const unsigned char text[20] = "check"; |
31 #endif | 30 #endif |
32 } // namespace | 31 } // namespace |
33 | 32 |
34 GpuWatchdogThread::GpuWatchdogThread(int timeout) | 33 GpuWatchdogThread::GpuWatchdogThread(int timeout) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 GpuWatchdogThread::GpuWatchdogTaskObserver::~GpuWatchdogTaskObserver() { | 105 GpuWatchdogThread::GpuWatchdogTaskObserver::~GpuWatchdogTaskObserver() { |
107 } | 106 } |
108 | 107 |
109 void GpuWatchdogThread::GpuWatchdogTaskObserver::WillProcessTask( | 108 void GpuWatchdogThread::GpuWatchdogTaskObserver::WillProcessTask( |
110 const base::PendingTask& pending_task) { | 109 const base::PendingTask& pending_task) { |
111 watchdog_->CheckArmed(); | 110 watchdog_->CheckArmed(); |
112 } | 111 } |
113 | 112 |
114 void GpuWatchdogThread::GpuWatchdogTaskObserver::DidProcessTask( | 113 void GpuWatchdogThread::GpuWatchdogTaskObserver::DidProcessTask( |
115 const base::PendingTask& pending_task) { | 114 const base::PendingTask& pending_task) { |
116 watchdog_->CheckArmed(); | |
117 } | 115 } |
118 | 116 |
119 GpuWatchdogThread::~GpuWatchdogThread() { | 117 GpuWatchdogThread::~GpuWatchdogThread() { |
120 // Verify that the thread was explicitly stopped. If the thread is stopped | 118 // Verify that the thread was explicitly stopped. If the thread is stopped |
121 // implicitly by the destructor, CleanUp() will not be called. | 119 // implicitly by the destructor, CleanUp() will not be called. |
122 DCHECK(!weak_factory_.HasWeakPtrs()); | 120 DCHECK(!weak_factory_.HasWeakPtrs()); |
123 | 121 |
124 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
125 CloseHandle(watched_thread_handle_); | 123 CloseHandle(watched_thread_handle_); |
126 #endif | 124 #endif |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 159 |
162 // If it took a long time for the acknowledgement, assume the computer was | 160 // If it took a long time for the acknowledgement, assume the computer was |
163 // recently suspended. | 161 // recently suspended. |
164 bool was_suspended = (base::Time::Now() > suspension_timeout_); | 162 bool was_suspended = (base::Time::Now() > suspension_timeout_); |
165 | 163 |
166 // The monitored thread has responded. Post a task to check it again. | 164 // The monitored thread has responded. Post a task to check it again. |
167 message_loop()->PostDelayedTask( | 165 message_loop()->PostDelayedTask( |
168 FROM_HERE, | 166 FROM_HERE, |
169 base::Bind(&GpuWatchdogThread::OnCheck, weak_factory_.GetWeakPtr(), | 167 base::Bind(&GpuWatchdogThread::OnCheck, weak_factory_.GetWeakPtr(), |
170 was_suspended), | 168 was_suspended), |
171 base::TimeDelta::FromMilliseconds(kCheckPeriodMs)); | 169 0.5 * timeout_); |
172 } | 170 } |
173 | 171 |
174 void GpuWatchdogThread::OnCheck(bool after_suspend) { | 172 void GpuWatchdogThread::OnCheck(bool after_suspend) { |
175 CHECK(base::PlatformThread::CurrentId() == thread_id()); | 173 CHECK(base::PlatformThread::CurrentId() == thread_id()); |
176 | 174 |
177 // Do not create any new termination tasks if one has already been created | 175 // Do not create any new termination tasks if one has already been created |
178 // or the system is suspended. | 176 // or the system is suspended. |
179 if (armed_ || suspended_) | 177 if (armed_ || suspended_) |
180 return; | 178 return; |
181 | 179 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // not increasing. The other is where either the kernel hangs and never | 395 // not increasing. The other is where either the kernel hangs and never |
398 // returns to user level or where user level code | 396 // returns to user level or where user level code |
399 // calls into kernel level repeatedly, giving up its quanta before it is | 397 // calls into kernel level repeatedly, giving up its quanta before it is |
400 // tracked, for example a loop that repeatedly Sleeps. | 398 // tracked, for example a loop that repeatedly Sleeps. |
401 return base::TimeDelta::FromMilliseconds(static_cast<int64>( | 399 return base::TimeDelta::FromMilliseconds(static_cast<int64>( |
402 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); | 400 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); |
403 } | 401 } |
404 #endif | 402 #endif |
405 | 403 |
406 } // namespace content | 404 } // namespace content |
OLD | NEW |