dom/quota/Client.h
author Tom Tung <shes050117@gmail.com>
Tue, 18 Jul 2017 18:54:20 +0800
changeset 429026 a3844ec447b4d85e8abff9b3fad06dda5b7f17fb
parent 397064 f9f06917c82a73e18a1ef189c891f506b313aa01
child 432603 6513161002fc5715cf7996a22fb7998226073dbc
permissions -rw-r--r--
Bug 1290481 - P6: Upgrade QuotaManager to v3.0 for adding directory padding file to existing DOM Cache directory. r=bkelly, janv MozReview-Commit-ID: KlVsaGhpABk

/* -*- 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_quota_client_h__
#define mozilla_dom_quota_client_h__

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

#include "mozilla/dom/ipc/IdType.h"

#include "PersistenceType.h"

class nsIFile;
class nsIRunnable;

#define IDB_DIRECTORY_NAME "idb"
#define ASMJSCACHE_DIRECTORY_NAME "asmjs"
#define DOMCACHE_DIRECTORY_NAME "cache"

BEGIN_QUOTA_NAMESPACE

class QuotaManager;
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:
  typedef mozilla::Atomic<bool> AtomicBool;

  NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING

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

  virtual Type
  GetType() = 0;

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

      case ASMJS:
        aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME);
        break;

      case DOMCACHE:
        aText.AssignLiteral(DOMCACHE_DIRECTORY_NAME);
        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_DIRECTORY_NAME)) {
      aType = IDB;
    }
    else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) {
      aType = ASMJS;
    }
    else if (aText.EqualsLiteral(DOMCACHE_DIRECTORY_NAME)) {
      aType = DOMCACHE;
    }
    else {
      return NS_ERROR_FAILURE;
    }

    return NS_OK;
  }

  // Methods which are called on the IO thread.
  virtual nsresult
  UpgradeStorageFrom1_0To2_0(nsIFile* aDirectory)
  {
    return NS_OK;
  }

  virtual nsresult
  UpgradeStorageFrom2_0To3_0(nsIFile* aDirectory)
  {
    return NS_OK;
  }

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

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

  virtual void
  OnOriginClearCompleted(PersistenceType aPersistenceType,
                         const nsACString& aOrigin) = 0;

  virtual void
  ReleaseIOThreadObjects() = 0;

  // Methods which are called on the background thread.
  virtual void
  AbortOperations(const nsACString& aOrigin) = 0;

  virtual void
  AbortOperationsForProcess(ContentParentId aContentParentId) = 0;

  virtual void
  StartIdleMaintenance() = 0;

  virtual void
  StopIdleMaintenance() = 0;

  virtual void
  ShutdownWorkThreads() = 0;

  // Methods which are called on the main thread.
  virtual void
  DidInitialize(QuotaManager* aQuotaManager)
  { }

  virtual void
  WillShutdown()
  { }

protected:
  virtual ~Client()
  { }
};

END_QUOTA_NAMESPACE

#endif // mozilla_dom_quota_client_h__