OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class MessageLoopProxy; | 19 class SingleThreadTaskRunner; |
20 } | 20 } |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 // This class provides an API for asynchronously listing the contents of a | 24 // This class provides an API for asynchronously listing the contents of a |
25 // directory on the filesystem. It runs a task on a background thread, and | 25 // directory on the filesystem. It runs a task on a background thread, and |
26 // enumerates all files in the specified directory on that thread. Destroying | 26 // enumerates all files in the specified directory on that thread. Destroying |
27 // the lister cancels the list operation. The DirectoryLister must only be | 27 // the lister cancels the list operation. The DirectoryLister must only be |
28 // used on a thread with a MessageLoop. | 28 // used on a thread with a MessageLoop. |
29 class NET_EXPORT DirectoryLister { | 29 class NET_EXPORT DirectoryLister { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 // Called on both threads. | 104 // Called on both threads. |
105 bool IsCancelled() const; | 105 bool IsCancelled() const; |
106 | 106 |
107 // Called on origin thread. | 107 // Called on origin thread. |
108 void DoneOnOriginThread(scoped_ptr<DirectoryList> directory_list, | 108 void DoneOnOriginThread(scoped_ptr<DirectoryList> directory_list, |
109 int error) const; | 109 int error) const; |
110 | 110 |
111 const base::FilePath dir_; | 111 const base::FilePath dir_; |
112 const ListingType type_; | 112 const ListingType type_; |
113 const scoped_refptr<base::MessageLoopProxy> origin_loop_; | 113 const scoped_refptr<base::SingleThreadTaskRunner> origin_loop_; |
114 | 114 |
115 // Only used on the origin thread. | 115 // Only used on the origin thread. |
116 DirectoryLister* lister_; | 116 DirectoryLister* lister_; |
117 | 117 |
118 // Set to 1 on cancellation. Used both to abort listing files early on the | 118 // Set to 1 on cancellation. Used both to abort listing files early on the |
119 // worker pool thread for performance reasons and to ensure |lister_| isn't | 119 // worker pool thread for performance reasons and to ensure |lister_| isn't |
120 // called after cancellation on the origin thread. | 120 // called after cancellation on the origin thread. |
121 base::subtle::Atomic32 cancelled_; | 121 base::subtle::Atomic32 cancelled_; |
122 | 122 |
123 DISALLOW_COPY_AND_ASSIGN(Core); | 123 DISALLOW_COPY_AND_ASSIGN(Core); |
124 }; | 124 }; |
125 | 125 |
126 // Call into the corresponding DirectoryListerDelegate. Must not be called | 126 // Call into the corresponding DirectoryListerDelegate. Must not be called |
127 // after cancellation. | 127 // after cancellation. |
128 void OnListFile(const DirectoryListerData& data); | 128 void OnListFile(const DirectoryListerData& data); |
129 void OnListDone(int error); | 129 void OnListDone(int error); |
130 | 130 |
131 scoped_refptr<Core> core_; | 131 scoped_refptr<Core> core_; |
132 DirectoryListerDelegate* const delegate_; | 132 DirectoryListerDelegate* const delegate_; |
133 | 133 |
134 DISALLOW_COPY_AND_ASSIGN(DirectoryLister); | 134 DISALLOW_COPY_AND_ASSIGN(DirectoryLister); |
135 }; | 135 }; |
136 | 136 |
137 } // namespace net | 137 } // namespace net |
138 | 138 |
139 #endif // NET_BASE_DIRECTORY_LISTER_H_ | 139 #endif // NET_BASE_DIRECTORY_LISTER_H_ |
OLD | NEW |