1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ProcessHangMonitor_h
8 #define mozilla_ProcessHangMonitor_h
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/Atomics.h"
13 #include "nsIObserver.h"
14 #include "nsIRemoteTab.h"
15 #include "nsIThread.h"
16 #include "nsStringFwd.h"
19 class nsIBrowserChild
;
27 struct CancelContentJSOptions
;
30 class PProcessHangMonitorParent
;
32 class ProcessHangMonitor final
: public nsIObserver
{
35 virtual ~ProcessHangMonitor();
38 static ProcessHangMonitor
* Get() { return sInstance
; }
39 static ProcessHangMonitor
* GetOrCreate();
44 static already_AddRefed
<PProcessHangMonitorParent
> AddProcess(
45 dom::ContentParent
* aContentParent
);
46 static void RemoveProcess(PProcessHangMonitorParent
* aParent
);
48 static void ClearHang();
50 static void PaintWhileInterruptingJS(PProcessHangMonitorParent
* aParent
,
51 dom::BrowserParent
* aTab
);
53 static void UnloadLayersWhileInterruptingJS(
54 PProcessHangMonitorParent
* aParent
, dom::BrowserParent
* aTab
);
56 static void ClearPaintWhileInterruptingJS();
57 static void MaybeStartPaintWhileInterruptingJS();
59 static void CancelContentJSExecutionIfRunning(
60 PProcessHangMonitorParent
* aParent
, dom::BrowserParent
* aTab
,
61 nsIRemoteTab::NavigationType aNavigationType
,
62 const dom::CancelContentJSOptions
& aCancelContentJSOptions
);
64 static void SetMainThreadQoSPriority(PProcessHangMonitorParent
* aParent
,
65 nsIThread::QoSPriority aQoSPriority
);
67 enum SlowScriptAction
{
72 SlowScriptAction
NotifySlowScript(nsIBrowserChild
* aBrowserChild
,
73 const char* aFileName
,
74 const nsString
& aAddonId
,
75 const double aDuration
);
77 void NotifyPluginHang(uint32_t aPluginId
);
79 bool IsDebuggerStartupComplete();
81 void InitiateCPOWTimeout();
82 bool ShouldTimeOutCPOWs();
84 nsresult
Dispatch(already_AddRefed
<nsIRunnable
> aRunnable
);
88 static ProcessHangMonitor
* sInstance
;
90 Atomic
<bool> mCPOWTimeout
;
92 nsCOMPtr
<nsIThread
> mThread
;
95 } // namespace mozilla
97 #endif // mozilla_ProcessHangMonitor_h