diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 17:38:30 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 17:38:30 +0000 |
commit | d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036 (patch) | |
tree | 1c2ee733bf62a44c31dc11f76dad53243a84439f /net/base | |
parent | e91d532339c854ff0a082c6562a519647524fa66 (diff) | |
download | chromium_src-d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036.zip chromium_src-d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036.tar.gz chromium_src-d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036.tar.bz2 |
Separate out some more ICU from base and into base/i18n.
This moves string_util_icu. I moved the number formatting function into
base/i18n/number_formatting and just removed the other function in
string_util_icu which was TrimWhitespaceUTF8. It is only used in a few places
and isn't actually helpful (and the fact that it round-trips through UTF-16 is
better for the caller to see).
This takes out the sorting from the FileEnumerator. The comment says the
sorting is not guaranteed. I moved it into file_util_icu as a standalone
function for callers of FileEnumerator to call manually if they need sorted
results. I modified the directory lister to use this sorting instead, and filed
a bug on doing more optimal JS-based sorting.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/267001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/directory_lister.cc | 48 | ||||
-rw-r--r-- | net/base/directory_lister.h | 8 | ||||
-rw-r--r-- | net/base/net_util.cc | 1 |
3 files changed, 43 insertions, 14 deletions
diff --git a/net/base/directory_lister.cc b/net/base/directory_lister.cc index 616fc82..7ea862f 100644 --- a/net/base/directory_lister.cc +++ b/net/base/directory_lister.cc @@ -1,10 +1,14 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "net/base/directory_lister.h" +#include <algorithm> +#include <vector> + #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/message_loop.h" #include "base/platform_thread.h" #include "net/base/net_errors.h" @@ -15,23 +19,37 @@ static const int kFilesPerEvent = 8; class DirectoryDataEvent : public Task { public: - explicit DirectoryDataEvent(DirectoryLister* d) - : lister(d), count(0), error(0) { + explicit DirectoryDataEvent(DirectoryLister* d) : lister(d), error(0) { + // Allocations of the FindInfo aren't super cheap, so reserve space. + data.reserve(64); } void Run() { - if (count) { - lister->OnReceivedData(data, count); - } else { + if (data.empty()) { lister->OnDone(error); + return; } + lister->OnReceivedData(&data[0], static_cast<int>(data.size())); } scoped_refptr<DirectoryLister> lister; - file_util::FileEnumerator::FindInfo data[kFilesPerEvent]; - int count, error; + std::vector<file_util::FileEnumerator::FindInfo> data; + int error; }; +// Comparator for sorting FindInfo's. This uses the locale aware filename +// comparison function on the filenames for sorting in the user's locale. +static bool CompareFindInfo(const file_util::FileEnumerator::FindInfo& a, + const file_util::FileEnumerator::FindInfo& b) { +#if defined(OS_WIN) + return file_util::LocaleAwareCompareFilenames(FilePath(a.cFileName), + FilePath(b.cFileName)); +#elif defined(OS_POSIX) + return file_util::LocaleAwareCompareFilenames(FilePath(a.filename), + FilePath(b.filename)); +#endif +} + DirectoryLister::DirectoryLister(const FilePath& dir, DirectoryListerDelegate* delegate) : dir_(dir), @@ -91,15 +109,25 @@ void DirectoryLister::ThreadMain() { file_util::FileEnumerator::INCLUDE_DOT_DOT)); while (!canceled_ && !(file_enum.Next().value().empty())) { - file_enum.GetFindInfo(&e->data[e->count]); + e->data.push_back(file_util::FileEnumerator::FindInfo()); + file_enum.GetFindInfo(&e->data[e->data.size() - 1]); + /* TODO(brettw) bug 24107: It would be nice to send incremental updates. + We gather them all so they can be sorted, but eventually the sorting + should be done from JS to give more flexibility in the page. When we do + that, we can uncomment this to send incremental updates to the page. if (++e->count == kFilesPerEvent) { message_loop_->PostTask(FROM_HERE, e); e = new DirectoryDataEvent(this); } + */ } - if (e->count > 0) { + if (!e->data.empty()) { + // Sort the results. See the TODO above (this sort should be removed and we + // should do it from JS). + std::sort(e->data.begin(), e->data.end(), CompareFindInfo); + message_loop_->PostTask(FROM_HERE, e); e = new DirectoryDataEvent(this); } diff --git a/net/base/directory_lister.h b/net/base/directory_lister.h index cb98da6..27204b6 100644 --- a/net/base/directory_lister.h +++ b/net/base/directory_lister.h @@ -1,9 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_BASE_DIRECTORY_LISTER_H__ -#define NET_BASE_DIRECTORY_LISTER_H__ +#ifndef NET_BASE_DIRECTORY_LISTER_H_ +#define NET_BASE_DIRECTORY_LISTER_H_ #include <string> @@ -68,4 +68,4 @@ class DirectoryLister : public base::RefCountedThreadSafe<DirectoryLister>, } // namespace net -#endif // NET_BASE_DIRECTORY_LISTER_H__ +#endif // NET_BASE_DIRECTORY_LISTER_H_ diff --git a/net/base/net_util.cc b/net/base/net_util.cc index b484b0c..8c36a5f 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -29,6 +29,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/lock.h" #include "base/logging.h" #include "base/message_loop.h" |