2012-06-03 20:33:52 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_file_lockedfile_h__
|
|
|
|
#define mozilla_dom_file_lockedfile_h__
|
|
|
|
|
2013-06-05 20:15:48 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-06-03 20:33:52 +04:00
|
|
|
#include "FileCommon.h"
|
2013-06-12 11:00:06 +04:00
|
|
|
#include "mozilla/dom/FileModeBinding.h"
|
2012-06-03 20:33:52 +04:00
|
|
|
#include "nsIDOMLockedFile.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
|
|
|
|
#include "nsDOMEventTargetHelper.h"
|
|
|
|
|
|
|
|
class nsIInputStream;
|
|
|
|
|
|
|
|
BEGIN_FILE_NAMESPACE
|
|
|
|
|
2014-02-09 12:04:37 +04:00
|
|
|
class DOMFileRequest;
|
2012-06-03 20:33:52 +04:00
|
|
|
class FileHandle;
|
|
|
|
class FileRequest;
|
|
|
|
class MetadataHelper;
|
|
|
|
|
|
|
|
class LockedFile : public nsDOMEventTargetHelper,
|
|
|
|
public nsIDOMLockedFile,
|
|
|
|
public nsIRunnable
|
|
|
|
{
|
|
|
|
friend class FinishHelper;
|
|
|
|
friend class FileService;
|
|
|
|
friend class FileHelper;
|
|
|
|
friend class MetadataHelper;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIDOMLOCKEDFILE
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LockedFile, nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
enum RequestMode
|
|
|
|
{
|
|
|
|
NORMAL = 0, // Sequential
|
|
|
|
PARALLEL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ReadyState
|
|
|
|
{
|
|
|
|
INITIAL = 0,
|
|
|
|
LOADING,
|
|
|
|
FINISHING,
|
|
|
|
DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
static already_AddRefed<LockedFile>
|
|
|
|
Create(FileHandle* aFileHandle,
|
2013-06-12 11:00:06 +04:00
|
|
|
FileMode aMode,
|
2012-06-03 20:33:52 +04:00
|
|
|
RequestMode aRequestMode = NORMAL);
|
|
|
|
|
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult
|
2013-06-05 20:15:48 +04:00
|
|
|
PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateParallelStream(nsISupports** aStream);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetOrCreateStream(nsISupports** aStream);
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsOpen() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsAborted() const
|
|
|
|
{
|
|
|
|
return mAborted;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileHandle*
|
|
|
|
Handle() const
|
|
|
|
{
|
|
|
|
return mFileHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
OpenInputStream(bool aWholeFile, uint64_t aStart, uint64_t aLength,
|
2012-06-03 20:33:52 +04:00
|
|
|
nsIInputStream** aResult);
|
|
|
|
|
|
|
|
private:
|
|
|
|
LockedFile();
|
|
|
|
~LockedFile();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnRequestFinished();
|
|
|
|
|
2014-02-09 12:04:37 +04:00
|
|
|
inline already_AddRefed<DOMFileRequest>
|
2012-06-03 20:33:52 +04:00
|
|
|
GenerateFileRequest();
|
|
|
|
|
|
|
|
nsresult
|
2014-01-23 23:49:40 +04:00
|
|
|
WriteOrAppend(JS::Handle<JS::Value> aValue, JSContext* aCx,
|
2013-03-17 12:51:36 +04:00
|
|
|
nsISupports** _retval, bool aAppend);
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
Finish();
|
|
|
|
|
|
|
|
nsRefPtr<FileHandle> mFileHandle;
|
|
|
|
ReadyState mReadyState;
|
2013-06-12 11:00:06 +04:00
|
|
|
FileMode mMode;
|
2012-06-03 20:33:52 +04:00
|
|
|
RequestMode mRequestMode;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mLocation;
|
|
|
|
uint32_t mPendingRequests;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
nsTArray<nsCOMPtr<nsISupports> > mParallelStreams;
|
|
|
|
nsCOMPtr<nsISupports> mStream;
|
|
|
|
|
|
|
|
bool mAborted;
|
|
|
|
bool mCreating;
|
|
|
|
};
|
|
|
|
|
2012-06-15 06:31:55 +04:00
|
|
|
class FinishHelper MOZ_FINAL : public nsIRunnable
|
2012-06-03 20:33:52 +04:00
|
|
|
{
|
|
|
|
friend class LockedFile;
|
|
|
|
|
|
|
|
public:
|
2013-07-19 06:21:20 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
private:
|
|
|
|
FinishHelper(LockedFile* aLockedFile);
|
|
|
|
~FinishHelper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsRefPtr<LockedFile> mLockedFile;
|
|
|
|
nsTArray<nsCOMPtr<nsISupports> > mParallelStreams;
|
|
|
|
nsCOMPtr<nsISupports> mStream;
|
|
|
|
|
|
|
|
bool mAborted;
|
|
|
|
};
|
|
|
|
|
|
|
|
END_FILE_NAMESPACE
|
|
|
|
|
|
|
|
#endif // mozilla_dom_file_lockedfile_h__
|