ProcessHangMonitor.h (2780B)
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/. */ 6 7 #ifndef mozilla_ProcessHangMonitor_h 8 #define mozilla_ProcessHangMonitor_h 9 10 #include "mozilla/AlreadyAddRefed.h" 11 #include "mozilla/Atomics.h" 12 #include "nsCOMPtr.h" 13 #include "nsIObserver.h" 14 #include "nsIRemoteTab.h" 15 #include "nsIThread.h" 16 #include "nsStringFwd.h" 17 18 class nsIRunnable; 19 class nsIBrowserChild; 20 class nsIThread; 21 22 namespace mozilla { 23 24 namespace dom { 25 class ContentParent; 26 class BrowserParent; 27 struct CancelContentJSOptions; 28 } // namespace dom 29 30 class PProcessHangMonitorParent; 31 32 class ProcessHangMonitor final : public nsIObserver { 33 private: 34 ProcessHangMonitor(); 35 virtual ~ProcessHangMonitor(); 36 37 public: 38 static ProcessHangMonitor* Get() { return sInstance; } 39 static ProcessHangMonitor* GetOrCreate(); 40 41 NS_DECL_ISUPPORTS 42 NS_DECL_NSIOBSERVER 43 44 static already_AddRefed<PProcessHangMonitorParent> AddProcess( 45 dom::ContentParent* aContentParent); 46 static void RemoveProcess(PProcessHangMonitorParent* aParent); 47 48 static void ClearHang(); 49 50 static void PaintWhileInterruptingJS(PProcessHangMonitorParent* aParent, 51 dom::BrowserParent* aTab); 52 53 static void UnloadLayersWhileInterruptingJS( 54 PProcessHangMonitorParent* aParent, dom::BrowserParent* aTab); 55 56 static void ClearPaintWhileInterruptingJS(); 57 static void MaybeStartPaintWhileInterruptingJS(); 58 59 static void CancelContentJSExecutionIfRunning( 60 PProcessHangMonitorParent* aParent, dom::BrowserParent* aTab, 61 nsIRemoteTab::NavigationType aNavigationType, 62 const dom::CancelContentJSOptions& aCancelContentJSOptions); 63 64 static void SetMainThreadQoSPriority(PProcessHangMonitorParent* aParent, 65 nsIThread::QoSPriority aQoSPriority); 66 67 enum SlowScriptAction { 68 Continue, 69 Terminate, 70 StartDebugger, 71 }; 72 SlowScriptAction NotifySlowScript(nsIBrowserChild* aBrowserChild, 73 const char* aFileName, 74 const nsString& aAddonId, 75 const double aDuration); 76 77 void NotifyPluginHang(uint32_t aPluginId); 78 79 bool IsDebuggerStartupComplete(); 80 81 void InitiateCPOWTimeout(); 82 bool ShouldTimeOutCPOWs(); 83 84 nsresult Dispatch(already_AddRefed<nsIRunnable> aRunnable); 85 bool IsOnThread(); 86 87 private: 88 static ProcessHangMonitor* sInstance; 89 90 Atomic<bool> mCPOWTimeout; 91 92 nsCOMPtr<nsIThread> mThread; 93 }; 94 95 } // namespace mozilla 96 97 #endif // mozilla_ProcessHangMonitor_h