2016-06-07 01:55:17 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-08-18 10:18:51 +03:00
|
|
|
#include "FileSystemRootDirectoryReader.h"
|
2016-06-07 01:55:17 +03:00
|
|
|
#include "CallbackRunnables.h"
|
|
|
|
#include "nsIGlobalObject.h"
|
2017-04-05 10:47:34 +03:00
|
|
|
#include "mozilla/dom/FileSystemUtils.h"
|
2016-06-07 01:55:17 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class EntriesCallbackRunnable final : public Runnable
|
|
|
|
{
|
|
|
|
public:
|
2016-08-18 10:19:15 +03:00
|
|
|
EntriesCallbackRunnable(FileSystemEntriesCallback* aCallback,
|
2016-08-18 10:17:25 +03:00
|
|
|
const Sequence<RefPtr<FileSystemEntry>>& aEntries)
|
2017-04-05 10:47:09 +03:00
|
|
|
: Runnable("EntriesCallbackRunnable")
|
|
|
|
, mCallback(aCallback)
|
2016-06-07 01:55:17 +03:00
|
|
|
, mEntries(aEntries)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Run() override
|
|
|
|
{
|
2016-08-18 10:17:25 +03:00
|
|
|
Sequence<OwningNonNull<FileSystemEntry>> entries;
|
2016-06-07 01:55:17 +03:00
|
|
|
for (uint32_t i = 0; i < mEntries.Length(); ++i) {
|
|
|
|
if (!entries.AppendElement(mEntries[i].forget(), fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mCallback->HandleEvent(entries);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-08-18 10:19:15 +03:00
|
|
|
RefPtr<FileSystemEntriesCallback> mCallback;
|
2016-08-18 10:17:25 +03:00
|
|
|
Sequence<RefPtr<FileSystemEntry>> mEntries;
|
2016-06-07 01:55:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2016-08-18 10:18:51 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemRootDirectoryReader,
|
|
|
|
FileSystemDirectoryReader, mEntries)
|
2016-06-07 01:55:17 +03:00
|
|
|
|
2016-08-18 10:18:51 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(FileSystemRootDirectoryReader,
|
|
|
|
FileSystemDirectoryReader)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(FileSystemRootDirectoryReader,
|
|
|
|
FileSystemDirectoryReader)
|
2016-06-07 01:55:17 +03:00
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemRootDirectoryReader)
|
2016-08-18 10:18:51 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(FileSystemDirectoryReader)
|
2016-06-07 01:55:17 +03:00
|
|
|
|
2016-11-03 09:55:30 +03:00
|
|
|
FileSystemRootDirectoryReader::FileSystemRootDirectoryReader(FileSystemDirectoryEntry* aParentEntry,
|
2016-08-18 10:18:51 +03:00
|
|
|
FileSystem* aFileSystem,
|
|
|
|
const Sequence<RefPtr<FileSystemEntry>>& aEntries)
|
2016-11-03 09:55:30 +03:00
|
|
|
: FileSystemDirectoryReader(aParentEntry, aFileSystem, nullptr)
|
2016-06-07 01:55:17 +03:00
|
|
|
, mEntries(aEntries)
|
|
|
|
, mAlreadyRead(false)
|
|
|
|
{
|
2016-11-03 09:55:30 +03:00
|
|
|
MOZ_ASSERT(aParentEntry);
|
2016-06-07 01:55:17 +03:00
|
|
|
MOZ_ASSERT(aFileSystem);
|
|
|
|
}
|
|
|
|
|
2016-08-18 10:18:51 +03:00
|
|
|
FileSystemRootDirectoryReader::~FileSystemRootDirectoryReader()
|
2016-06-07 01:55:17 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
2016-08-18 10:19:15 +03:00
|
|
|
FileSystemRootDirectoryReader::ReadEntries(FileSystemEntriesCallback& aSuccessCallback,
|
2016-08-18 10:18:51 +03:00
|
|
|
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
|
|
|
|
ErrorResult& aRv)
|
2016-06-07 01:55:17 +03:00
|
|
|
{
|
|
|
|
if (mAlreadyRead) {
|
|
|
|
RefPtr<EmptyEntriesCallbackRunnable> runnable =
|
|
|
|
new EmptyEntriesCallbackRunnable(&aSuccessCallback);
|
2017-04-05 10:47:34 +03:00
|
|
|
|
|
|
|
aRv = FileSystemUtils::DispatchRunnable(GetParentObject(), runnable.forget());
|
2016-06-07 01:55:17 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This object can be used only once.
|
|
|
|
mAlreadyRead = true;
|
|
|
|
|
|
|
|
RefPtr<EntriesCallbackRunnable> runnable =
|
|
|
|
new EntriesCallbackRunnable(&aSuccessCallback, mEntries);
|
2017-04-05 10:47:34 +03:00
|
|
|
|
|
|
|
aRv = FileSystemUtils::DispatchRunnable(GetParentObject(), runnable.forget());
|
2016-06-07 01:55:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|