Source code

Revision control

Other Tools

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_StorageObserver_h
8
#define mozilla_dom_StorageObserver_h
9
10
#include "nsIObserver.h"
11
#include "nsITimer.h"
12
#include "nsWeakReference.h"
13
#include "nsTObserverArray.h"
14
#include "nsString.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
class StorageObserver;
20
21
// Main-thread interface implemented by legacy LocalStorageManager and current
22
// SessionStorageManager for direct consumption. Also implemented by legacy
23
// StorageDBParent and current SessionStorageObserverParent for propagation to
24
// content processes.
25
class StorageObserverSink {
26
public:
27
virtual ~StorageObserverSink() {}
28
29
private:
30
friend class StorageObserver;
31
virtual nsresult Observe(const char* aTopic,
32
const nsAString& aOriginAttributesPattern,
33
const nsACString& aOriginScope) = 0;
34
};
35
36
// Statically (through layout statics) initialized observer receiving and
37
// processing chrome clearing notifications, such as cookie deletion etc.
38
class StorageObserver : public nsIObserver, public nsSupportsWeakReference {
39
public:
40
NS_DECL_ISUPPORTS
41
NS_DECL_NSIOBSERVER
42
43
static nsresult Init();
44
static nsresult Shutdown();
45
static StorageObserver* Self() { return sSelf; }
46
47
void AddSink(StorageObserverSink* aObs);
48
void RemoveSink(StorageObserverSink* aObs);
49
void Notify(const char* aTopic,
50
const nsAString& aOriginAttributesPattern = EmptyString(),
51
const nsACString& aOriginScope = EmptyCString());
52
53
void NoteBackgroundThread(nsIEventTarget* aBackgroundThread);
54
55
private:
56
virtual ~StorageObserver() {}
57
58
nsresult GetOriginScope(const char16_t* aData, nsACString& aOriginScope);
59
60
static void TestingPrefChanged(const char* aPrefName, void* aClosure);
61
62
static StorageObserver* sSelf;
63
64
nsCOMPtr<nsIEventTarget> mBackgroundThread;
65
66
// Weak references
67
nsTObserverArray<StorageObserverSink*> mSinks;
68
nsCOMPtr<nsITimer> mDBThreadStartDelayTimer;
69
};
70
71
} // namespace dom
72
} // namespace mozilla
73
74
#endif // mozilla_dom_StorageObserver_h