dom/quota/FileStreams.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/quota/FileStreams.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     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
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_quota_filestreams_h__
    1.11 +#define mozilla_dom_quota_filestreams_h__
    1.12 +
    1.13 +#include "QuotaCommon.h"
    1.14 +
    1.15 +#include "nsFileStreams.h"
    1.16 +
    1.17 +#include "PersistenceType.h"
    1.18 +#include "QuotaObject.h"
    1.19 +
    1.20 +BEGIN_QUOTA_NAMESPACE
    1.21 +
    1.22 +template <class FileStreamBase>
    1.23 +class FileQuotaStream : public FileStreamBase
    1.24 +{
    1.25 +public:
    1.26 +  // nsFileStreamBase override
    1.27 +  NS_IMETHOD
    1.28 +  SetEOF() MOZ_OVERRIDE;
    1.29 +
    1.30 +  NS_IMETHOD
    1.31 +  Close() MOZ_OVERRIDE;
    1.32 +
    1.33 +protected:
    1.34 +  FileQuotaStream(PersistenceType aPersistenceType, const nsACString& aGroup,
    1.35 +                  const nsACString& aOrigin)
    1.36 +  : mPersistenceType(aPersistenceType), mGroup(aGroup), mOrigin(aOrigin)
    1.37 +  { }
    1.38 +
    1.39 +  // nsFileStreamBase override
    1.40 +  virtual nsresult
    1.41 +  DoOpen() MOZ_OVERRIDE;
    1.42 +
    1.43 +  PersistenceType mPersistenceType;
    1.44 +  nsCString mGroup;
    1.45 +  nsCString mOrigin;
    1.46 +  nsRefPtr<QuotaObject> mQuotaObject;
    1.47 +};
    1.48 +
    1.49 +template <class FileStreamBase>
    1.50 +class FileQuotaStreamWithWrite : public FileQuotaStream<FileStreamBase>
    1.51 +{
    1.52 +public:
    1.53 +  // nsFileStreamBase override
    1.54 +  NS_IMETHOD
    1.55 +  Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) MOZ_OVERRIDE;
    1.56 +
    1.57 +protected:
    1.58 +  FileQuotaStreamWithWrite(PersistenceType aPersistenceType,
    1.59 +                           const nsACString& aGroup, const nsACString& aOrigin)
    1.60 +  : FileQuotaStream<FileStreamBase>(aPersistenceType, aGroup, aOrigin)
    1.61 +  { }
    1.62 +};
    1.63 +
    1.64 +class FileInputStream : public FileQuotaStream<nsFileInputStream>
    1.65 +{
    1.66 +public:
    1.67 +  NS_DECL_ISUPPORTS_INHERITED
    1.68 +
    1.69 +  static already_AddRefed<FileInputStream>
    1.70 +  Create(PersistenceType aPersistenceType, const nsACString& aGroup,
    1.71 +         const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
    1.72 +         int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
    1.73 +
    1.74 +private:
    1.75 +  FileInputStream(PersistenceType aPersistenceType, const nsACString& aGroup,
    1.76 +                  const nsACString& aOrigin)
    1.77 +  : FileQuotaStream<nsFileInputStream>(aPersistenceType, aGroup, aOrigin)
    1.78 +  { }
    1.79 +
    1.80 +  virtual ~FileInputStream() {
    1.81 +    Close();
    1.82 +  }
    1.83 +};
    1.84 +
    1.85 +class FileOutputStream : public FileQuotaStreamWithWrite<nsFileOutputStream>
    1.86 +{
    1.87 +public:
    1.88 +  NS_DECL_ISUPPORTS_INHERITED
    1.89 +
    1.90 +  static already_AddRefed<FileOutputStream>
    1.91 +  Create(PersistenceType aPersistenceType, const nsACString& aGroup,
    1.92 +         const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
    1.93 +         int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
    1.94 +
    1.95 +private:
    1.96 +  FileOutputStream(PersistenceType aPersistenceType, const nsACString& aGroup,
    1.97 +                   const nsACString& aOrigin)
    1.98 +  : FileQuotaStreamWithWrite<nsFileOutputStream>(aPersistenceType, aGroup,
    1.99 +                                                 aOrigin)
   1.100 +  { }
   1.101 +
   1.102 +  virtual ~FileOutputStream() {
   1.103 +    Close();
   1.104 +  }
   1.105 +};
   1.106 +
   1.107 +class FileStream : public FileQuotaStreamWithWrite<nsFileStream>
   1.108 +{
   1.109 +public:
   1.110 +  NS_DECL_ISUPPORTS_INHERITED
   1.111 +
   1.112 +  static already_AddRefed<FileStream>
   1.113 +  Create(PersistenceType aPersistenceType, const nsACString& aGroup,
   1.114 +         const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags = -1,
   1.115 +         int32_t aPerm = -1, int32_t aBehaviorFlags = 0);
   1.116 +
   1.117 +private:
   1.118 +  FileStream(PersistenceType aPersistenceType, const nsACString& aGroup,
   1.119 +             const nsACString& aOrigin)
   1.120 +  : FileQuotaStreamWithWrite<nsFileStream>(aPersistenceType, aGroup, aOrigin)
   1.121 +  { }
   1.122 +
   1.123 +  virtual ~FileStream() {
   1.124 +    Close();
   1.125 +  }
   1.126 +};
   1.127 +
   1.128 +END_QUOTA_NAMESPACE
   1.129 +
   1.130 +#endif /* mozilla_dom_quota_filestreams_h__ */

mercurial