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

Unified Diff: components/browser_watcher/window_hang_monitor_win.cc

Issue 1543803005: Added an integration test for kasko hang reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: components/browser_watcher/window_hang_monitor_win.cc
diff --git a/components/browser_watcher/window_hang_monitor_win.cc b/components/browser_watcher/window_hang_monitor_win.cc
index 964a6f76f4620a56aa2d2d4a557d1bec65b63ec5..c5a60b05c31dc8220508251efa80f2786712f8d7 100644
--- a/components/browser_watcher/window_hang_monitor_win.cc
+++ b/components/browser_watcher/window_hang_monitor_win.cc
@@ -13,13 +13,29 @@ namespace browser_watcher {
namespace {
-HWND FindNamedWindowForProcess(const base::string16 name, base::ProcessId pid) {
- HWND candidate = base::win::MessageWindow::FindWindow(name);
- if (candidate) {
+// Returns the class name for the |window|.
+base::string16 GetWindowClassName(HWND window) {
+ const int kClassNameLength = MAX_PATH;
+ wchar_t class_name[kClassNameLength];
+ int nb_copied = ::GetClassName(window, class_name, kClassNameLength);
+ if (nb_copied) {
+ return base::string16(class_name);
+ }
+ return base::string16();
+}
+
+// Returns the Chrome message window handle for the specified |pid| or nullptr
+// if not found.
+HWND FindChromeMessageWindow(base::ProcessId pid) {
+ HWND candidate = ::FindWindowEx(HWND_MESSAGE, nullptr, nullptr, nullptr);
+ while (candidate) {
DWORD actual_process_id = 0;
::GetWindowThreadProcessId(candidate, &actual_process_id);
- if (actual_process_id == pid)
+ if (GetWindowClassName(candidate) == L"Chrome_MessageWindow" &&
+ actual_process_id == pid) {
return candidate;
+ }
+ candidate = ::GetNextWindow(candidate, GW_HWNDNEXT);
}
return nullptr;
}
@@ -45,9 +61,7 @@ WindowHangMonitor::~WindowHangMonitor() {
}
}
-void WindowHangMonitor::Initialize(base::Process process,
- const base::string16& window_name) {
- window_name_ = window_name;
+void WindowHangMonitor::Initialize(base::Process process) {
window_process_ = process.Pass();
timer_.SetTaskRunner(base::MessageLoop::current()->task_runner());
@@ -69,7 +83,7 @@ void WindowHangMonitor::PollForWindow() {
return;
}
- HWND hwnd = FindNamedWindowForProcess(window_name_, window_process_.Pid());
+ HWND hwnd = FindChromeMessageWindow(window_process_.Pid());
if (hwnd) {
// Sends a ping and schedules a timeout task. Upon receiving a ping response
// further pings will be scheduled ad infinitum. Will signal any failure now
@@ -129,8 +143,7 @@ void WindowHangMonitor::OnHangTimeout(HWND hwnd) {
outstanding_ping_->monitor = NULL;
outstanding_ping_ = NULL;
- if (hwnd !=
- FindNamedWindowForProcess(window_name_, window_process_.Pid())) {
+ if (hwnd != FindChromeMessageWindow(window_process_.Pid())) {
// The window vanished.
callback_.Run(WINDOW_VANISHED);
} else {
@@ -155,7 +168,7 @@ void WindowHangMonitor::OnRetryTimeout() {
// process.
// 2. The window handle might have been re-assigned to a different process
// at any point after we found it.
- HWND hwnd = FindNamedWindowForProcess(window_name_, window_process_.Pid());
+ HWND hwnd = FindChromeMessageWindow(window_process_.Pid());
if (hwnd)
SendPing(hwnd);
else

Powered by Google App Engine
This is Rietveld 408576698