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/. */
7 #ifndef DOM_INDEXEDDB_DATABASEFILEMANAGERIMPL_H_
8 #define DOM_INDEXEDDB_DATABASEFILEMANAGERIMPL_H_
10 #include "DatabaseFileManager.h"
13 #include "ActorsParentCommon.h"
16 #include "mozilla/dom/quota/Assertions.h"
17 #include "mozilla/dom/quota/QuotaCommon.h"
21 namespace mozilla::dom::indexedDB
{
23 template <typename KnownDirEntryOp
, typename UnknownDirEntryOp
>
24 Result
<Ok
, nsresult
> DatabaseFileManager::TraverseFiles(
25 nsIFile
& aDirectory
, KnownDirEntryOp
&& aKnownDirEntryOp
,
26 UnknownDirEntryOp
&& aUnknownDirEntryOp
) {
27 quota::AssertIsOnIOThread();
29 QM_TRY_INSPECT(const bool& exists
,
30 MOZ_TO_RESULT_INVOKE_MEMBER(aDirectory
, Exists
));
36 QM_TRY(quota::CollectEachFile(
38 [&aKnownDirEntryOp
, &aUnknownDirEntryOp
](
39 const nsCOMPtr
<nsIFile
>& file
) -> Result
<Ok
, nsresult
> {
40 QM_TRY_INSPECT(const auto& dirEntryKind
, quota::GetDirEntryKind(*file
));
42 switch (dirEntryKind
) {
43 case quota::nsIFileKind::ExistsAsDirectory
: {
46 MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString
, file
, GetLeafName
));
48 if (leafName
.Equals(kJournalDirectoryName
)) {
49 QM_TRY(std::forward
<KnownDirEntryOp
>(aKnownDirEntryOp
)(
50 *file
, /* isDirectory */ true));
55 Unused
<< WARN_IF_FILE_IS_UNKNOWN(*file
);
57 QM_TRY(std::forward
<UnknownDirEntryOp
>(aUnknownDirEntryOp
)(
58 *file
, /* isDirectory */ true));
63 case quota::nsIFileKind::ExistsAsFile
: {
66 MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString
, file
, GetLeafName
));
69 leafName
.ToInteger64(&rv
);
70 if (NS_SUCCEEDED(rv
)) {
71 QM_TRY(std::forward
<KnownDirEntryOp
>(aKnownDirEntryOp
)(
72 *file
, /* isDirectory */ false));
77 Unused
<< WARN_IF_FILE_IS_UNKNOWN(*file
);
79 QM_TRY(std::forward
<UnknownDirEntryOp
>(aUnknownDirEntryOp
)(
80 *file
, /* isDirectory */ false));
85 case quota::nsIFileKind::DoesNotExist
:
86 // Ignore files that got removed externally while iterating.
96 } // namespace mozilla::dom::indexedDB
98 #endif // DOM_INDEXEDDB_DATABASEFILEMANAGERIMPL_H_