Index: net/base/directory_lister.h |
diff --git a/net/base/directory_lister.h b/net/base/directory_lister.h |
index b531880898b713390bbc8c6f217b2569208105a2..d565049e9c57dfbff13955e9115ef8282cd37a7a 100644 |
--- a/net/base/directory_lister.h |
+++ b/net/base/directory_lister.h |
@@ -6,46 +6,40 @@ |
#define NET_BASE_DIRECTORY_LISTER_H_ |
#pragma once |
-#include <vector> |
- |
-#include "base/cancellation_flag.h" |
+#include "base/basictypes.h" |
#include "base/file_path.h" |
#include "base/file_util.h" |
-#include "base/platform_thread.h" |
#include "base/ref_counted.h" |
-#include "base/task.h" |
- |
-class MessageLoop; |
+#include "base/worker_pool_job.h" |
namespace net { |
-// |
// This class provides an API for listing the contents of a directory on the |
// filesystem asynchronously. It spawns a background thread, and enumerates |
// the specified directory on that thread. It marshalls WIN32_FIND_DATA |
// structs over to the main application thread. The consumer of this class |
// is insulated from any of the multi-threading details. |
// |
-class DirectoryLister : public base::RefCountedThreadSafe<DirectoryLister>, |
- public PlatformThread::Delegate { |
+class DirectoryLister { |
public: |
// Represents one file found. |
- struct DirectoryListerData { |
+ struct Data { |
file_util::FileEnumerator::FindInfo info; |
FilePath path; |
}; |
// Implement this class to receive directory entries. |
- class DirectoryListerDelegate { |
+ class Delegate { |
public: |
// Called for each file found by the lister. |
- virtual void OnListFile(const DirectoryListerData& data) = 0; |
+ virtual void OnListFile(const Data& data) = 0; |
- // Called when the listing is complete. |
+ // Called when the listing is complete. May not be called if Cancel() is |
+ // called. |
virtual void OnListDone(int error) = 0; |
protected: |
- virtual ~DirectoryListerDelegate() {} |
+ virtual ~Delegate() {} |
}; |
// Sort options |
@@ -60,54 +54,27 @@ class DirectoryLister : public base::RefCountedThreadSafe<DirectoryLister>, |
FULL_PATH |
}; |
- DirectoryLister(const FilePath& dir, |
- DirectoryListerDelegate* delegate); |
+ DirectoryLister(const FilePath& dir, Delegate* delegate); |
DirectoryLister(const FilePath& dir, |
bool recursive, |
SORT_TYPE sort, |
- DirectoryListerDelegate* delegate); |
- |
+ Delegate* delegate); |
+ ~DirectoryLister(); |
// Call this method to start the directory enumeration thread. |
- bool Start(); |
+ void Start(); |
- // Call this method to asynchronously stop directory enumeration. The |
- // delegate will receive the OnListDone notification with an error code of |
- // net::ERR_ABORTED. |
+ // Only valid to call this after Start() is called, and before |
+ // Delegate::OnListDone() is invoked. |
void Cancel(); |
- // The delegate pointer may be modified at any time. |
- DirectoryListerDelegate* delegate() const { return delegate_; } |
- void set_delegate(DirectoryListerDelegate* d) { delegate_ = d; } |
- |
- // PlatformThread::Delegate implementation |
- virtual void ThreadMain(); |
- |
private: |
- friend class base::RefCountedThreadSafe<DirectoryLister>; |
- friend class DirectoryDataEvent; |
- |
- // Comparison methods for sorting, chosen based on |sort_|. |
- static bool CompareAlphaDirsFirst(const DirectoryListerData& a, |
- const DirectoryListerData& b); |
- static bool CompareDate(const DirectoryListerData& a, |
- const DirectoryListerData& b); |
- static bool CompareFullPath(const DirectoryListerData& a, |
- const DirectoryListerData& b); |
- |
- ~DirectoryLister(); |
+ class Job; |
- void OnReceivedData(const DirectoryListerData* data, int count); |
- void OnDone(int error); |
+ base::WorkerPoolJob::ScopedHandle<Job> job_handle_; |
- FilePath dir_; |
- bool recursive_; |
- DirectoryListerDelegate* delegate_; |
- SORT_TYPE sort_; |
- MessageLoop* message_loop_; |
- PlatformThreadHandle thread_; |
- base::CancellationFlag canceled_; |
+ DISALLOW_COPY_AND_ASSIGN(DirectoryLister); |
}; |
} // namespace net |