gecko-dev/dom/indexedDB/FileSnapshot.cpp
Ryan VanderMeulen cd3e8a6f73 Backed out 7 changesets (bug 1047483, bug 1079301, bug 1079335) for webplatform test failures.
Backed out changeset 7d06b68c44d0 (bug 1079335)
Backed out changeset 92030169528e (bug 1079301)
Backed out changeset c09d7f95554a (bug 1047483)
Backed out changeset c199f1057d7e (bug 1047483)
Backed out changeset 18830d07884c (bug 1047483)
Backed out changeset e087289ccfbb (bug 1047483)
Backed out changeset 6238ff5d3ed0 (bug 1047483)

CLOSED TREE

--HG--
rename : content/base/public/File.h => content/base/public/nsDOMFile.h
rename : content/base/src/MultipartFileImpl.cpp => content/base/src/nsDOMBlobBuilder.cpp
rename : content/base/src/MultipartFileImpl.h => content/base/src/nsDOMBlobBuilder.h
rename : content/base/src/File.cpp => content/base/src/nsDOMFile.cpp
2014-10-07 13:16:11 -04:00

180 lines
3.9 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FileSnapshot.h"
#include "IDBFileHandle.h"
#include "MainThreadUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/MetadataHelper.h"
#ifdef DEBUG
#include "nsXULAppAPI.h"
#endif
namespace mozilla {
namespace dom {
namespace indexedDB {
// Create as a stored file
FileImplSnapshot::FileImplSnapshot(const nsAString& aName,
const nsAString& aContentType,
MetadataParameters* aMetadataParams,
nsIFile* aFile,
IDBFileHandle* aFileHandle,
FileInfo* aFileInfo)
: DOMFileImplBase(aName,
aContentType,
aMetadataParams->Size(),
aMetadataParams->LastModified())
, mFile(aFile)
, mFileHandle(aFileHandle)
, mWholeFile(true)
{
AssertSanity();
MOZ_ASSERT(aMetadataParams);
MOZ_ASSERT(aMetadataParams->Size() != UINT64_MAX);
MOZ_ASSERT(aMetadataParams->LastModified() != INT64_MAX);
MOZ_ASSERT(aFile);
MOZ_ASSERT(aFileHandle);
MOZ_ASSERT(aFileInfo);
mFileInfos.AppendElement(aFileInfo);
}
// Create slice
FileImplSnapshot::FileImplSnapshot(const FileImplSnapshot* aOther,
uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, aOther->mStart + aStart, aLength)
, mFile(aOther->mFile)
, mFileHandle(aOther->mFileHandle)
, mWholeFile(false)
{
AssertSanity();
MOZ_ASSERT(aOther);
FileInfo* fileInfo;
if (IndexedDatabaseManager::IsClosed()) {
fileInfo = aOther->GetFileInfo();
} else {
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
fileInfo = aOther->GetFileInfo();
}
mFileInfos.AppendElement(fileInfo);
}
FileImplSnapshot::~FileImplSnapshot()
{
}
#ifdef DEBUG
// static
void
FileImplSnapshot::AssertSanity()
{
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
MOZ_ASSERT(NS_IsMainThread());
}
#endif // DEBUG
NS_IMPL_ISUPPORTS_INHERITED0(FileImplSnapshot, DOMFileImpl)
void
FileImplSnapshot::Unlink()
{
AssertSanity();
FileImplSnapshot* tmp = this;
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFileHandle);
}
void
FileImplSnapshot::Traverse(nsCycleCollectionTraversalCallback &cb)
{
AssertSanity();
FileImplSnapshot* tmp = this;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFileHandle);
}
bool
FileImplSnapshot::IsCCed() const
{
AssertSanity();
return true;
}
nsresult
FileImplSnapshot::GetInternalStream(nsIInputStream** aStream)
{
AssertSanity();
nsresult rv = mFileHandle->OpenInputStream(mWholeFile, mStart, mLength,
aStream);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
already_AddRefed<DOMFileImpl>
FileImplSnapshot::CreateSlice(uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType)
{
AssertSanity();
nsRefPtr<DOMFileImpl> impl =
new FileImplSnapshot(this, aStart, aLength, aContentType);
return impl.forget();
}
nsresult
FileImplSnapshot::GetMozFullPathInternal(nsAString& aFilename)
{
AssertSanity();
MOZ_ASSERT(mIsFile);
return mFile->GetPath(aFilename);
}
bool
FileImplSnapshot::IsStoredFile() const
{
AssertSanity();
return true;
}
bool
FileImplSnapshot::IsWholeFile() const
{
AssertSanity();
return mWholeFile;
}
bool
FileImplSnapshot::IsSnapshot() const
{
AssertSanity();
return true;
}
} // namespace indexedDB
} // namespace dom
} // namespace mozilla