dom/quota/Client.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/quota/Client.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_quota_client_h__
    1.11 +#define mozilla_dom_quota_client_h__
    1.12 +
    1.13 +#include "mozilla/dom/quota/QuotaCommon.h"
    1.14 +
    1.15 +#include "PersistenceType.h"
    1.16 +
    1.17 +class nsIOfflineStorage;
    1.18 +class nsIRunnable;
    1.19 +
    1.20 +#define IDB_DIRECTORY_NAME "idb"
    1.21 +#define ASMJSCACHE_DIRECTORY_NAME "asmjs"
    1.22 +
    1.23 +BEGIN_QUOTA_NAMESPACE
    1.24 +
    1.25 +class OriginOrPatternString;
    1.26 +class UsageInfo;
    1.27 +
    1.28 +// An abstract interface for quota manager clients.
    1.29 +// Each storage API must provide an implementation of this interface in order
    1.30 +// to participate in centralized quota and storage handling.
    1.31 +class Client
    1.32 +{
    1.33 +public:
    1.34 +  NS_IMETHOD_(MozExternalRefCountType)
    1.35 +  AddRef() = 0;
    1.36 +
    1.37 +  NS_IMETHOD_(MozExternalRefCountType)
    1.38 +  Release() = 0;
    1.39 +
    1.40 +  enum Type {
    1.41 +    IDB = 0,
    1.42 +    //LS,
    1.43 +    //APPCACHE,
    1.44 +    ASMJS,
    1.45 +    TYPE_MAX
    1.46 +  };
    1.47 +
    1.48 +  virtual Type
    1.49 +  GetType() = 0;
    1.50 +
    1.51 +  static nsresult
    1.52 +  TypeToText(Type aType, nsAString& aText)
    1.53 +  {
    1.54 +    switch (aType) {
    1.55 +      case IDB:
    1.56 +        aText.AssignLiteral(IDB_DIRECTORY_NAME);
    1.57 +        break;
    1.58 +
    1.59 +      case ASMJS:
    1.60 +        aText.AssignLiteral(ASMJSCACHE_DIRECTORY_NAME);
    1.61 +        break;
    1.62 +
    1.63 +      case TYPE_MAX:
    1.64 +      default:
    1.65 +        NS_NOTREACHED("Bad id value!");
    1.66 +        return NS_ERROR_UNEXPECTED;
    1.67 +    }
    1.68 +
    1.69 +    return NS_OK;
    1.70 +  }
    1.71 +
    1.72 +  static nsresult
    1.73 +  TypeFromText(const nsAString& aText, Type& aType)
    1.74 +  {
    1.75 +    if (aText.EqualsLiteral(IDB_DIRECTORY_NAME)) {
    1.76 +      aType = IDB;
    1.77 +    }
    1.78 +    else if (aText.EqualsLiteral(ASMJSCACHE_DIRECTORY_NAME)) {
    1.79 +      aType = ASMJS;
    1.80 +    }
    1.81 +    else {
    1.82 +      return NS_ERROR_FAILURE;
    1.83 +    }
    1.84 +
    1.85 +    return NS_OK;
    1.86 +  }
    1.87 +
    1.88 +  // Methods which are called on the IO thred.
    1.89 +  virtual nsresult
    1.90 +  InitOrigin(PersistenceType aPersistenceType,
    1.91 +             const nsACString& aGroup,
    1.92 +             const nsACString& aOrigin,
    1.93 +             UsageInfo* aUsageInfo) = 0;
    1.94 +
    1.95 +  virtual nsresult
    1.96 +  GetUsageForOrigin(PersistenceType aPersistenceType,
    1.97 +                    const nsACString& aGroup,
    1.98 +                    const nsACString& aOrigin,
    1.99 +                    UsageInfo* aUsageInfo) = 0;
   1.100 +
   1.101 +  virtual void
   1.102 +  OnOriginClearCompleted(PersistenceType aPersistenceType,
   1.103 +                         const OriginOrPatternString& aOriginOrPattern) = 0;
   1.104 +
   1.105 +  virtual void
   1.106 +  ReleaseIOThreadObjects() = 0;
   1.107 +
   1.108 +  // Methods which are called on the main thred.
   1.109 +  virtual bool
   1.110 +  IsFileServiceUtilized() = 0;
   1.111 +
   1.112 +  virtual bool
   1.113 +  IsTransactionServiceActivated() = 0;
   1.114 +
   1.115 +  virtual void
   1.116 +  WaitForStoragesToComplete(nsTArray<nsIOfflineStorage*>& aStorages,
   1.117 +                            nsIRunnable* aCallback) = 0;
   1.118 +
   1.119 +  virtual void
   1.120 +  AbortTransactionsForStorage(nsIOfflineStorage* aStorage) = 0;
   1.121 +
   1.122 +  virtual bool
   1.123 +  HasTransactionsForStorage(nsIOfflineStorage* aStorage) = 0;
   1.124 +
   1.125 +  virtual void
   1.126 +  ShutdownTransactionService() = 0;
   1.127 +
   1.128 +protected:
   1.129 +  virtual ~Client()
   1.130 +  { }
   1.131 +};
   1.132 +
   1.133 +END_QUOTA_NAMESPACE
   1.134 +
   1.135 +#endif // mozilla_dom_quota_client_h__

mercurial