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/. */
7 #ifndef mozilla_dom_StorageObserver_h
8 #define mozilla_dom_StorageObserver_h
10 #include "mozilla/dom/quota/CheckedUnsafePtr.h"
12 #include "nsIObserver.h"
14 #include "nsWeakReference.h"
15 #include "nsTObserverArray.h"
18 namespace mozilla::dom
{
20 class StorageObserver
;
22 // Main-thread interface implemented by legacy LocalStorageManager and current
23 // SessionStorageManager for direct consumption. Also implemented by legacy
24 // StorageDBParent and current SessionStorageObserverParent for propagation to
26 class StorageObserverSink
27 : public SupportsCheckedUnsafePtr
<CheckIf
<DiagnosticAssertEnabled
>> {
29 virtual ~StorageObserverSink() = default;
32 friend class StorageObserver
;
33 virtual nsresult
Observe(const char* aTopic
,
34 const nsAString
& aOriginAttributesPattern
,
35 const nsACString
& aOriginScope
) = 0;
38 // Statically (through layout statics) initialized observer receiving and
39 // processing chrome clearing notifications, such as cookie deletion etc.
40 class StorageObserver
: public nsIObserver
,
42 public nsSupportsWeakReference
{
48 static nsresult
Init();
49 static nsresult
Shutdown();
50 static StorageObserver
* Self() { return sSelf
; }
52 void AddSink(StorageObserverSink
* aObs
);
53 void RemoveSink(StorageObserverSink
* aObs
);
54 void Notify(const char* aTopic
,
55 const nsAString
& aOriginAttributesPattern
= u
""_ns
,
56 const nsACString
& aOriginScope
= ""_ns
);
58 void NoteBackgroundThread(uint32_t aPrivateBrowsingId
,
59 nsIEventTarget
* aBackgroundThread
);
62 virtual ~StorageObserver() = default;
64 nsresult
GetOriginScope(const char16_t
* aData
, nsACString
& aOriginScope
);
66 static void TestingPrefChanged(const char* aPrefName
, void* aClosure
);
68 static StorageObserver
* sSelf
;
70 nsCOMPtr
<nsIEventTarget
> mBackgroundThread
[2];
73 nsTObserverArray
<CheckedUnsafePtr
<StorageObserverSink
>> mSinks
;
74 nsCOMPtr
<nsITimer
> mDBThreadStartDelayTimer
;
77 } // namespace mozilla::dom
79 #endif // mozilla_dom_StorageObserver_h