2014-05-05 21:30:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-04-18 06:34:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsConsoleService class declaration.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __nsconsoleservice_h__
|
|
|
|
#define __nsconsoleservice_h__
|
|
|
|
|
2020-11-23 19:12:02 +03:00
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/LinkedList.h"
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2011-12-18 07:47:45 +04:00
|
|
|
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-01-11 20:28:21 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "nsIConsoleListener.h"
|
|
|
|
#include "nsIConsoleMessage.h"
|
2000-04-18 06:34:54 +04:00
|
|
|
#include "nsIConsoleService.h"
|
2017-01-23 17:24:01 +03:00
|
|
|
#include "nsIObserver.h"
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "nsISupports.h"
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class nsCOMArray;
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2015-07-31 16:49:27 +03:00
|
|
|
class nsConsoleService final : public nsIConsoleService, public nsIObserver {
|
2000-04-18 06:34:54 +04:00
|
|
|
public:
|
2014-05-05 21:30:39 +04:00
|
|
|
nsConsoleService();
|
|
|
|
nsresult Init();
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSICONSOLESERVICE
|
2015-07-31 16:49:27 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void SetIsDelivering() {
|
2014-05-05 21:30:39 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mDeliveringMessage);
|
|
|
|
mDeliveringMessage = true;
|
|
|
|
}
|
2012-01-11 20:28:21 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
void SetDoneDelivering() {
|
2014-05-05 21:30:39 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mDeliveringMessage);
|
|
|
|
mDeliveringMessage = false;
|
|
|
|
}
|
2012-01-11 20:28:21 +04:00
|
|
|
|
2014-08-25 23:17:24 +04:00
|
|
|
typedef nsInterfaceHashtable<nsISupportsHashKey, nsIConsoleListener>
|
|
|
|
ListenerHash;
|
2015-07-10 02:54:59 +03:00
|
|
|
void CollectCurrentListeners(nsCOMArray<nsIConsoleListener>& aListeners);
|
2013-01-29 20:02:56 +04:00
|
|
|
|
2000-04-18 06:34:54 +04:00
|
|
|
private:
|
2015-08-18 04:05:48 +03:00
|
|
|
class MessageElement : public mozilla::LinkedListElement<MessageElement> {
|
|
|
|
public:
|
|
|
|
explicit MessageElement(nsIConsoleMessage* aMessage) : mMessage(aMessage) {}
|
|
|
|
|
|
|
|
nsIConsoleMessage* Get() { return mMessage.get(); }
|
|
|
|
|
2015-10-03 00:47:13 +03:00
|
|
|
// Swap directly into an nsCOMPtr to avoid spurious refcount
|
|
|
|
// traffic off the main thread in debug builds from
|
|
|
|
// NSCAP_ASSERT_NO_QUERY_NEEDED().
|
|
|
|
void swapMessage(nsCOMPtr<nsIConsoleMessage>& aRetVal) {
|
|
|
|
mMessage.swap(aRetVal);
|
2015-08-18 04:05:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~MessageElement();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIConsoleMessage> mMessage;
|
|
|
|
|
|
|
|
MessageElement(const MessageElement&) = delete;
|
|
|
|
MessageElement& operator=(const MessageElement&) = delete;
|
|
|
|
MessageElement(MessageElement&&) = delete;
|
|
|
|
MessageElement& operator=(MessageElement&&) = delete;
|
|
|
|
};
|
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
~nsConsoleService();
|
2004-01-15 09:14:18 +03:00
|
|
|
|
2019-09-04 12:44:50 +03:00
|
|
|
nsresult MaybeForwardScriptError(nsIConsoleMessage* aMessage, bool* sent);
|
|
|
|
|
2015-07-31 16:49:27 +03:00
|
|
|
void ClearMessagesForWindowID(const uint64_t innerID);
|
2022-08-03 19:39:41 +03:00
|
|
|
void ClearMessages() MOZ_REQUIRES(mLock);
|
2015-07-31 16:49:27 +03:00
|
|
|
|
2022-08-03 19:39:41 +03:00
|
|
|
mozilla::LinkedList<MessageElement> mMessages MOZ_GUARDED_BY(mLock);
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2015-08-18 04:05:48 +03:00
|
|
|
// The current size of mMessages.
|
2022-08-03 19:39:41 +03:00
|
|
|
uint32_t mCurrentSize MOZ_GUARDED_BY(mLock);
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2015-08-18 04:05:48 +03:00
|
|
|
// The maximum size of mMessages.
|
2022-03-24 01:22:51 +03:00
|
|
|
const uint32_t mMaximumSize;
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// Are we currently delivering a console message on the main thread? If
|
|
|
|
// so, we suppress incoming messages on the main thread only, to avoid
|
|
|
|
// infinite repitition.
|
2022-03-24 01:22:51 +03:00
|
|
|
// Only touched on MainThread
|
2014-05-05 21:30:39 +04:00
|
|
|
bool mDeliveringMessage;
|
2012-01-11 20:28:21 +04:00
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// Listeners to notify whenever a new message is logged.
|
2022-08-03 19:39:41 +03:00
|
|
|
ListenerHash mListeners MOZ_GUARDED_BY(mLock);
|
2000-04-18 06:34:54 +04:00
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// To serialize interesting methods.
|
2022-03-24 01:22:51 +03:00
|
|
|
mozilla::Mutex mLock;
|
2000-04-18 06:34:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __nsconsoleservice_h__ */
|