1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_quota_filestreams_h__
8 #define mozilla_dom_quota_filestreams_h__
10 #include "QuotaCommon.h"
12 #include "nsFileStreams.h"
14 #include "PersistenceType.h"
15 #include "QuotaObject.h"
19 template <class FileStreamBase
>
20 class FileQuotaStream
: public FileStreamBase
23 // nsFileStreamBase override
25 SetEOF() MOZ_OVERRIDE
;
31 FileQuotaStream(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
32 const nsACString
& aOrigin
)
33 : mPersistenceType(aPersistenceType
), mGroup(aGroup
), mOrigin(aOrigin
)
36 // nsFileStreamBase override
38 DoOpen() MOZ_OVERRIDE
;
40 PersistenceType mPersistenceType
;
43 nsRefPtr
<QuotaObject
> mQuotaObject
;
46 template <class FileStreamBase
>
47 class FileQuotaStreamWithWrite
: public FileQuotaStream
<FileStreamBase
>
50 // nsFileStreamBase override
52 Write(const char* aBuf
, uint32_t aCount
, uint32_t* _retval
) MOZ_OVERRIDE
;
55 FileQuotaStreamWithWrite(PersistenceType aPersistenceType
,
56 const nsACString
& aGroup
, const nsACString
& aOrigin
)
57 : FileQuotaStream
<FileStreamBase
>(aPersistenceType
, aGroup
, aOrigin
)
61 class FileInputStream
: public FileQuotaStream
<nsFileInputStream
>
64 NS_DECL_ISUPPORTS_INHERITED
66 static already_AddRefed
<FileInputStream
>
67 Create(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
68 const nsACString
& aOrigin
, nsIFile
* aFile
, int32_t aIOFlags
= -1,
69 int32_t aPerm
= -1, int32_t aBehaviorFlags
= 0);
72 FileInputStream(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
73 const nsACString
& aOrigin
)
74 : FileQuotaStream
<nsFileInputStream
>(aPersistenceType
, aGroup
, aOrigin
)
77 virtual ~FileInputStream() {
82 class FileOutputStream
: public FileQuotaStreamWithWrite
<nsFileOutputStream
>
85 NS_DECL_ISUPPORTS_INHERITED
87 static already_AddRefed
<FileOutputStream
>
88 Create(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
89 const nsACString
& aOrigin
, nsIFile
* aFile
, int32_t aIOFlags
= -1,
90 int32_t aPerm
= -1, int32_t aBehaviorFlags
= 0);
93 FileOutputStream(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
94 const nsACString
& aOrigin
)
95 : FileQuotaStreamWithWrite
<nsFileOutputStream
>(aPersistenceType
, aGroup
,
99 virtual ~FileOutputStream() {
104 class FileStream
: public FileQuotaStreamWithWrite
<nsFileStream
>
107 NS_DECL_ISUPPORTS_INHERITED
109 static already_AddRefed
<FileStream
>
110 Create(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
111 const nsACString
& aOrigin
, nsIFile
* aFile
, int32_t aIOFlags
= -1,
112 int32_t aPerm
= -1, int32_t aBehaviorFlags
= 0);
115 FileStream(PersistenceType aPersistenceType
, const nsACString
& aGroup
,
116 const nsACString
& aOrigin
)
117 : FileQuotaStreamWithWrite
<nsFileStream
>(aPersistenceType
, aGroup
, aOrigin
)
120 virtual ~FileStream() {
127 #endif /* mozilla_dom_quota_filestreams_h__ */