Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1312)

Unified Diff: net/base/directory_lister.cc

Issue 1096323003: Remove unused sorting options from DirectoryLister. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/directory_lister.h ('k') | net/base/directory_lister_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/directory_lister.cc
diff --git a/net/base/directory_lister.cc b/net/base/directory_lister.cc
index f746f9b2e476576098d8d5ea9c7400c4674c5ecb..43827b256936096f285045a37a532309c77f7f74 100644
--- a/net/base/directory_lister.cc
+++ b/net/base/directory_lister.cc
@@ -45,42 +45,15 @@ bool CompareAlphaDirsFirst(const DirectoryLister::DirectoryListerData& a,
b.info.GetName());
}
-bool CompareDate(const DirectoryLister::DirectoryListerData& a,
- const DirectoryLister::DirectoryListerData& b) {
- // Parent directory before all else.
- if (IsDotDot(a.info.GetName()))
- return true;
- if (IsDotDot(b.info.GetName()))
- return false;
-
- // Directories before regular files.
- bool a_is_directory = a.info.IsDirectory();
- bool b_is_directory = b.info.IsDirectory();
- if (a_is_directory != b_is_directory)
- return a_is_directory;
- return a.info.GetLastModifiedTime() > b.info.GetLastModifiedTime();
-}
-
-// Comparator for sorting find result by paths. This uses the locale-aware
-// comparison function on the filenames for sorting in the user's locale.
-// Static.
-bool CompareFullPath(const DirectoryLister::DirectoryListerData& a,
- const DirectoryLister::DirectoryListerData& b) {
- return base::i18n::LocaleAwareCompareFilenames(a.path, b.path);
-}
-
void SortData(std::vector<DirectoryLister::DirectoryListerData>* data,
- DirectoryLister::SortType sort_type) {
+ DirectoryLister::ListingType listing_type) {
// Sort the results. See the TODO below (this sort should be removed and we
// should do it from JS).
- if (sort_type == DirectoryLister::DATE) {
- std::sort(data->begin(), data->end(), CompareDate);
- } else if (sort_type == DirectoryLister::FULL_PATH) {
- std::sort(data->begin(), data->end(), CompareFullPath);
- } else if (sort_type == DirectoryLister::ALPHA_DIRS_FIRST) {
+ if (listing_type == DirectoryLister::ALPHA_DIRS_FIRST) {
std::sort(data->begin(), data->end(), CompareAlphaDirsFirst);
- } else {
- DCHECK_EQ(DirectoryLister::NO_SORT, sort_type);
+ } else if (listing_type != DirectoryLister::NO_SORT &&
+ listing_type != DirectoryLister::NO_SORT_RECURSIVE) {
+ NOTREACHED();
}
}
@@ -89,17 +62,16 @@ void SortData(std::vector<DirectoryLister::DirectoryListerData>* data,
DirectoryLister::DirectoryLister(const base::FilePath& dir,
DirectoryListerDelegate* delegate)
: delegate_(delegate) {
- core_ = new Core(dir, false, ALPHA_DIRS_FIRST, this);
+ core_ = new Core(dir, ALPHA_DIRS_FIRST, this);
DCHECK(delegate_);
DCHECK(!dir.value().empty());
}
DirectoryLister::DirectoryLister(const base::FilePath& dir,
- bool recursive,
- SortType sort,
+ ListingType type,
DirectoryListerDelegate* delegate)
: delegate_(delegate) {
- core_ = new Core(dir, recursive, sort, this);
+ core_ = new Core(dir, type, this);
DCHECK(delegate_);
DCHECK(!dir.value().empty());
}
@@ -120,12 +92,10 @@ void DirectoryLister::Cancel() {
}
DirectoryLister::Core::Core(const base::FilePath& dir,
- bool recursive,
- SortType sort,
+ ListingType type,
DirectoryLister* lister)
: dir_(dir),
- recursive_(recursive),
- sort_(sort),
+ type_(type),
origin_loop_(base::MessageLoopProxy::current()),
lister_(lister),
cancelled_(0) {
@@ -156,10 +126,14 @@ void DirectoryLister::Core::Start() {
}
int types = base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES;
- if (!recursive_)
+ bool recursive;
+ if (NO_SORT_RECURSIVE != type_) {
types |= base::FileEnumerator::INCLUDE_DOT_DOT;
-
- base::FileEnumerator file_enum(dir_, recursive_, types);
+ recursive = false;
+ } else {
+ recursive = true;
+ }
+ base::FileEnumerator file_enum(dir_, recursive, types);
base::FilePath path;
while (!(path = file_enum.Next()).empty()) {
@@ -189,7 +163,7 @@ void DirectoryLister::Core::Start() {
*/
}
- SortData(directory_list.get(), sort_);
+ SortData(directory_list.get(), type_);
origin_loop_->PostTask(
FROM_HERE,
« no previous file with comments | « net/base/directory_lister.h ('k') | net/base/directory_lister_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698