/src/mozilla-central/dom/quota/FileStreams.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=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/. */ |
6 | | |
7 | | #include "FileStreams.h" |
8 | | |
9 | | #include "QuotaManager.h" |
10 | | #include "prio.h" |
11 | | |
12 | | BEGIN_QUOTA_NAMESPACE |
13 | | |
14 | | template <class FileStreamBase> |
15 | | NS_IMETHODIMP |
16 | | FileQuotaStream<FileStreamBase>::SetEOF() |
17 | 0 | { |
18 | 0 | nsresult rv = FileStreamBase::SetEOF(); |
19 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
20 | 0 |
|
21 | 0 | if (mQuotaObject) { |
22 | 0 | int64_t offset; |
23 | 0 | nsresult rv = FileStreamBase::Tell(&offset); |
24 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
25 | 0 |
|
26 | 0 | mQuotaObject->MaybeUpdateSize(offset, /* aTruncate */ true); |
27 | 0 | } |
28 | 0 |
|
29 | 0 | return NS_OK; |
30 | 0 | } Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileInputStream>::SetEOF() Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileOutputStream>::SetEOF() Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileStream>::SetEOF() |
31 | | |
32 | | template <class FileStreamBase> |
33 | | NS_IMETHODIMP |
34 | | FileQuotaStream<FileStreamBase>::Close() |
35 | 0 | { |
36 | 0 | nsresult rv = FileStreamBase::Close(); |
37 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
38 | 0 |
|
39 | 0 | mQuotaObject = nullptr; |
40 | 0 |
|
41 | 0 | return NS_OK; |
42 | 0 | } Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileInputStream>::Close() Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileOutputStream>::Close() Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileStream>::Close() |
43 | | |
44 | | template <class FileStreamBase> |
45 | | nsresult |
46 | | FileQuotaStream<FileStreamBase>::DoOpen() |
47 | 0 | { |
48 | 0 | QuotaManager* quotaManager = QuotaManager::Get(); |
49 | 0 | NS_ASSERTION(quotaManager, "Shouldn't be null!"); |
50 | 0 |
|
51 | 0 | NS_ASSERTION(!mQuotaObject, "Creating quota object more than once?"); |
52 | 0 | mQuotaObject = quotaManager->GetQuotaObject(mPersistenceType, mGroup, mOrigin, |
53 | 0 | FileStreamBase::mOpenParams.localFile); |
54 | 0 |
|
55 | 0 | nsresult rv = FileStreamBase::DoOpen(); |
56 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
57 | 0 |
|
58 | 0 | if (mQuotaObject && (FileStreamBase::mOpenParams.ioFlags & PR_TRUNCATE)) { |
59 | 0 | mQuotaObject->MaybeUpdateSize(0, /* aTruncate */ true); |
60 | 0 | } |
61 | 0 |
|
62 | 0 | return NS_OK; |
63 | 0 | } Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileInputStream>::DoOpen() Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileOutputStream>::DoOpen() Unexecuted instantiation: mozilla::dom::quota::FileQuotaStream<nsFileStream>::DoOpen() |
64 | | |
65 | | template <class FileStreamBase> |
66 | | NS_IMETHODIMP |
67 | | FileQuotaStreamWithWrite<FileStreamBase>::Write(const char* aBuf, |
68 | | uint32_t aCount, |
69 | | uint32_t* _retval) |
70 | 0 | { |
71 | 0 | nsresult rv; |
72 | 0 |
|
73 | 0 | if (FileQuotaStreamWithWrite::mQuotaObject) { |
74 | 0 | int64_t offset; |
75 | 0 | rv = FileStreamBase::Tell(&offset); |
76 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
77 | 0 |
|
78 | 0 | MOZ_ASSERT(INT64_MAX - offset >= int64_t(aCount)); |
79 | 0 |
|
80 | 0 | if (!FileQuotaStreamWithWrite:: |
81 | 0 | mQuotaObject->MaybeUpdateSize(offset + int64_t(aCount), |
82 | 0 | /* aTruncate */ false)) { |
83 | 0 | return NS_ERROR_FILE_NO_DEVICE_SPACE; |
84 | 0 | } |
85 | 0 | } |
86 | 0 | |
87 | 0 | rv = FileStreamBase::Write(aBuf, aCount, _retval); |
88 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
89 | 0 |
|
90 | 0 | return NS_OK; |
91 | 0 | } Unexecuted instantiation: mozilla::dom::quota::FileQuotaStreamWithWrite<nsFileOutputStream>::Write(char const*, unsigned int, unsigned int*) Unexecuted instantiation: mozilla::dom::quota::FileQuotaStreamWithWrite<nsFileStream>::Write(char const*, unsigned int, unsigned int*) |
92 | | |
93 | | already_AddRefed<FileInputStream> |
94 | | CreateFileInputStream(PersistenceType aPersistenceType, |
95 | | const nsACString& aGroup, |
96 | | const nsACString& aOrigin, |
97 | | nsIFile* aFile, |
98 | | int32_t aIOFlags, |
99 | | int32_t aPerm, |
100 | | int32_t aBehaviorFlags) |
101 | 0 | { |
102 | 0 | RefPtr<FileInputStream> stream = |
103 | 0 | new FileInputStream(aPersistenceType, aGroup, aOrigin); |
104 | 0 | nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags); |
105 | 0 | NS_ENSURE_SUCCESS(rv, nullptr); |
106 | 0 | return stream.forget(); |
107 | 0 | } |
108 | | |
109 | | already_AddRefed<FileOutputStream> |
110 | | CreateFileOutputStream(PersistenceType aPersistenceType, |
111 | | const nsACString& aGroup, |
112 | | const nsACString& aOrigin, |
113 | | nsIFile* aFile, |
114 | | int32_t aIOFlags, |
115 | | int32_t aPerm, |
116 | | int32_t aBehaviorFlags) |
117 | 0 | { |
118 | 0 | RefPtr<FileOutputStream> stream = |
119 | 0 | new FileOutputStream(aPersistenceType, aGroup, aOrigin); |
120 | 0 | nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags); |
121 | 0 | NS_ENSURE_SUCCESS(rv, nullptr); |
122 | 0 | return stream.forget(); |
123 | 0 | } |
124 | | |
125 | | already_AddRefed<FileStream> |
126 | | CreateFileStream(PersistenceType aPersistenceType, |
127 | | const nsACString& aGroup, |
128 | | const nsACString& aOrigin, |
129 | | nsIFile* aFile, |
130 | | int32_t aIOFlags, |
131 | | int32_t aPerm, |
132 | | int32_t aBehaviorFlags) |
133 | 0 | { |
134 | 0 | RefPtr<FileStream> stream = |
135 | 0 | new FileStream(aPersistenceType, aGroup, aOrigin); |
136 | 0 | nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags); |
137 | 0 | NS_ENSURE_SUCCESS(rv, nullptr); |
138 | 0 | return stream.forget(); |
139 | 0 | } |
140 | | |
141 | | END_QUOTA_NAMESPACE |