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

Unified Diff: components/browser_watcher/window_hang_monitor_win.h

Issue 1036623002: Implements a monitor to watch for the browser hanging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finish testing, simplify callback. Created 5 years, 9 months 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.h
diff --git a/components/browser_watcher/window_hang_monitor_win.h b/components/browser_watcher/window_hang_monitor_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..3d1c7bce46d053e3521f94c80744b4c65fa0a81c
--- /dev/null
+++ b/components/browser_watcher/window_hang_monitor_win.h
@@ -0,0 +1,96 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#ifndef COMPONENTS_BROWSER_WATCHER_WINDOW_HANG_MONITOR_WIN_H_
+#define COMPONENTS_BROWSER_WATCHER_WINDOW_HANG_MONITOR_WIN_H_
+
+#include <windows.h>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/process/process.h"
+#include "base/strings/string16.h"
+#include "base/time/time.h"
+#include "base/timer/timer.h"
+
+namespace browser_watcher {
+
+// Monitors a window for hanging by periodically sending it a WM_NULL message
+// and timing the response.
+class WindowHangMonitor {
+ public:
+ enum WindowEvent {
+ WINDOW_HUNG,
+ WINDOW_VANISHED,
+ };
+ // Called when a hang is detected or when the window has gone away.
+ // 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.
+ typedef base::Callback<void(WindowEvent)> WindowEventCallback;
+
+ // Initialize the monitor with an event callback.
+ explicit WindowHangMonitor(const WindowEventCallback& callback);
+ ~WindowHangMonitor();
+
+ // Initializes the watcher to monitor the window answering to |window_name|.
+ // Returns true on success.
+ bool Initialize(const base::string16& window_name);
+
+ // Testing accessors.
+ bool IsIdleForTesting() const { return !timer_.IsRunning(); }
+ void SetPingIntervalForTesting(base::TimeDelta ping_interval);
+ void SetHangTimeoutForTesting(base::TimeDelta hang_timeout);
+
+ HWND window() const { return window_; }
+ const base::Process& window_process() const { return window_process_; }
+
+ private:
+ static void CALLBACK
+ SendAsyncProc(HWND window, UINT msg, ULONG_PTR data, LRESULT lresult);
+
+ // 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.
+ // Issues a |WINDOW_VANISHED| callback if the window's no longer valid.
+ // Schedules OnHangTimeout in case of success.
+ // Returns true on success, false if the window is no longer valid or other
+ // failure.
+ bool MaybeSendPing();
+ void OnPongReceived(LRESULT lresult);
+ void OnHangTimeout();
+ void OnRetryTimeout();
+
+ struct OutstandingPing {
+ 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.
+ };
+
+ // Invoked on significant window events.
+ WindowEventCallback callback_;
+
+ // 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.
+ base::string16 window_name_;
+
+ // The monitored window handle.
+ HWND window_;
+
+ // The process that owned |window_| when Initialize was called.
+ base::Process window_process_;
+
+ // The time the last message was sent.
+ base::Time last_ping_;
+
+ // The ping interval, must be larger than |hang_timeout_|.
+ base::TimeDelta ping_interval_;
+ // The time after which |window_| is assumed hung.
+ base::TimeDelta hang_timeout_;
+
+ // The timer used to schedule polls.
+ base::Timer timer_;
+
+ // Non-null when there is an outstanding ping.
+ // This is intentionally leaked when a hang is detected.
+ OutstandingPing* outstanding_ping_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowHangMonitor);
+};
+
+} // namespace browser_watcher
+
+#endif // COMPONENTS_BROWSER_WATCHER_WINDOW_HANG_MONITOR_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698