| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 | |
| 5 #ifndef CHROME_BROWSER_HANG_MONITOR_HUNG_WINDOW_DETECTOR_H__ | |
| 6 #define CHROME_BROWSER_HANG_MONITOR_HUNG_WINDOW_DETECTOR_H__ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/synchronization/lock.h" | |
| 10 #include "chrome/common/worker_thread_ticker.h" | |
| 11 | |
| 12 // This class provides the following functionality: | |
| 13 // Given a top-level window handle, it enumerates all descendant windows | |
| 14 // of that window and, on finding a window that belongs to a different | |
| 15 // thread from that of the top-level window, it tests to see if that window | |
| 16 // is responding to messages. It does this test by first calling the | |
| 17 // IsHungAppWindow API and, additionally (since the IsHungAppWindow API | |
| 18 // does not deal correctly with suspended threads), send a dummy message | |
| 19 // (WM_NULL) to the window and verifies that the call does not timeout. | |
| 20 // This class is typically used in conjunction with the WorkerThreadTicker | |
| 21 // class so that the checking can happen on a periodic basis. | |
| 22 // If a hung window is detected it calls back the specified implementation of | |
| 23 // the HungWindowNotification interface. Currently this class only supports | |
| 24 // a single callback but it can be extended later to support multiple | |
| 25 // callbacks. | |
| 26 class HungWindowDetector : public WorkerThreadTicker::Callback { | |
| 27 public: | |
| 28 // This property specifies the message timeout for a child window. | |
| 29 static const wchar_t kHungChildWindowTimeout[]; | |
| 30 // This is the notification callback interface that is used to notify | |
| 31 // callers about a non-responsive window | |
| 32 class HungWindowNotification { | |
| 33 public: | |
| 34 enum ActionOnHungWindow { | |
| 35 HUNG_WINDOW_IGNORE, | |
| 36 HUNG_WINDOW_TERMINATE_PROCESS, | |
| 37 }; | |
| 38 | |
| 39 // This callback method is invoked when a hung window is detected. | |
| 40 // A return value of false indicates that we should stop enumerating the | |
| 41 // child windows of the browser window to check if they are hung. | |
| 42 virtual bool OnHungWindowDetected(HWND hung_window, HWND top_level_window, | |
| 43 ActionOnHungWindow* action) = 0; | |
| 44 }; | |
| 45 | |
| 46 // The notification object is not owned by this class. It is assumed that | |
| 47 // this pointer will be valid throughout the lifetime of this class. | |
| 48 // Ownership of this pointer is not transferred to this class. | |
| 49 // Note that the Initialize method needs to be called to initiate monitoring | |
| 50 // of hung windows. | |
| 51 explicit HungWindowDetector(HungWindowNotification* notification); | |
| 52 ~HungWindowDetector() override; | |
| 53 | |
| 54 // This method initialized the monitoring of hung windows. All descendant | |
| 55 // windows of the passed-in top-level window which belong to a thread | |
| 56 // different from that of the top-level window are monitored. The | |
| 57 // message_response_timeout parameter indicates how long this class must | |
| 58 // wait for a window to respond to a sent message before it is considered | |
| 59 // to be non-responsive. | |
| 60 // Initialize can be called multiple times to change the actual window to | |
| 61 // be monitored as well as the message response timeout | |
| 62 bool Initialize(HWND top_level_window, | |
| 63 int message_response_timeout); | |
| 64 | |
| 65 // Implementation of the WorkerThreadTicker::Callback interface | |
| 66 void OnTick() override; | |
| 67 | |
| 68 private: | |
| 69 // Helper function that checks whether the specified child window is hung. | |
| 70 // If so, it invokes the HungWindowNotification interface implementation | |
| 71 bool CheckChildWindow(HWND child_window); | |
| 72 | |
| 73 static BOOL CALLBACK ChildWndEnumProc(HWND child_window, LPARAM param); | |
| 74 | |
| 75 // Pointer to the HungWindowNotification callback interface. This class does | |
| 76 // not RefCount this pointer and it is assumed that the pointer will be valid | |
| 77 // throughout the lifetime of this class. | |
| 78 HungWindowNotification* notification_; | |
| 79 HWND top_level_window_; | |
| 80 | |
| 81 // How long do we wait before we consider a window hung (in ms) | |
| 82 int message_response_timeout_; | |
| 83 base::Lock hang_detection_lock_; | |
| 84 // Indicates if this object is currently enumerating hung windows | |
| 85 bool enumerating_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(HungWindowDetector); | |
| 88 }; | |
| 89 | |
| 90 | |
| 91 #endif // CHROME_BROWSER_HANG_MONITOR_HUNG_WINDOW_DETECTOR_H__ | |
| OLD | NEW |