Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/indexedDB/IDBMutableFile.h
Line
Count
Source (jump to first uncovered line)
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
class nsPIDOMWindowInner;
21
22
namespace mozilla {
23
24
class ErrorResult;
25
26
namespace dom {
27
28
class DOMRequest;
29
class File;
30
class IDBDatabase;
31
class IDBFileHandle;
32
33
namespace indexedDB {
34
class BackgroundMutableFileChild;
35
}
36
37
class IDBMutableFile final
38
  : public DOMEventTargetHelper
39
{
40
  RefPtr<IDBDatabase> mDatabase;
41
42
  indexedDB::BackgroundMutableFileChild* mBackgroundActor;
43
44
  nsTHashtable<nsPtrHashKey<IDBFileHandle>> mFileHandles;
45
46
  nsString mName;
47
  nsString mType;
48
49
  Atomic<bool> mInvalidated;
50
51
public:
52
  IDBMutableFile(IDBDatabase* aDatabase,
53
                 indexedDB::BackgroundMutableFileChild* aActor,
54
                 const nsAString& aName,
55
                 const nsAString& aType);
56
57
  void
58
  AssertIsOnOwningThread() const
59
#ifdef DEBUG
60
  ;
61
#else
62
0
  { }
63
#endif
64
65
  indexedDB::BackgroundMutableFileChild*
66
  GetBackgroundActor() const
67
0
  {
68
0
    AssertIsOnOwningThread();
69
0
70
0
    return mBackgroundActor;
71
0
  }
72
73
  void
74
  ClearBackgroundActor()
75
0
  {
76
0
    AssertIsOnOwningThread();
77
0
78
0
    mBackgroundActor = nullptr;
79
0
  }
80
81
  const nsString&
82
  Name() const
83
0
  {
84
0
    AssertIsOnOwningThread();
85
0
86
0
    return mName;
87
0
  }
88
89
  const nsString&
90
  Type() const
91
0
  {
92
0
    AssertIsOnOwningThread();
93
0
94
0
    return mType;
95
0
  }
96
97
  void
98
  SetLazyData(const nsAString& aName,
99
              const nsAString& aType)
100
0
  {
101
0
    mName = aName;
102
0
    mType = aType;
103
0
  }
104
105
  int64_t
106
  GetFileId() const;
107
108
  void
109
  Invalidate();
110
111
  bool
112
  IsInvalidated() const
113
0
  {
114
0
    AssertIsOnOwningThread();
115
0
116
0
    return mInvalidated;
117
0
  }
118
119
  void
120
  RegisterFileHandle(IDBFileHandle* aFileHandle);
121
122
  void
123
  UnregisterFileHandle(IDBFileHandle* aFileHandle);
124
125
  void
126
  AbortFileHandles();
127
128
  // WebIDL
129
  nsPIDOMWindowInner*
130
  GetParentObject() const
131
  {
132
    return GetOwner();
133
  }
134
135
  void
136
  GetName(nsString& aName) const
137
  {
138
    aName = mName;
139
  }
140
141
  void
142
  GetType(nsString& aType) const
143
  {
144
    aType = mType;
145
  }
146
147
  IDBDatabase*
148
  Database() const;
149
150
  already_AddRefed<IDBFileHandle>
151
  Open(FileMode aMode, ErrorResult& aError);
152
153
  already_AddRefed<DOMRequest>
154
  GetFile(ErrorResult& aError);
155
156
  IMPL_EVENT_HANDLER(abort)
157
  IMPL_EVENT_HANDLER(error)
158
159
  NS_DECL_ISUPPORTS_INHERITED
160
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBMutableFile, DOMEventTargetHelper)
161
162
  // nsWrapperCache
163
  virtual JSObject*
164
  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
165
166
private:
167
  ~IDBMutableFile();
168
};
169
170
} // namespace dom
171
} // namespace mozilla
172
173
#endif // mozilla_dom_idbmutablefile_h__