Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 #ifndef COMPONENTS_BROWSER_WATCHER_WINDOW_HANG_MONITOR_WIN_H_ | |
| 5 #define COMPONENTS_BROWSER_WATCHER_WINDOW_HANG_MONITOR_WIN_H_ | |
| 6 | |
| 7 #include <windows.h> | |
| 8 | |
| 9 #include "base/callback_forward.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/process/process.h" | |
| 12 #include "base/strings/string16.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 | |
| 16 namespace browser_watcher { | |
| 17 | |
| 18 // Monitors a window for hanging by periodically sending it a WM_NULL message | |
| 19 // and timing the response. | |
| 20 class WindowHangMonitor { | |
| 21 public: | |
| 22 enum WindowEvent { | |
| 23 WINDOW_HUNG, | |
| 24 WINDOW_VANISHED, | |
| 25 }; | |
| 26 // Called when a hang is detected or when the window has gone away. | |
| 27 // Called precisely zero or once. | |
|
erikwright (departed)
2015/03/25 18:57:22
zero or one time(s).
Sigurður Ásgeirsson
2015/03/25 19:56:53
Done.
| |
| 28 typedef base::Callback<void(WindowEvent)> WindowEventCallback; | |
| 29 | |
| 30 // Initialize the monitor with an event callback. | |
| 31 explicit WindowHangMonitor(const WindowEventCallback& callback); | |
| 32 ~WindowHangMonitor(); | |
| 33 | |
| 34 // Initializes the watcher to monitor the window answering to |window_name|. | |
| 35 // Returns true on success. | |
| 36 bool Initialize(const base::string16& window_name); | |
| 37 | |
| 38 // Testing accessors. | |
| 39 bool IsIdleForTesting() const { return !timer_.IsRunning(); } | |
| 40 void SetPingIntervalForTesting(base::TimeDelta ping_interval); | |
| 41 void SetHangTimeoutForTesting(base::TimeDelta hang_timeout); | |
| 42 | |
| 43 HWND window() const { return window_; } | |
| 44 const base::Process& window_process() const { return window_process_; } | |
| 45 | |
| 46 private: | |
| 47 static void CALLBACK | |
| 48 SendAsyncProc(HWND window, UINT msg, ULONG_PTR data, LRESULT lresult); | |
| 49 | |
| 50 // Checks that |window_| is still valid, and sends it a ping. | |
|
erikwright (departed)
2015/03/25 18:57:21
Comments for the other methods?
Sigurður Ásgeirsson
2015/03/25 19:56:53
Done.
| |
| 51 // Issues a |WINDOW_VANISHED| callback if the window's no longer valid. | |
| 52 // Schedules OnHangTimeout in case of success. | |
| 53 // Returns true on success, false if the window is no longer valid or other | |
| 54 // failure. | |
| 55 bool MaybeSendPing(); | |
| 56 void OnPongReceived(LRESULT lresult); | |
| 57 void OnHangTimeout(); | |
| 58 void OnRetryTimeout(); | |
| 59 | |
| 60 struct OutstandingPing { | |
| 61 WindowHangMonitor* monitor; | |
|
erikwright (departed)
2015/03/25 18:57:21
I believe the ordering rules would have this go ab
Sigurður Ásgeirsson
2015/03/25 19:56:53
Done.
| |
| 62 }; | |
| 63 | |
| 64 // Invoked on significant window events. | |
| 65 WindowEventCallback callback_; | |
| 66 | |
| 67 // The registry path where a hang event will be recorded. | |
|
erikwright (departed)
2015/03/25 18:57:21
comment invalid
Sigurður Ásgeirsson
2015/03/25 19:56:53
Done.
| |
| 68 base::string16 window_name_; | |
| 69 | |
| 70 // The monitored window handle. | |
| 71 HWND window_; | |
| 72 | |
| 73 // The process that owned |window_| when Initialize was called. | |
| 74 base::Process window_process_; | |
| 75 | |
| 76 // The time the last message was sent. | |
| 77 base::Time last_ping_; | |
| 78 | |
| 79 // The ping interval, must be larger than |hang_timeout_|. | |
| 80 base::TimeDelta ping_interval_; | |
| 81 // The time after which |window_| is assumed hung. | |
| 82 base::TimeDelta hang_timeout_; | |
| 83 | |
| 84 // The timer used to schedule polls. | |
| 85 base::Timer timer_; | |
| 86 | |
| 87 // Non-null when there is an outstanding ping. | |
| 88 // This is intentionally leaked when a hang is detected. | |
| 89 OutstandingPing* outstanding_ping_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(WindowHangMonitor); | |
| 92 }; | |
| 93 | |
| 94 } // namespace browser_watcher | |
| 95 | |
| 96 #endif // COMPONENTS_BROWSER_WATCHER_WINDOW_HANG_MONITOR_WIN_H_ | |
| OLD | NEW |