dom/quota/Client.h
author Fabrice Desré <fabrice@mozilla.com>
Wed, 23 Oct 2013 11:56:20 -0700
changeset 152643 f103eff52a1a224321b1e8d6d5a32ff45fa869e5
parent 146523 8734ea74053b8cbcce4085cd1b6972e80b30b600
child 157716 5387d9c92201b3fa6a712b5287af0f3b3a1cb734
permissions -rw-r--r--
Bug 924702 - Rewrite the app:// protocol handler in c++ r=jduell,mrbkap

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=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_quota_client_h__
#define mozilla_dom_quota_client_h__

#include "mozilla/dom/quota/QuotaCommon.h"

#include "PersistenceType.h"

class nsIOfflineStorage;
class nsIRunnable;

BEGIN_QUOTA_NAMESPACE

class OriginOrPatternString;
class UsageInfo;

// An abstract interface for quota manager clients.
// Each storage API must provide an implementation of this interface in order
// to participate in centralized quota and storage handling.
class Client
{
public:
  NS_IMETHOD_(nsrefcnt)
  AddRef() = 0;

  NS_IMETHOD_(nsrefcnt)
  Release() = 0;

  enum Type {
    IDB = 0,
    //LS,
    //APPCACHE,
    TYPE_MAX
  };

  virtual Type
  GetType() = 0;

  static nsresult
  TypeToText(Type aType, nsAString& aText)
  {
    switch (aType) {
      case IDB:
        aText.AssignLiteral("idb");
        break;

      case TYPE_MAX:
      default:
        NS_NOTREACHED("Bad id value!");
        return NS_ERROR_UNEXPECTED;
    }

    return NS_OK;
  }

  static nsresult
  TypeFromText(const nsAString& aText, Type& aType)
  {
    if (aText.EqualsLiteral("idb")) {
      aType = IDB;
    }
    else {
      return NS_ERROR_FAILURE;
    }

    return NS_OK;
  }

  // Methods which are called on the IO thred.
  virtual nsresult
  InitOrigin(PersistenceType aPersistenceType,
             const nsACString& aGroup,
             const nsACString& aOrigin,
             UsageInfo* aUsageInfo) = 0;

  virtual nsresult
  GetUsageForOrigin(PersistenceType aPersistenceType,
                    const nsACString& aGroup,
                    const nsACString& aOrigin,
                    UsageInfo* aUsageInfo) = 0;

  virtual void
  OnOriginClearCompleted(PersistenceType aPersistenceType,
                         const OriginOrPatternString& aOriginOrPattern) = 0;

  virtual void
  ReleaseIOThreadObjects() = 0;

  // Methods which are called on the main thred.
  virtual bool
  IsFileServiceUtilized() = 0;

  virtual bool
  IsTransactionServiceActivated() = 0;

  virtual void
  WaitForStoragesToComplete(nsTArray<nsIOfflineStorage*>& aStorages,
                            nsIRunnable* aCallback) = 0;

  virtual void
  AbortTransactionsForStorage(nsIOfflineStorage* aStorage) = 0;

  virtual bool
  HasTransactionsForStorage(nsIOfflineStorage* aStorage) = 0;

  virtual void
  ShutdownTransactionService() = 0;

protected:
  virtual ~Client()
  { }
};

END_QUOTA_NAMESPACE

#endif // mozilla_dom_quota_client_h__