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
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef IndexedDatabaseInlines_h
8
#define IndexedDatabaseInlines_h
9
10
#ifndef mozilla_dom_indexeddatabase_h__
11
# error Must include IndexedDatabase.h first
12
#endif
13
14
#include "FileInfo.h"
15
#include "IDBMutableFile.h"
16
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
17
#include "mozilla/dom/DOMStringList.h"
18
#include "mozilla/dom/File.h"
19
20
namespace mozilla {
21
namespace dom {
22
namespace indexedDB {
23
24
inline StructuredCloneFile::StructuredCloneFile(FileType aType,
25
RefPtr<Blob> aBlob)
26
: mBlob{std::move(aBlob)}, mType{aType} {
27
MOZ_COUNT_CTOR(StructuredCloneFile);
28
}
29
30
inline StructuredCloneFile::StructuredCloneFile(
31
RefPtr<IDBMutableFile> aMutableFile)
32
: mMutableFile{std::move(aMutableFile)}, mType{eMutableFile} {
33
MOZ_COUNT_CTOR(StructuredCloneFile);
34
}
35
36
inline StructuredCloneFile::~StructuredCloneFile() {
37
MOZ_COUNT_DTOR(StructuredCloneFile);
38
}
39
40
inline bool StructuredCloneFile::operator==(
41
const StructuredCloneFile& aOther) const {
42
return this->mBlob == aOther.mBlob &&
43
this->mMutableFile == aOther.mMutableFile &&
44
this->mFileInfo == aOther.mFileInfo && this->mType == aOther.mType;
45
}
46
47
inline StructuredCloneReadInfo::StructuredCloneReadInfo(
48
JS::StructuredCloneScope aScope)
49
: mData(aScope), mDatabase(nullptr), mHasPreprocessInfo(false) {
50
MOZ_COUNT_CTOR(StructuredCloneReadInfo);
51
}
52
53
inline StructuredCloneReadInfo::StructuredCloneReadInfo()
54
: StructuredCloneReadInfo(
55
JS::StructuredCloneScope::DifferentProcessForIndexedDB) {}
56
57
inline StructuredCloneReadInfo::StructuredCloneReadInfo(
58
JSStructuredCloneData&& aData, nsTArray<StructuredCloneFile> aFiles,
59
IDBDatabase* aDatabase, bool aHasPreprocessInfo)
60
: mData{std::move(aData)},
61
mFiles{std::move(aFiles)},
62
mDatabase{aDatabase},
63
mHasPreprocessInfo{aHasPreprocessInfo} {
64
MOZ_COUNT_CTOR(StructuredCloneReadInfo);
65
}
66
67
#ifdef NS_BUILD_REFCNT_LOGGING
68
inline StructuredCloneReadInfo::StructuredCloneReadInfo(
69
StructuredCloneReadInfo&& aOther) noexcept
70
: mData(std::move(aOther.mData)) {
71
MOZ_ASSERT(&aOther != this);
72
MOZ_COUNT_CTOR(StructuredCloneReadInfo);
73
74
mFiles.Clear();
75
mFiles.SwapElements(aOther.mFiles);
76
mDatabase = aOther.mDatabase;
77
aOther.mDatabase = nullptr;
78
mHasPreprocessInfo = aOther.mHasPreprocessInfo;
79
aOther.mHasPreprocessInfo = false;
80
}
81
82
inline StructuredCloneReadInfo::~StructuredCloneReadInfo() {
83
MOZ_COUNT_DTOR(StructuredCloneReadInfo);
84
}
85
86
inline StructuredCloneReadInfo& StructuredCloneReadInfo::operator=(
87
StructuredCloneReadInfo&& aOther) noexcept {
88
MOZ_ASSERT(&aOther != this);
89
90
mData = std::move(aOther.mData);
91
mFiles.Clear();
92
mFiles.SwapElements(aOther.mFiles);
93
mDatabase = aOther.mDatabase;
94
aOther.mDatabase = nullptr;
95
mHasPreprocessInfo = aOther.mHasPreprocessInfo;
96
aOther.mHasPreprocessInfo = false;
97
return *this;
98
}
99
#endif
100
101
inline size_t StructuredCloneReadInfo::Size() const {
102
size_t size = mData.Size();
103
104
for (uint32_t i = 0, count = mFiles.Length(); i < count; ++i) {
105
// We don't want to calculate the size of files and so on, because are
106
// mainly file descriptors.
107
size += sizeof(uint64_t);
108
}
109
110
return size;
111
}
112
113
template <typename E, typename Map>
114
already_AddRefed<DOMStringList> CreateSortedDOMStringList(
115
const nsTArray<E>& aArray, const Map& aMap) {
116
auto list = MakeRefPtr<DOMStringList>();
117
118
if (!aArray.IsEmpty()) {
119
nsTArray<nsString>& mapped = list->StringArray();
120
mapped.SetCapacity(aArray.Length());
121
122
std::transform(aArray.cbegin(), aArray.cend(), MakeBackInserter(mapped),
123
aMap);
124
125
mapped.Sort();
126
}
127
128
return list.forget();
129
}
130
131
} // namespace indexedDB
132
} // namespace dom
133
} // namespace mozilla
134
135
#endif // IndexedDatabaseInlines_h