michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "File.h" michael@0: michael@0: #include "LockedFile.h" michael@0: michael@0: USING_FILE_NAMESPACE michael@0: using mozilla::dom::indexedDB::IndexedDatabaseManager; michael@0: michael@0: // Create slice michael@0: File::File(const File* aOther, uint64_t aStart, uint64_t aLength, michael@0: const nsAString& aContentType) michael@0: : nsDOMFileCC(aContentType, aOther->mStart + aStart, aLength), michael@0: mFile(aOther->mFile), mLockedFile(aOther->mLockedFile), michael@0: mWholeFile(false), mStoredFile(aOther->mStoredFile) michael@0: { michael@0: NS_ASSERTION(mFile, "Null file!"); michael@0: NS_ASSERTION(mLockedFile, "Null locked file!"); michael@0: michael@0: if (mStoredFile) { michael@0: FileInfo* fileInfo; michael@0: michael@0: if (IndexedDatabaseManager::IsClosed()) { michael@0: fileInfo = aOther->GetFileInfo(); michael@0: } michael@0: else { michael@0: MutexAutoLock lock(IndexedDatabaseManager::FileMutex()); michael@0: fileInfo = aOther->GetFileInfo(); michael@0: } michael@0: michael@0: mFileInfos.AppendElement(fileInfo); michael@0: } michael@0: } michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC, michael@0: mLockedFile) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File) michael@0: NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC) michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(File, nsDOMFileCC) michael@0: NS_IMPL_RELEASE_INHERITED(File, nsDOMFileCC) michael@0: michael@0: NS_IMETHODIMP michael@0: File::GetInternalStream(nsIInputStream **aStream) michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: michael@0: nsresult rv = mLockedFile->OpenInputStream(mWholeFile, mStart, mLength, michael@0: aStream); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: already_AddRefed michael@0: File::CreateSlice(uint64_t aStart, uint64_t aLength, michael@0: const nsAString& aContentType) michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: michael@0: nsCOMPtr t = michael@0: new File(this, aStart, aLength, aContentType); michael@0: return t.forget(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: File::GetMozFullPathInternal(nsAString &aFilename) michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: NS_ASSERTION(mIsFile, "Should only be called on files"); michael@0: michael@0: return mFile->GetPath(aFilename); michael@0: }