Source code

Revision control

Other Tools

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 file,
5
* You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_idbmutablefile_h__
8
#define mozilla_dom_idbmutablefile_h__
9
10
#include "js/TypeDecls.h"
11
#include "mozilla/Atomics.h"
12
#include "mozilla/Attributes.h"
13
#include "mozilla/DOMEventTargetHelper.h"
14
#include "mozilla/dom/FileModeBinding.h"
15
#include "nsCycleCollectionParticipant.h"
16
#include "nsHashKeys.h"
17
#include "nsString.h"
18
#include "nsTHashtable.h"
19
20
namespace mozilla {
21
22
class ErrorResult;
23
24
namespace dom {
25
26
class DOMRequest;
27
class File;
28
class IDBDatabase;
29
class IDBFileHandle;
30
31
namespace indexedDB {
32
class BackgroundMutableFileChild;
33
}
34
35
class IDBMutableFile final : public DOMEventTargetHelper {
36
RefPtr<IDBDatabase> mDatabase;
37
38
indexedDB::BackgroundMutableFileChild* mBackgroundActor;
39
40
nsTHashtable<nsPtrHashKey<IDBFileHandle>> mFileHandles;
41
42
nsString mName;
43
nsString mType;
44
45
Atomic<bool> mInvalidated;
46
47
public:
48
IDBMutableFile(IDBDatabase* aDatabase,
49
indexedDB::BackgroundMutableFileChild* aActor,
50
const nsAString& aName, const nsAString& aType);
51
52
void AssertIsOnOwningThread() const
53
#ifdef DEBUG
54
;
55
#else
56
{
57
}
58
#endif
59
60
indexedDB::BackgroundMutableFileChild* GetBackgroundActor() const {
61
AssertIsOnOwningThread();
62
63
return mBackgroundActor;
64
}
65
66
void ClearBackgroundActor() {
67
AssertIsOnOwningThread();
68
69
mBackgroundActor = nullptr;
70
}
71
72
const nsString& Name() const {
73
AssertIsOnOwningThread();
74
75
return mName;
76
}
77
78
const nsString& Type() const {
79
AssertIsOnOwningThread();
80
81
return mType;
82
}
83
84
void SetLazyData(const nsAString& aName, const nsAString& aType) {
85
mName = aName;
86
mType = aType;
87
}
88
89
int64_t GetFileId() const;
90
91
void Invalidate();
92
93
bool IsInvalidated() const {
94
AssertIsOnOwningThread();
95
96
return mInvalidated;
97
}
98
99
void RegisterFileHandle(IDBFileHandle* aFileHandle);
100
101
void UnregisterFileHandle(IDBFileHandle* aFileHandle);
102
103
void AbortFileHandles();
104
105
// WebIDL
106
void GetName(nsString& aName) const { aName = mName; }
107
108
void GetType(nsString& aType) const { aType = mType; }
109
110
IDBDatabase* Database() const;
111
112
already_AddRefed<IDBFileHandle> Open(FileMode aMode, ErrorResult& aError);
113
114
already_AddRefed<DOMRequest> GetFile(ErrorResult& aError);
115
116
IMPL_EVENT_HANDLER(abort)
117
IMPL_EVENT_HANDLER(error)
118
119
NS_DECL_ISUPPORTS_INHERITED
120
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBMutableFile, DOMEventTargetHelper)
121
122
// nsWrapperCache
123
virtual JSObject* WrapObject(JSContext* aCx,
124
JS::Handle<JSObject*> aGivenProto) override;
125
126
private:
127
~IDBMutableFile();
128
};
129
130
} // namespace dom
131
} // namespace mozilla
132
133
#endif // mozilla_dom_idbmutablefile_h__