DOMStorageObserver.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsIDOMStorageObserver_h__
  6. #define nsIDOMStorageObserver_h__
  7. #include "nsIObserver.h"
  8. #include "nsITimer.h"
  9. #include "nsWeakReference.h"
  10. #include "nsTArray.h"
  11. #include "nsString.h"
  12. namespace mozilla {
  13. namespace dom {
  14. class DOMStorageObserver;
  15. // Implementers are DOMStorageManager and DOMStorageDBParent to forward to
  16. // child processes.
  17. class DOMStorageObserverSink
  18. {
  19. public:
  20. virtual ~DOMStorageObserverSink() {}
  21. private:
  22. friend class DOMStorageObserver;
  23. virtual nsresult Observe(const char* aTopic,
  24. const nsAString& aOriginAttributesPattern,
  25. const nsACString& aOriginScope) = 0;
  26. };
  27. // Statically (though layout statics) initialized observer receiving and processing
  28. // chrome clearing notifications, such as cookie deletion etc.
  29. class DOMStorageObserver : public nsIObserver
  30. , public nsSupportsWeakReference
  31. {
  32. public:
  33. NS_DECL_ISUPPORTS
  34. NS_DECL_NSIOBSERVER
  35. static nsresult Init();
  36. static nsresult Shutdown();
  37. static DOMStorageObserver* Self() { return sSelf; }
  38. void AddSink(DOMStorageObserverSink* aObs);
  39. void RemoveSink(DOMStorageObserverSink* aObs);
  40. void Notify(const char* aTopic,
  41. const nsAString& aOriginAttributesPattern = EmptyString(),
  42. const nsACString& aOriginScope = EmptyCString());
  43. private:
  44. virtual ~DOMStorageObserver() {}
  45. static DOMStorageObserver* sSelf;
  46. // Weak references
  47. nsTArray<DOMStorageObserverSink*> mSinks;
  48. nsCOMPtr<nsITimer> mDBThreadStartDelayTimer;
  49. };
  50. } // namespace dom
  51. } // namespace mozilla
  52. #endif