dom/quota/FileStreams.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "FileStreams.h"
michael@0 8
michael@0 9 #include "QuotaManager.h"
michael@0 10 #include "prio.h"
michael@0 11
michael@0 12 USING_QUOTA_NAMESPACE
michael@0 13
michael@0 14 template <class FileStreamBase>
michael@0 15 NS_IMETHODIMP
michael@0 16 FileQuotaStream<FileStreamBase>::SetEOF()
michael@0 17 {
michael@0 18 nsresult rv = FileStreamBase::SetEOF();
michael@0 19 NS_ENSURE_SUCCESS(rv, rv);
michael@0 20
michael@0 21 if (mQuotaObject) {
michael@0 22 int64_t offset;
michael@0 23 nsresult rv = FileStreamBase::Tell(&offset);
michael@0 24 NS_ENSURE_SUCCESS(rv, rv);
michael@0 25
michael@0 26 mQuotaObject->UpdateSize(offset);
michael@0 27 }
michael@0 28
michael@0 29 return NS_OK;
michael@0 30 }
michael@0 31
michael@0 32 template <class FileStreamBase>
michael@0 33 NS_IMETHODIMP
michael@0 34 FileQuotaStream<FileStreamBase>::Close()
michael@0 35 {
michael@0 36 nsresult rv = FileStreamBase::Close();
michael@0 37 NS_ENSURE_SUCCESS(rv, rv);
michael@0 38
michael@0 39 mQuotaObject = nullptr;
michael@0 40
michael@0 41 return NS_OK;
michael@0 42 }
michael@0 43
michael@0 44 template <class FileStreamBase>
michael@0 45 nsresult
michael@0 46 FileQuotaStream<FileStreamBase>::DoOpen()
michael@0 47 {
michael@0 48 QuotaManager* quotaManager = QuotaManager::Get();
michael@0 49 NS_ASSERTION(quotaManager, "Shouldn't be null!");
michael@0 50
michael@0 51 NS_ASSERTION(!mQuotaObject, "Creating quota object more than once?");
michael@0 52 mQuotaObject = quotaManager->GetQuotaObject(mPersistenceType, mGroup, mOrigin,
michael@0 53 FileStreamBase::mOpenParams.localFile);
michael@0 54
michael@0 55 nsresult rv = FileStreamBase::DoOpen();
michael@0 56 NS_ENSURE_SUCCESS(rv, rv);
michael@0 57
michael@0 58 if (mQuotaObject && (FileStreamBase::mOpenParams.ioFlags & PR_TRUNCATE)) {
michael@0 59 mQuotaObject->UpdateSize(0);
michael@0 60 }
michael@0 61
michael@0 62 return NS_OK;
michael@0 63 }
michael@0 64
michael@0 65 template <class FileStreamBase>
michael@0 66 NS_IMETHODIMP
michael@0 67 FileQuotaStreamWithWrite<FileStreamBase>::Write(const char* aBuf,
michael@0 68 uint32_t aCount,
michael@0 69 uint32_t* _retval)
michael@0 70 {
michael@0 71 nsresult rv;
michael@0 72
michael@0 73 if (FileQuotaStreamWithWrite::mQuotaObject) {
michael@0 74 int64_t offset;
michael@0 75 rv = FileStreamBase::Tell(&offset);
michael@0 76 NS_ENSURE_SUCCESS(rv, rv);
michael@0 77
michael@0 78 if (!FileQuotaStreamWithWrite::
michael@0 79 mQuotaObject->MaybeAllocateMoreSpace(offset, aCount)) {
michael@0 80 return NS_ERROR_FILE_NO_DEVICE_SPACE;
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 rv = FileStreamBase::Write(aBuf, aCount, _retval);
michael@0 85 NS_ENSURE_SUCCESS(rv, rv);
michael@0 86
michael@0 87 return NS_OK;
michael@0 88 }
michael@0 89
michael@0 90 NS_IMPL_ISUPPORTS_INHERITED0(FileInputStream, nsFileInputStream)
michael@0 91
michael@0 92 already_AddRefed<FileInputStream>
michael@0 93 FileInputStream::Create(PersistenceType aPersistenceType,
michael@0 94 const nsACString& aGroup, const nsACString& aOrigin,
michael@0 95 nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
michael@0 96 int32_t aBehaviorFlags)
michael@0 97 {
michael@0 98 nsRefPtr<FileInputStream> stream =
michael@0 99 new FileInputStream(aPersistenceType, aGroup, aOrigin);
michael@0 100 nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
michael@0 101 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 102 return stream.forget();
michael@0 103 }
michael@0 104
michael@0 105 NS_IMPL_ISUPPORTS_INHERITED0(FileOutputStream, nsFileOutputStream)
michael@0 106
michael@0 107 already_AddRefed<FileOutputStream>
michael@0 108 FileOutputStream::Create(PersistenceType aPersistenceType,
michael@0 109 const nsACString& aGroup, const nsACString& aOrigin,
michael@0 110 nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
michael@0 111 int32_t aBehaviorFlags)
michael@0 112 {
michael@0 113 nsRefPtr<FileOutputStream> stream =
michael@0 114 new FileOutputStream(aPersistenceType, aGroup, aOrigin);
michael@0 115 nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
michael@0 116 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 117 return stream.forget();
michael@0 118 }
michael@0 119
michael@0 120 NS_IMPL_ISUPPORTS_INHERITED0(FileStream, nsFileStream)
michael@0 121
michael@0 122 already_AddRefed<FileStream>
michael@0 123 FileStream::Create(PersistenceType aPersistenceType, const nsACString& aGroup,
michael@0 124 const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags,
michael@0 125 int32_t aPerm, int32_t aBehaviorFlags)
michael@0 126 {
michael@0 127 nsRefPtr<FileStream> stream =
michael@0 128 new FileStream(aPersistenceType, aGroup, aOrigin);
michael@0 129 nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
michael@0 130 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 131 return stream.forget();
michael@0 132 }

mercurial