| 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 #include "net/base/directory_lister.h" | 5 #include "net/base/directory_lister.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 return true; | 34 return true; |
| 35 if (IsDotDot(b.info.GetName())) | 35 if (IsDotDot(b.info.GetName())) |
| 36 return false; | 36 return false; |
| 37 | 37 |
| 38 // Directories before regular files. | 38 // Directories before regular files. |
| 39 bool a_is_directory = a.info.IsDirectory(); | 39 bool a_is_directory = a.info.IsDirectory(); |
| 40 bool b_is_directory = b.info.IsDirectory(); | 40 bool b_is_directory = b.info.IsDirectory(); |
| 41 if (a_is_directory != b_is_directory) | 41 if (a_is_directory != b_is_directory) |
| 42 return a_is_directory; | 42 return a_is_directory; |
| 43 | 43 |
| 44 return file_util::LocaleAwareCompareFilenames(a.info.GetName(), | 44 return base::i18n::LocaleAwareCompareFilenames(a.info.GetName(), |
| 45 b.info.GetName()); | 45 b.info.GetName()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool CompareDate(const DirectoryLister::DirectoryListerData& a, | 48 bool CompareDate(const DirectoryLister::DirectoryListerData& a, |
| 49 const DirectoryLister::DirectoryListerData& b) { | 49 const DirectoryLister::DirectoryListerData& b) { |
| 50 // Parent directory before all else. | 50 // Parent directory before all else. |
| 51 if (IsDotDot(a.info.GetName())) | 51 if (IsDotDot(a.info.GetName())) |
| 52 return true; | 52 return true; |
| 53 if (IsDotDot(b.info.GetName())) | 53 if (IsDotDot(b.info.GetName())) |
| 54 return false; | 54 return false; |
| 55 | 55 |
| 56 // Directories before regular files. | 56 // Directories before regular files. |
| 57 bool a_is_directory = a.info.IsDirectory(); | 57 bool a_is_directory = a.info.IsDirectory(); |
| 58 bool b_is_directory = b.info.IsDirectory(); | 58 bool b_is_directory = b.info.IsDirectory(); |
| 59 if (a_is_directory != b_is_directory) | 59 if (a_is_directory != b_is_directory) |
| 60 return a_is_directory; | 60 return a_is_directory; |
| 61 return a.info.GetLastModifiedTime() > b.info.GetLastModifiedTime(); | 61 return a.info.GetLastModifiedTime() > b.info.GetLastModifiedTime(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Comparator for sorting find result by paths. This uses the locale-aware | 64 // Comparator for sorting find result by paths. This uses the locale-aware |
| 65 // comparison function on the filenames for sorting in the user's locale. | 65 // comparison function on the filenames for sorting in the user's locale. |
| 66 // Static. | 66 // Static. |
| 67 bool CompareFullPath(const DirectoryLister::DirectoryListerData& a, | 67 bool CompareFullPath(const DirectoryLister::DirectoryListerData& a, |
| 68 const DirectoryLister::DirectoryListerData& b) { | 68 const DirectoryLister::DirectoryListerData& b) { |
| 69 return file_util::LocaleAwareCompareFilenames(a.path, b.path); | 69 return base::i18n::LocaleAwareCompareFilenames(a.path, b.path); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void SortData(std::vector<DirectoryLister::DirectoryListerData>* data, | 72 void SortData(std::vector<DirectoryLister::DirectoryListerData>* data, |
| 73 DirectoryLister::SortType sort_type) { | 73 DirectoryLister::SortType sort_type) { |
| 74 // Sort the results. See the TODO below (this sort should be removed and we | 74 // Sort the results. See the TODO below (this sort should be removed and we |
| 75 // should do it from JS). | 75 // should do it from JS). |
| 76 if (sort_type == DirectoryLister::DATE) | 76 if (sort_type == DirectoryLister::DATE) |
| 77 std::sort(data->begin(), data->end(), CompareDate); | 77 std::sort(data->begin(), data->end(), CompareDate); |
| 78 else if (sort_type == DirectoryLister::FULL_PATH) | 78 else if (sort_type == DirectoryLister::FULL_PATH) |
| 79 std::sort(data->begin(), data->end(), CompareFullPath); | 79 std::sort(data->begin(), data->end(), CompareFullPath); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 void DirectoryLister::OnReceivedData(const DirectoryListerData& data) { | 206 void DirectoryLister::OnReceivedData(const DirectoryListerData& data) { |
| 207 delegate_->OnListFile(data); | 207 delegate_->OnListFile(data); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void DirectoryLister::OnDone(int error) { | 210 void DirectoryLister::OnDone(int error) { |
| 211 delegate_->OnListDone(error); | 211 delegate_->OnListDone(error); |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace net | 214 } // namespace net |
| OLD | NEW |