/src/mozilla-central/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp
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 | | #include "FileSystemRootDirectoryReader.h" |
8 | | #include "CallbackRunnables.h" |
9 | | #include "nsIGlobalObject.h" |
10 | | #include "mozilla/dom/FileSystemUtils.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | namespace { |
16 | | |
17 | | class EntriesCallbackRunnable final : public Runnable |
18 | | { |
19 | | public: |
20 | | EntriesCallbackRunnable(FileSystemEntriesCallback* aCallback, |
21 | | const Sequence<RefPtr<FileSystemEntry>>& aEntries) |
22 | | : Runnable("EntriesCallbackRunnable") |
23 | | , mCallback(aCallback) |
24 | | , mEntries(aEntries) |
25 | 0 | { |
26 | 0 | MOZ_ASSERT(aCallback); |
27 | 0 | } |
28 | | |
29 | | NS_IMETHOD |
30 | | Run() override |
31 | 0 | { |
32 | 0 | Sequence<OwningNonNull<FileSystemEntry>> entries; |
33 | 0 | for (uint32_t i = 0; i < mEntries.Length(); ++i) { |
34 | 0 | if (!entries.AppendElement(mEntries[i].forget(), fallible)) { |
35 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
36 | 0 | } |
37 | 0 | } |
38 | 0 |
|
39 | 0 | mCallback->HandleEvent(entries); |
40 | 0 | return NS_OK; |
41 | 0 | } |
42 | | |
43 | | private: |
44 | | RefPtr<FileSystemEntriesCallback> mCallback; |
45 | | Sequence<RefPtr<FileSystemEntry>> mEntries; |
46 | | }; |
47 | | |
48 | | } // anonymous namespace |
49 | | |
50 | | NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemRootDirectoryReader, |
51 | | FileSystemDirectoryReader, mEntries) |
52 | | |
53 | | NS_IMPL_ADDREF_INHERITED(FileSystemRootDirectoryReader, |
54 | | FileSystemDirectoryReader) |
55 | | NS_IMPL_RELEASE_INHERITED(FileSystemRootDirectoryReader, |
56 | | FileSystemDirectoryReader) |
57 | | |
58 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemRootDirectoryReader) |
59 | 0 | NS_INTERFACE_MAP_END_INHERITING(FileSystemDirectoryReader) |
60 | | |
61 | | FileSystemRootDirectoryReader::FileSystemRootDirectoryReader(FileSystemDirectoryEntry* aParentEntry, |
62 | | FileSystem* aFileSystem, |
63 | | const Sequence<RefPtr<FileSystemEntry>>& aEntries) |
64 | | : FileSystemDirectoryReader(aParentEntry, aFileSystem, nullptr) |
65 | | , mEntries(aEntries) |
66 | | , mAlreadyRead(false) |
67 | 0 | { |
68 | 0 | MOZ_ASSERT(aParentEntry); |
69 | 0 | MOZ_ASSERT(aFileSystem); |
70 | 0 | } |
71 | | |
72 | | FileSystemRootDirectoryReader::~FileSystemRootDirectoryReader() |
73 | 0 | {} |
74 | | |
75 | | void |
76 | | FileSystemRootDirectoryReader::ReadEntries(FileSystemEntriesCallback& aSuccessCallback, |
77 | | const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback, |
78 | | ErrorResult& aRv) |
79 | 0 | { |
80 | 0 | if (mAlreadyRead) { |
81 | 0 | RefPtr<EmptyEntriesCallbackRunnable> runnable = |
82 | 0 | new EmptyEntriesCallbackRunnable(&aSuccessCallback); |
83 | 0 |
|
84 | 0 | aRv = FileSystemUtils::DispatchRunnable(GetParentObject(), runnable.forget()); |
85 | 0 | return; |
86 | 0 | } |
87 | 0 | |
88 | 0 | // This object can be used only once. |
89 | 0 | mAlreadyRead = true; |
90 | 0 |
|
91 | 0 | RefPtr<EntriesCallbackRunnable> runnable = |
92 | 0 | new EntriesCallbackRunnable(&aSuccessCallback, mEntries); |
93 | 0 |
|
94 | 0 | aRv = FileSystemUtils::DispatchRunnable(GetParentObject(), runnable.forget()); |
95 | 0 | } |
96 | | |
97 | | } // dom namespace |
98 | | } // mozilla namespace |