| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_BASE_DIRECTORY_LISTER_H_ | 5 #ifndef NET_BASE_DIRECTORY_LISTER_H__ |
| 6 #define NET_BASE_DIRECTORY_LISTER_H_ | 6 #define NET_BASE_DIRECTORY_LISTER_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/platform_thread.h" | 12 #include "base/platform_thread.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 | 14 |
| 15 class MessageLoop; | 15 class MessageLoop; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 // | 19 // |
| 20 // This class provides an API for listing the contents of a directory on the | 20 // This class provides an API for listing the contents of a directory on the |
| 21 // filesystem asynchronously. It spawns a background thread, and enumerates | 21 // filesystem asynchronously. It spawns a background thread, and enumerates |
| 22 // the specified directory on that thread. It marshalls WIN32_FIND_DATA | 22 // the specified directory on that thread. It marshalls WIN32_FIND_DATA |
| 23 // structs over to the main application thread. The consumer of this class | 23 // structs over to the main application thread. The consumer of this class |
| 24 // is insulated from any of the multi-threading details. | 24 // is insulated from any of the multi-threading details. |
| 25 // | 25 // |
| 26 class DirectoryLister : public base::RefCountedThreadSafe<DirectoryLister>, | 26 class DirectoryLister : public base::RefCountedThreadSafe<DirectoryLister>, |
| 27 public PlatformThread::Delegate { | 27 public PlatformThread::Delegate { |
| 28 public: | 28 public: |
| 29 // Implement this class to receive directory entries. | 29 // Implement this class to receive directory entries. |
| 30 class DirectoryListerDelegate { | 30 class DirectoryListerDelegate { |
| 31 public: | 31 public: |
| 32 virtual void OnListFile( | 32 virtual void OnListFile( |
| 33 const file_util::FileEnumerator::FindInfo& data) = 0; | 33 const file_util::FileEnumerator::FindInfo& data) = 0; |
| 34 virtual void OnListDone(int error) = 0; | 34 virtual void OnListDone(int error) = 0; |
| 35 | |
| 36 protected: | |
| 37 ~DirectoryListerDelegate() {} | |
| 38 }; | 35 }; |
| 39 | 36 |
| 40 DirectoryLister(const FilePath& dir, DirectoryListerDelegate* delegate); | 37 DirectoryLister(const FilePath& dir, DirectoryListerDelegate* delegate); |
| 41 ~DirectoryLister(); | 38 ~DirectoryLister(); |
| 42 | 39 |
| 43 // Call this method to start the directory enumeration thread. | 40 // Call this method to start the directory enumeration thread. |
| 44 bool Start(); | 41 bool Start(); |
| 45 | 42 |
| 46 // Call this method to asynchronously stop directory enumeration. The | 43 // Call this method to asynchronously stop directory enumeration. The |
| 47 // delegate will receive the OnListDone notification with an error code of | 44 // delegate will receive the OnListDone notification with an error code of |
| (...skipping 16 matching lines...) Expand all Loading... |
| 64 | 61 |
| 65 FilePath dir_; | 62 FilePath dir_; |
| 66 DirectoryListerDelegate* delegate_; | 63 DirectoryListerDelegate* delegate_; |
| 67 MessageLoop* message_loop_; | 64 MessageLoop* message_loop_; |
| 68 PlatformThreadHandle thread_; | 65 PlatformThreadHandle thread_; |
| 69 bool canceled_; | 66 bool canceled_; |
| 70 }; | 67 }; |
| 71 | 68 |
| 72 } // namespace net | 69 } // namespace net |
| 73 | 70 |
| 74 #endif // NET_BASE_DIRECTORY_LISTER_H_ | 71 #endif // NET_BASE_DIRECTORY_LISTER_H__ |
| OLD | NEW |