LCOV - code coverage report
Current view: top level - dom/quota - FileStreams.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 51 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : USING_QUOTA_NAMESPACE
      13             : 
      14             : template <class FileStreamBase>
      15             : NS_IMETHODIMP
      16           0 : FileQuotaStream<FileStreamBase>::SetEOF()
      17             : {
      18           0 :   nsresult rv = FileStreamBase::SetEOF();
      19           0 :   NS_ENSURE_SUCCESS(rv, rv);
      20             : 
      21           0 :   if (mQuotaObject) {
      22             :     int64_t offset;
      23           0 :     nsresult rv = FileStreamBase::Tell(&offset);
      24           0 :     NS_ENSURE_SUCCESS(rv, rv);
      25             : 
      26           0 :     mQuotaObject->MaybeUpdateSize(offset, /* aTruncate */ true);
      27             :   }
      28             : 
      29           0 :   return NS_OK;
      30             : }
      31             : 
      32             : template <class FileStreamBase>
      33             : NS_IMETHODIMP
      34           0 : FileQuotaStream<FileStreamBase>::Close()
      35             : {
      36           0 :   nsresult rv = FileStreamBase::Close();
      37           0 :   NS_ENSURE_SUCCESS(rv, rv);
      38             : 
      39           0 :   mQuotaObject = nullptr;
      40             : 
      41           0 :   return NS_OK;
      42             : }
      43             : 
      44             : template <class FileStreamBase>
      45             : nsresult
      46           0 : FileQuotaStream<FileStreamBase>::DoOpen()
      47             : {
      48           0 :   QuotaManager* quotaManager = QuotaManager::Get();
      49           0 :   NS_ASSERTION(quotaManager, "Shouldn't be null!");
      50             : 
      51           0 :   NS_ASSERTION(!mQuotaObject, "Creating quota object more than once?");
      52           0 :   mQuotaObject = quotaManager->GetQuotaObject(mPersistenceType, mGroup, mOrigin,
      53             :     FileStreamBase::mOpenParams.localFile);
      54             : 
      55           0 :   nsresult rv = FileStreamBase::DoOpen();
      56           0 :   NS_ENSURE_SUCCESS(rv, rv);
      57             : 
      58           0 :   if (mQuotaObject && (FileStreamBase::mOpenParams.ioFlags & PR_TRUNCATE)) {
      59           0 :     mQuotaObject->MaybeUpdateSize(0, /* aTruncate */ true);
      60             :   }
      61             : 
      62           0 :   return NS_OK;
      63             : }
      64             : 
      65             : template <class FileStreamBase>
      66             : NS_IMETHODIMP
      67           0 : FileQuotaStreamWithWrite<FileStreamBase>::Write(const char* aBuf,
      68             :                                                 uint32_t aCount,
      69             :                                                 uint32_t* _retval)
      70             : {
      71             :   nsresult rv;
      72             : 
      73           0 :   if (FileQuotaStreamWithWrite::mQuotaObject) {
      74             :     int64_t offset;
      75           0 :     rv = FileStreamBase::Tell(&offset);
      76           0 :     NS_ENSURE_SUCCESS(rv, rv);
      77             : 
      78           0 :     MOZ_ASSERT(INT64_MAX - offset >= int64_t(aCount));
      79             : 
      80           0 :     if (!FileQuotaStreamWithWrite::
      81             :          mQuotaObject->MaybeUpdateSize(offset + int64_t(aCount),
      82             :                                        /* aTruncate */ false)) {
      83           0 :       return NS_ERROR_FILE_NO_DEVICE_SPACE;
      84             :     }
      85             :   }
      86             : 
      87           0 :   rv = FileStreamBase::Write(aBuf, aCount, _retval);
      88           0 :   NS_ENSURE_SUCCESS(rv, rv);
      89             : 
      90           0 :   return NS_OK;
      91             : }
      92             : 
      93           0 : NS_IMPL_ISUPPORTS_INHERITED0(FileInputStream, nsFileInputStream)
      94             : 
      95             : already_AddRefed<FileInputStream>
      96           0 : FileInputStream::Create(PersistenceType aPersistenceType,
      97             :                         const nsACString& aGroup, const nsACString& aOrigin,
      98             :                         nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
      99             :                         int32_t aBehaviorFlags)
     100             : {
     101             :   RefPtr<FileInputStream> stream =
     102           0 :     new FileInputStream(aPersistenceType, aGroup, aOrigin);
     103           0 :   nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
     104           0 :   NS_ENSURE_SUCCESS(rv, nullptr);
     105           0 :   return stream.forget();
     106             : }
     107             : 
     108           0 : NS_IMPL_ISUPPORTS_INHERITED0(FileOutputStream, nsFileOutputStream)
     109             : 
     110             : already_AddRefed<FileOutputStream>
     111           0 : FileOutputStream::Create(PersistenceType aPersistenceType,
     112             :                          const nsACString& aGroup, const nsACString& aOrigin,
     113             :                          nsIFile* aFile, int32_t aIOFlags, int32_t aPerm,
     114             :                          int32_t aBehaviorFlags)
     115             : {
     116             :   RefPtr<FileOutputStream> stream =
     117           0 :     new FileOutputStream(aPersistenceType, aGroup, aOrigin);
     118           0 :   nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
     119           0 :   NS_ENSURE_SUCCESS(rv, nullptr);
     120           0 :   return stream.forget();
     121             : }
     122             : 
     123           0 : NS_IMPL_ISUPPORTS_INHERITED0(FileStream, nsFileStream)
     124             : 
     125             : already_AddRefed<FileStream>
     126           0 : FileStream::Create(PersistenceType aPersistenceType, const nsACString& aGroup,
     127             :                    const nsACString& aOrigin, nsIFile* aFile, int32_t aIOFlags,
     128             :                    int32_t aPerm, int32_t aBehaviorFlags)
     129             : {
     130             :   RefPtr<FileStream> stream =
     131           0 :     new FileStream(aPersistenceType, aGroup, aOrigin);
     132           0 :   nsresult rv = stream->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
     133           0 :   NS_ENSURE_SUCCESS(rv, nullptr);
     134           0 :   return stream.forget();
     135             : }

Generated by: LCOV version 1.13