1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "LSObserver.h"
10 #include "ActorsChild.h"
14 #include "mozilla/StaticPtr.h"
15 #include "nsTHashMap.h"
16 #include "nsHashKeys.h"
18 namespace mozilla::dom
{
22 using LSObserverHashtable
= nsTHashMap
<nsCStringHashKey
, LSObserver
*>;
24 StaticAutoPtr
<LSObserverHashtable
> gLSObservers
;
28 LSObserver::LSObserver(const nsACString
& aOrigin
)
29 : mActor(nullptr), mOrigin(aOrigin
) {
30 AssertIsOnOwningThread();
33 gLSObservers
= new LSObserverHashtable();
36 MOZ_ASSERT(!gLSObservers
->Contains(mOrigin
));
37 gLSObservers
->InsertOrUpdate(mOrigin
, this);
40 LSObserver::~LSObserver() {
41 AssertIsOnOwningThread();
44 mActor
->SendDeleteMeInternal();
45 MOZ_ASSERT(!mActor
, "SendDeleteMeInternal should have cleared!");
48 MOZ_ASSERT(gLSObservers
);
49 MOZ_ASSERT(gLSObservers
->Get(mOrigin
));
50 gLSObservers
->Remove(mOrigin
);
52 if (!gLSObservers
->Count()) {
53 gLSObservers
= nullptr;
58 LSObserver
* LSObserver::Get(const nsACString
& aOrigin
) {
59 return gLSObservers
? gLSObservers
->Get(aOrigin
) : nullptr;
62 void LSObserver::SetActor(LSObserverChild
* aActor
) {
63 AssertIsOnOwningThread();
70 } // namespace mozilla::dom