OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "components/browser_watcher/window_hang_monitor_win.h" | 5 #include "components/browser_watcher/window_hang_monitor_win.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
8 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
13 #include "base/process/process.h" | 14 #include "base/process/process.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
16 #include "base/test/multiprocess_test.h" | 17 #include "base/test/multiprocess_test.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "base/win/message_window.h" | 19 #include "base/win/message_window.h" |
19 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
20 #include "base/win/win_util.h" | 21 #include "base/win/win_util.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 203 } |
203 | 204 |
204 void DeleteMessageWindowInWorkerThread(base::WaitableEvent* deleted) { | 205 void DeleteMessageWindowInWorkerThread(base::WaitableEvent* deleted) { |
205 CHECK(deleted); | 206 CHECK(deleted); |
206 message_window_.reset(); | 207 message_window_.reset(); |
207 deleted->Signal(); | 208 deleted->Signal(); |
208 } | 209 } |
209 | 210 |
210 // The thread that holds the message window. | 211 // The thread that holds the message window. |
211 base::Thread message_window_thread_; | 212 base::Thread message_window_thread_; |
212 scoped_ptr<base::win::MessageWindow> message_window_; | 213 std::unique_ptr<base::win::MessageWindow> message_window_; |
213 | 214 |
214 // Event used to hang the message window. | 215 // Event used to hang the message window. |
215 base::WaitableEvent hang_event_; | 216 base::WaitableEvent hang_event_; |
216 | 217 |
217 // Anonymous pipe handles for IPC with the parent process. | 218 // Anonymous pipe handles for IPC with the parent process. |
218 base::win::ScopedHandle read_pipe_; | 219 base::win::ScopedHandle read_pipe_; |
219 base::win::ScopedHandle write_pipe_; | 220 base::win::ScopedHandle write_pipe_; |
220 | 221 |
221 DISALLOW_COPY_AND_ASSIGN(MonitoredProcessClient); | 222 DISALLOW_COPY_AND_ASSIGN(MonitoredProcessClient); |
222 }; | 223 }; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 // Destroys the WindowHangMonitor. | 313 // Destroys the WindowHangMonitor. |
313 void ShutdownOnThread() { hang_monitor_.reset(); } | 314 void ShutdownOnThread() { hang_monitor_.reset(); } |
314 | 315 |
315 // The detected event. Invalid if |event_received_| has not been signaled. | 316 // The detected event. Invalid if |event_received_| has not been signaled. |
316 WindowHangMonitor::WindowEvent event_; | 317 WindowHangMonitor::WindowEvent event_; |
317 // Indicates that |event_| has been assigned in response to a callback from | 318 // Indicates that |event_| has been assigned in response to a callback from |
318 // the WindowHangMonitor. | 319 // the WindowHangMonitor. |
319 base::WaitableEvent event_received_; | 320 base::WaitableEvent event_received_; |
320 // The WindowHangMonitor under test. | 321 // The WindowHangMonitor under test. |
321 scoped_ptr<WindowHangMonitor> hang_monitor_; | 322 std::unique_ptr<WindowHangMonitor> hang_monitor_; |
322 // The background thread. | 323 // The background thread. |
323 base::Thread thread_; | 324 base::Thread thread_; |
324 | 325 |
325 DISALLOW_COPY_AND_ASSIGN(HangMonitorThread); | 326 DISALLOW_COPY_AND_ASSIGN(HangMonitorThread); |
326 }; | 327 }; |
327 | 328 |
328 class WindowHangMonitorTest : public testing::Test { | 329 class WindowHangMonitorTest : public testing::Test { |
329 public: | 330 public: |
330 WindowHangMonitorTest() {} | 331 WindowHangMonitorTest() {} |
331 | 332 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 460 |
460 ASSERT_TRUE(SendSignal(IPC_SIGNAL_HANG_MESSAGE_WINDOW)); | 461 ASSERT_TRUE(SendSignal(IPC_SIGNAL_HANG_MESSAGE_WINDOW)); |
461 | 462 |
462 EXPECT_EQ(WindowHangMonitor::WINDOW_HUNG, | 463 EXPECT_EQ(WindowHangMonitor::WINDOW_HUNG, |
463 monitor_thread().WaitForEvent()); | 464 monitor_thread().WaitForEvent()); |
464 | 465 |
465 ASSERT_TRUE(SendSignal(IPC_SIGNAL_TERMINATE_PROCESS)); | 466 ASSERT_TRUE(SendSignal(IPC_SIGNAL_TERMINATE_PROCESS)); |
466 } | 467 } |
467 | 468 |
468 } // namespace browser_watcher | 469 } // namespace browser_watcher |
OLD | NEW |