LCOV - code coverage report
Current view: top level - xpcom/base - nsConsoleService.h (source / functions) Hit Total Coverage
Test: output.info Lines: 4 17 23.5 %
Date: 2017-07-14 16:53:18 Functions: 2 5 40.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             : /*
       8             :  * nsConsoleService class declaration.
       9             :  */
      10             : 
      11             : #ifndef __nsconsoleservice_h__
      12             : #define __nsconsoleservice_h__
      13             : 
      14             : #include "mozilla/Attributes.h"
      15             : #include "mozilla/Mutex.h"
      16             : 
      17             : #include "nsInterfaceHashtable.h"
      18             : #include "nsHashKeys.h"
      19             : 
      20             : #include "nsIConsoleService.h"
      21             : #include "nsIObserver.h"
      22             : 
      23             : class nsConsoleService final : public nsIConsoleService,
      24             :                                public nsIObserver
      25             : {
      26             : public:
      27             :   nsConsoleService();
      28             :   nsresult Init();
      29             : 
      30             :   NS_DECL_THREADSAFE_ISUPPORTS
      31             :   NS_DECL_NSICONSOLESERVICE
      32             :   NS_DECL_NSIOBSERVER
      33             : 
      34           0 :   void SetIsDelivering()
      35             :   {
      36           0 :     MOZ_ASSERT(NS_IsMainThread());
      37           0 :     MOZ_ASSERT(!mDeliveringMessage);
      38           0 :     mDeliveringMessage = true;
      39           0 :   }
      40             : 
      41           0 :   void SetDoneDelivering()
      42             :   {
      43           0 :     MOZ_ASSERT(NS_IsMainThread());
      44           0 :     MOZ_ASSERT(mDeliveringMessage);
      45           0 :     mDeliveringMessage = false;
      46           0 :   }
      47             : 
      48             :   // This is a variant of LogMessage which allows the caller to determine
      49             :   // if the message should be output to an OS-specific log. This is used on
      50             :   // B2G to control whether the message is logged to the android log or not.
      51             : 
      52             :   enum OutputMode {
      53             :     SuppressLog,
      54             :     OutputToLog
      55             :   };
      56             :   virtual nsresult LogMessageWithMode(nsIConsoleMessage* aMessage,
      57             :                                       OutputMode aOutputMode);
      58             : 
      59             :   typedef nsInterfaceHashtable<nsISupportsHashKey,
      60             :                                nsIConsoleListener> ListenerHash;
      61             :   void CollectCurrentListeners(nsCOMArray<nsIConsoleListener>& aListeners);
      62             : 
      63             : private:
      64             :   class MessageElement : public mozilla::LinkedListElement<MessageElement>
      65             :   {
      66             :   public:
      67           3 :     explicit MessageElement(nsIConsoleMessage* aMessage) : mMessage(aMessage)
      68           3 :     {}
      69             : 
      70           3 :     nsIConsoleMessage* Get()
      71             :     {
      72           3 :       return mMessage.get();
      73             :     }
      74             : 
      75             :     // Swap directly into an nsCOMPtr to avoid spurious refcount
      76             :     // traffic off the main thread in debug builds from
      77             :     // NSCAP_ASSERT_NO_QUERY_NEEDED().
      78           0 :     void swapMessage(nsCOMPtr<nsIConsoleMessage>& aRetVal)
      79             :     {
      80           0 :       mMessage.swap(aRetVal);
      81           0 :     }
      82             : 
      83             :     ~MessageElement();
      84             : 
      85             :   private:
      86             :     nsCOMPtr<nsIConsoleMessage> mMessage;
      87             : 
      88             :     MessageElement(const MessageElement&) = delete;
      89             :     MessageElement& operator=(const MessageElement&) = delete;
      90             :     MessageElement(MessageElement&&) = delete;
      91             :     MessageElement& operator=(MessageElement&&) = delete;
      92             :   };
      93             : 
      94             :   ~nsConsoleService();
      95             : 
      96             :   void ClearMessagesForWindowID(const uint64_t innerID);
      97             :   void ClearMessages();
      98             : 
      99             :   mozilla::LinkedList<MessageElement> mMessages;
     100             : 
     101             :   // The current size of mMessages.
     102             :   uint32_t mCurrentSize;
     103             : 
     104             :   // The maximum size of mMessages.
     105             :   uint32_t mMaximumSize;
     106             : 
     107             :   // Are we currently delivering a console message on the main thread? If
     108             :   // so, we suppress incoming messages on the main thread only, to avoid
     109             :   // infinite repitition.
     110             :   bool mDeliveringMessage;
     111             : 
     112             :   // Listeners to notify whenever a new message is logged.
     113             :   ListenerHash mListeners;
     114             : 
     115             :   // To serialize interesting methods.
     116             :   mozilla::Mutex mLock;
     117             : };
     118             : 
     119             : #endif /* __nsconsoleservice_h__ */

Generated by: LCOV version 1.13