summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/native_file_system/native_file_system_directory_iterator.h
blob: 34026cd8a19ff4cacc29d4d3248fd5734c46a272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_DIRECTORY_ITERATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_DIRECTORY_ITERATOR_H_

#include "base/files/file.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/blink/public/mojom/native_file_system/native_file_system_directory_handle.mojom-blink.h"
#include "third_party/blink/public/mojom/native_file_system/native_file_system_error.mojom-blink.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"

namespace blink {
class NativeFileSystemDirectoryHandle;
class NativeFileSystemHandle;
class ScriptPromise;
class ScriptPromiseResolver;
class ScriptState;

class NativeFileSystemDirectoryIterator final
    : public ScriptWrappable,
      public ContextLifecycleObserver,
      public mojom::blink::NativeFileSystemDirectoryEntriesListener {
  DEFINE_WRAPPERTYPEINFO();
  USING_GARBAGE_COLLECTED_MIXIN(NativeFileSystemDirectoryIterator);
  USING_PRE_FINALIZER(NativeFileSystemDirectoryIterator, Dispose);

 public:
  NativeFileSystemDirectoryIterator(NativeFileSystemDirectoryHandle* directory,
                                    ExecutionContext* execution_context);

  ScriptPromise next(ScriptState*);

  void Trace(Visitor*) override;

 private:
  void DidReadDirectory(mojom::blink::NativeFileSystemErrorPtr result,
                        Vector<mojom::blink::NativeFileSystemEntryPtr> entries,
                        bool has_more_entries) override;
  void Dispose();

  mojom::blink::NativeFileSystemErrorPtr error_;
  bool waiting_for_more_entries_ = true;
  HeapDeque<Member<NativeFileSystemHandle>> entries_;
  Member<ScriptPromiseResolver> pending_next_;
  Member<NativeFileSystemDirectoryHandle> directory_;
  mojo::Receiver<mojom::blink::NativeFileSystemDirectoryEntriesListener>
      receiver_{this};
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_DIRECTORY_ITERATOR_H_