Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/storage/StorageObserver.h
Line
Count
Source (jump to first uncovered line)
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
// Implementers are StorageManager and StorageDBParent to forward to
22
// child processes.
23
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
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
0
  static StorageObserver* Self() { return sSelf; }
47
48
  void AddSink(StorageObserverSink* aObs);
49
  void RemoveSink(StorageObserverSink* aObs);
50
  void Notify(const char* aTopic,
51
              const nsAString& aOriginAttributesPattern = EmptyString(),
52
              const nsACString& aOriginScope = EmptyCString());
53
54
  void
55
  NoteBackgroundThread(nsIEventTarget* aBackgroundThread);
56
57
private:
58
0
  virtual ~StorageObserver() {}
59
60
  nsresult
61
  ClearMatchingOrigin(const char16_t* aData,
62
                      nsACString& aOriginScope);
63
64
  static void TestingPrefChanged(const char* aPrefName, void* aClosure);
65
66
  static StorageObserver* sSelf;
67
68
  nsCOMPtr<nsIEventTarget> mBackgroundThread;
69
70
  // Weak references
71
  nsTObserverArray<StorageObserverSink*> mSinks;
72
  nsCOMPtr<nsITimer> mDBThreadStartDelayTimer;
73
};
74
75
} // namespace dom
76
} // namespace mozilla
77
78
#endif // mozilla_dom_StorageObserver_h