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 : #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 "nsTArray.h"
14 : #include "nsString.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class StorageObserver;
20 :
21 : // Implementers are StorageManager and StorageDBParent to forward to
22 : // child processes.
23 4 : class StorageObserverSink
24 : {
25 : public:
26 0 : virtual ~StorageObserverSink() {}
27 :
28 : private:
29 : friend class StorageObserver;
30 : virtual nsresult Observe(const char* aTopic,
31 : const nsAString& aOriginAttributesPattern,
32 : const nsACString& aOriginScope) = 0;
33 : };
34 :
35 : // Statically (through layout statics) initialized observer receiving and
36 : // processing chrome clearing notifications, such as cookie deletion etc.
37 3 : class StorageObserver : public nsIObserver
38 : , public nsSupportsWeakReference
39 : {
40 : public:
41 : NS_DECL_ISUPPORTS
42 : NS_DECL_NSIOBSERVER
43 :
44 : static nsresult Init();
45 : static nsresult Shutdown();
46 4 : static StorageObserver* Self() { return sSelf; }
47 :
48 : void AddSink(StorageObserverSink* aObs);
49 : void RemoveSink(StorageObserverSink* aObs);
50 : void Notify(const char* aTopic,
51 1 : const nsAString& aOriginAttributesPattern = EmptyString(),
52 1 : const nsACString& aOriginScope = EmptyCString());
53 :
54 : private:
55 0 : virtual ~StorageObserver() {}
56 :
57 : static void TestingPrefChanged(const char* aPrefName, void* aClosure);
58 :
59 : static StorageObserver* sSelf;
60 :
61 : // Weak references
62 : nsTArray<StorageObserverSink*> mSinks;
63 : nsCOMPtr<nsITimer> mDBThreadStartDelayTimer;
64 : };
65 :
66 : } // namespace dom
67 : } // namespace mozilla
68 :
69 : #endif // mozilla_dom_StorageObserver_h
|