2012-06-03 16:33:52 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-06-03 16:33:52 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#ifndef mozilla_dom_idbmutablefile_h__
|
|
|
|
#define mozilla_dom_idbmutablefile_h__
|
2012-06-03 16:33:52 +00:00
|
|
|
|
2014-07-17 16:40:54 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2014-05-07 14:33:02 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-09-17 23:36:01 +00:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/FileModeBinding.h"
|
2014-05-07 14:33:02 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2015-09-09 11:15:05 +00:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsString.h"
|
2021-03-23 10:36:33 +00:00
|
|
|
#include "nsTHashSet.h"
|
2012-06-03 16:33:52 +00:00
|
|
|
|
2014-07-17 16:40:54 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class DOMRequest;
|
2015-05-18 13:52:26 +00:00
|
|
|
class File;
|
2016-02-16 21:46:08 +00:00
|
|
|
class IDBDatabase;
|
|
|
|
class IDBFileHandle;
|
2014-07-17 16:40:54 +00:00
|
|
|
|
|
|
|
namespace indexedDB {
|
2015-09-09 11:15:05 +00:00
|
|
|
class BackgroundMutableFileChild;
|
2016-02-16 21:46:08 +00:00
|
|
|
}
|
2013-07-31 15:48:46 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class IDBMutableFile final : public DOMEventTargetHelper {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IDBDatabase> mDatabase;
|
2015-09-09 11:15:05 +00:00
|
|
|
|
2017-06-07 10:36:42 +00:00
|
|
|
indexedDB::BackgroundMutableFileChild* mBackgroundActor;
|
|
|
|
|
2021-03-23 10:36:33 +00:00
|
|
|
nsTHashSet<IDBFileHandle*> mFileHandles;
|
2014-05-07 14:33:02 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsString mName;
|
|
|
|
nsString mType;
|
|
|
|
|
|
|
|
Atomic<bool> mInvalidated;
|
|
|
|
|
|
|
|
public:
|
2015-09-09 11:15:05 +00:00
|
|
|
IDBMutableFile(IDBDatabase* aDatabase,
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundMutableFileChild* aActor,
|
2015-09-09 11:15:05 +00:00
|
|
|
const nsAString& aName, const nsAString& aType);
|
2014-02-24 20:56:13 +00:00
|
|
|
|
2017-06-07 10:36:42 +00:00
|
|
|
void AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
indexedDB::BackgroundMutableFileChild* GetBackgroundActor() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mBackgroundActor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearBackgroundActor() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mBackgroundActor = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsString& Name() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsString& Type() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
void SetLazyData(const nsAString& aName, const nsAString& aType) {
|
|
|
|
mName = aName;
|
|
|
|
mType = aType;
|
2014-07-17 16:40:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
int64_t GetFileId() const;
|
2012-06-03 16:33:52 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void Invalidate();
|
|
|
|
|
2017-06-07 10:36:42 +00:00
|
|
|
bool IsInvalidated() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mInvalidated;
|
|
|
|
}
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
void RegisterFileHandle(IDBFileHandle* aFileHandle);
|
2014-05-07 14:33:02 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
void UnregisterFileHandle(IDBFileHandle* aFileHandle);
|
2012-06-03 16:33:52 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
void AbortFileHandles();
|
2012-06-03 16:33:52 +00:00
|
|
|
|
2014-02-24 20:56:13 +00:00
|
|
|
// WebIDL
|
2014-07-17 16:40:54 +00:00
|
|
|
void GetName(nsString& aName) const { aName = mName; }
|
|
|
|
|
|
|
|
void GetType(nsString& aType) const { aType = mType; }
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBDatabase* Database() const;
|
2013-07-01 07:02:37 +00:00
|
|
|
|
2020-04-23 01:49:16 +00:00
|
|
|
[[nodiscard]] RefPtr<IDBFileHandle> Open(FileMode aMode, ErrorResult& aError);
|
2014-07-17 16:40:54 +00:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBMutableFile, DOMEventTargetHelper)
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2015-09-09 11:15:05 +00:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
private:
|
2014-09-26 23:21:57 +00:00
|
|
|
~IDBMutableFile();
|
2012-06-03 16:33:52 +00:00
|
|
|
};
|
|
|
|
|
2014-07-17 16:40:54 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-06-03 16:33:52 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#endif // mozilla_dom_idbmutablefile_h__
|