dom/storage/StorageObserver.h
author Jan Varga <jan.varga@gmail.com>
Wed, 26 Jul 2017 12:19:13 +0200
changeset 421295 5b5c8f31b0a7dee674246143145f2b371b381cc8
parent 372940 5c83df4b3e89a3727c09530d82222e69dd6299c5
child 421647 89e197ce9f96ebe25f66035ddd0ef86301c0d98b
permissions -rw-r--r--
Bug 1350637 - Part 2: Core changes for LocalStorage on PBackground. r=asuth, a=lizzard - stop inheriting StorageDBBridge in StorageDBThread and StorageDBChild - move StorageDBThread and StorageDBChild initialization out of LocalStorageCache - use IPC even for the intra-process communication in main process - rationalize a bit storage observer code - make StorageDBParent to always be created and destroyed on the background thread

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_StorageObserver_h
#define mozilla_dom_StorageObserver_h

#include "nsIObserver.h"
#include "nsITimer.h"
#include "nsWeakReference.h"
#include "nsTArray.h"
#include "nsString.h"

namespace mozilla {
namespace dom {

class StorageObserver;

// Implementers are StorageManager and StorageDBParent to forward to
// child processes.
class StorageObserverSink
{
public:
  virtual ~StorageObserverSink() {}

private:
  friend class StorageObserver;
  virtual nsresult Observe(const char* aTopic,
                           const nsAString& aOriginAttributesPattern,
                           const nsACString& aOriginScope) = 0;
};

// Statically (through layout statics) initialized observer receiving and
// processing chrome clearing notifications, such as cookie deletion etc.
class StorageObserver : public nsIObserver
                      , public nsSupportsWeakReference
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIOBSERVER

  static nsresult Init();
  static nsresult Shutdown();
  static StorageObserver* Self() { return sSelf; }

  void AddSink(StorageObserverSink* aObs);
  void RemoveSink(StorageObserverSink* aObs);
  void Notify(const char* aTopic,
              const nsAString& aOriginAttributesPattern = EmptyString(),
              const nsACString& aOriginScope = EmptyCString());

  void
  NoteBackgroundThread(nsIEventTarget* aBackgroundThread);

private:
  virtual ~StorageObserver() {}

  static void TestingPrefChanged(const char* aPrefName, void* aClosure);

  static StorageObserver* sSelf;

  nsCOMPtr<nsIEventTarget> mBackgroundThread;

  // Weak references
  nsTArray<StorageObserverSink*> mSinks;
  nsCOMPtr<nsITimer> mDBThreadStartDelayTimer;
};

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_StorageObserver_h