LCOV - code coverage report
Current view: top level - dom/workers - WorkerDebuggerManager.h (source / functions) Hit Total Coverage
Test: output.info Lines: 6 18 33.3 %
Date: 2017-07-14 16:53:18 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_dom_workers_workerdebuggermanager_h
       8             : #define mozilla_dom_workers_workerdebuggermanager_h
       9             : 
      10             : #include "Workers.h"
      11             : 
      12             : #include "nsIObserver.h"
      13             : #include "nsIWorkerDebuggerManager.h"
      14             : 
      15             : #include "nsServiceManagerUtils.h"
      16             : #include "nsTArray.h"
      17             : #include "nsThreadUtils.h"
      18             : 
      19             : #define WORKERDEBUGGERMANAGER_CID \
      20             :   { 0x62ec8731, 0x55ad, 0x4246, \
      21             :     { 0xb2, 0xea, 0xf2, 0x6c, 0x1f, 0xe1, 0x9d, 0x2d } }
      22             : #define WORKERDEBUGGERMANAGER_CONTRACTID \
      23             :   "@mozilla.org/dom/workers/workerdebuggermanager;1"
      24             : 
      25             : BEGIN_WORKERS_NAMESPACE
      26             : 
      27             : class WorkerDebugger;
      28             : 
      29             : class WorkerDebuggerManager final : public nsIObserver,
      30             :                                     public nsIWorkerDebuggerManager
      31             : {
      32             :   Mutex mMutex;
      33             : 
      34             :   // Protected by mMutex.
      35             :   nsTArray<nsCOMPtr<nsIWorkerDebuggerManagerListener>> mListeners;
      36             : 
      37             :   // Only touched on the main thread.
      38             :   nsTArray<RefPtr<WorkerDebugger>> mDebuggers;
      39             : 
      40             : public:
      41             :   static already_AddRefed<WorkerDebuggerManager>
      42             :   GetInstance();
      43             : 
      44             :   static WorkerDebuggerManager*
      45             :   GetOrCreate();
      46             : 
      47             :   static WorkerDebuggerManager*
      48             :   Get();
      49             : 
      50             :   WorkerDebuggerManager();
      51             : 
      52             :   NS_DECL_ISUPPORTS
      53             :   NS_DECL_NSIOBSERVER
      54             :   NS_DECL_NSIWORKERDEBUGGERMANAGER
      55             : 
      56             :   nsresult
      57             :   Init();
      58             : 
      59             :   void
      60             :   Shutdown();
      61             : 
      62             :   void
      63             :   RegisterDebugger(WorkerPrivate* aWorkerPrivate);
      64             : 
      65             :   void
      66             :   RegisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate,
      67             :                              bool aNotifyListeners);
      68             : 
      69             :   void
      70             :   UnregisterDebugger(WorkerPrivate* aWorkerPrivate);
      71             : 
      72             :   void
      73             :   UnregisterDebuggerMainThread(WorkerPrivate* aWorkerPrivate);
      74             : 
      75             : private:
      76             :   virtual ~WorkerDebuggerManager();
      77             : };
      78             : 
      79             : inline nsresult
      80           1 : RegisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
      81             : {
      82             :   WorkerDebuggerManager* manager;
      83             : 
      84           1 :   if (NS_IsMainThread()) {
      85           1 :     manager = WorkerDebuggerManager::GetOrCreate();
      86           1 :     if (!manager) {
      87           0 :       NS_WARNING("Failed to create worker debugger manager!");
      88           0 :       return NS_ERROR_FAILURE;
      89             :     }
      90             :   }
      91             :   else {
      92           0 :     manager = WorkerDebuggerManager::Get();
      93             :   }
      94             : 
      95           1 :   manager->RegisterDebugger(aWorkerPrivate);
      96           1 :   return NS_OK;
      97             : }
      98             : 
      99             : inline nsresult
     100           0 : UnregisterWorkerDebugger(WorkerPrivate* aWorkerPrivate)
     101             : {
     102             :   WorkerDebuggerManager* manager;
     103             : 
     104           0 :   if (NS_IsMainThread()) {
     105           0 :     manager = WorkerDebuggerManager::GetOrCreate();
     106           0 :     if (!manager) {
     107           0 :       NS_WARNING("Failed to create worker debugger manager!");
     108           0 :       return NS_ERROR_FAILURE;
     109             :     }
     110             :   }
     111             :   else {
     112           0 :     manager = WorkerDebuggerManager::Get();
     113             :   }
     114             : 
     115           0 :   manager->UnregisterDebugger(aWorkerPrivate);
     116           0 :   return NS_OK;
     117             : }
     118             : 
     119             : END_WORKERS_NAMESPACE
     120             : 
     121             : #endif // mozilla_dom_workers_workerdebuggermanager_h

Generated by: LCOV version 1.13