| Index: runtime/bin/directory.h
|
| diff --git a/runtime/bin/directory.h b/runtime/bin/directory.h
|
| index 7a1c5d13914e0f8f5daba773f975cb2c49f8d67f..09f479bf21e60ac9aa393e4dc0cec01e67828aa1 100644
|
| --- a/runtime/bin/directory.h
|
| +++ b/runtime/bin/directory.h
|
| @@ -7,6 +7,7 @@
|
|
|
| #include "bin/builtin.h"
|
| #include "bin/dartutils.h"
|
| +#include "bin/reference_counting.h"
|
| #include "bin/thread.h"
|
| #include "platform/globals.h"
|
|
|
| @@ -107,9 +108,7 @@ class DirectoryListing {
|
| }
|
|
|
| virtual ~DirectoryListing() {
|
| - while (!IsEmpty()) {
|
| - Pop();
|
| - }
|
| + PopAll();
|
| }
|
|
|
| virtual bool HandleDirectory(const char* dir_name) = 0;
|
| @@ -133,6 +132,12 @@ class DirectoryListing {
|
| return top_ == NULL;
|
| }
|
|
|
| + void PopAll() {
|
| + while (!IsEmpty()) {
|
| + Pop();
|
| + }
|
| + }
|
| +
|
| DirectoryListingEntry* top() const {
|
| return top_;
|
| }
|
| @@ -166,7 +171,8 @@ class DirectoryListing {
|
| };
|
|
|
|
|
| -class AsyncDirectoryListing : public DirectoryListing {
|
| +class AsyncDirectoryListing : public ReferenceCounted<AsyncDirectoryListing>,
|
| + public DirectoryListing {
|
| public:
|
| enum Response {
|
| kListFile = 0,
|
| @@ -179,9 +185,13 @@ class AsyncDirectoryListing : public DirectoryListing {
|
| AsyncDirectoryListing(const char* dir_name,
|
| bool recursive,
|
| bool follow_links)
|
| - : DirectoryListing(dir_name, recursive, follow_links) {}
|
| + : ReferenceCounted(),
|
| + DirectoryListing(dir_name, recursive, follow_links),
|
| + array_(NULL),
|
| + index_(0),
|
| + length_(0),
|
| + weak_handle_(NULL) {}
|
|
|
| - virtual ~AsyncDirectoryListing() {}
|
| virtual bool HandleDirectory(const char* dir_name);
|
| virtual bool HandleFile(const char* file_name);
|
| virtual bool HandleLink(const char* file_name);
|
| @@ -199,12 +209,32 @@ class AsyncDirectoryListing : public DirectoryListing {
|
| return index_;
|
| }
|
|
|
| + // Returns the weak persistent handle for the Dart wrapper.
|
| + Dart_WeakPersistentHandle WeakHandle() const { return weak_handle_; }
|
| +
|
| + // Set the weak persistent handle for the Dart wrapper.
|
| + void SetWeakHandle(Dart_WeakPersistentHandle handle) {
|
| + ASSERT(weak_handle_ == NULL);
|
| + weak_handle_ = handle;
|
| + }
|
| +
|
| + // Deletes the weak persistent handle for the Dart wrapper. Call
|
| + // when the listing is explicitly closed and the finalizer is no longer
|
| + // needed.
|
| + void DeleteWeakHandle(Dart_Isolate isolate) {
|
| + Dart_DeleteWeakPersistentHandle(isolate, weak_handle_);
|
| + weak_handle_ = NULL;
|
| + }
|
| +
|
| private:
|
| + virtual ~AsyncDirectoryListing() {}
|
| bool AddFileSystemEntityToResponse(Response response, const char* arg);
|
| CObjectArray* array_;
|
| intptr_t index_;
|
| intptr_t length_;
|
| + Dart_WeakPersistentHandle weak_handle_;
|
|
|
| + friend class ReferenceCounted<AsyncDirectoryListing>;
|
| DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncDirectoryListing);
|
| };
|
|
|
| @@ -238,6 +268,7 @@ class SyncDirectoryListing: public DirectoryListing {
|
| Dart_Handle file_type_;
|
| Dart_Handle link_type_;
|
|
|
| + DISALLOW_ALLOCATION()
|
| DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing);
|
| };
|
|
|
|
|