| 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 "chrome/browser/download/download_query.h" | 5 #include "chrome/browser/download/download_query.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> |
| 8 #include <string> | 11 #include <string> |
| 9 #include <vector> | 12 #include <vector> |
| 10 | 13 |
| 11 #include "base/bind.h" | 14 #include "base/bind.h" |
| 12 #include "base/callback.h" | 15 #include "base/callback.h" |
| 13 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 14 #include "base/i18n/case_conversion.h" | 17 #include "base/i18n/case_conversion.h" |
| 15 #include "base/i18n/string_search.h" | 18 #include "base/i18n/string_search.h" |
| 16 #include "base/logging.h" | 19 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return false; | 65 return false; |
| 63 } | 66 } |
| 64 out->push_back(element); | 67 out->push_back(element); |
| 65 } | 68 } |
| 66 return true; | 69 return true; |
| 67 } | 70 } |
| 68 | 71 |
| 69 // The next several functions are helpers for making Callbacks that access | 72 // The next several functions are helpers for making Callbacks that access |
| 70 // DownloadItem fields. | 73 // DownloadItem fields. |
| 71 | 74 |
| 72 static int64 GetStartTimeMsEpoch(const DownloadItem& item) { | 75 static int64_t GetStartTimeMsEpoch(const DownloadItem& item) { |
| 73 return (item.GetStartTime() - base::Time::UnixEpoch()).InMilliseconds(); | 76 return (item.GetStartTime() - base::Time::UnixEpoch()).InMilliseconds(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 static int64 GetEndTimeMsEpoch(const DownloadItem& item) { | 79 static int64_t GetEndTimeMsEpoch(const DownloadItem& item) { |
| 77 return (item.GetEndTime() - base::Time::UnixEpoch()).InMilliseconds(); | 80 return (item.GetEndTime() - base::Time::UnixEpoch()).InMilliseconds(); |
| 78 } | 81 } |
| 79 | 82 |
| 80 std::string TimeToISO8601(const base::Time& t) { | 83 std::string TimeToISO8601(const base::Time& t) { |
| 81 base::Time::Exploded exploded; | 84 base::Time::Exploded exploded; |
| 82 t.UTCExplode(&exploded); | 85 t.UTCExplode(&exploded); |
| 83 return base::StringPrintf( | 86 return base::StringPrintf( |
| 84 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, | 87 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, |
| 85 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, | 88 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
| 86 exploded.millisecond); | 89 exploded.millisecond); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 !base::i18n::StringSearchIgnoringCaseAndAccents( | 235 !base::i18n::StringSearchIgnoringCaseAndAccents( |
| 233 term, url_formatted, NULL, NULL) && | 236 term, url_formatted, NULL, NULL) && |
| 234 !base::i18n::StringSearchIgnoringCaseAndAccents( | 237 !base::i18n::StringSearchIgnoringCaseAndAccents( |
| 235 term, path, NULL, NULL)) { | 238 term, path, NULL, NULL)) { |
| 236 return false; | 239 return false; |
| 237 } | 240 } |
| 238 } | 241 } |
| 239 return true; | 242 return true; |
| 240 } | 243 } |
| 241 | 244 |
| 242 DownloadQuery::DownloadQuery() : limit_(kuint32max), skip_(0U) {} | 245 DownloadQuery::DownloadQuery() |
| 246 : limit_(std::numeric_limits<uint32_t>::max()), skip_(0U) {} |
| 243 DownloadQuery::~DownloadQuery() {} | 247 DownloadQuery::~DownloadQuery() {} |
| 244 | 248 |
| 245 // AddFilter() pushes a new FilterCallback to filters_. Most FilterCallbacks are | 249 // AddFilter() pushes a new FilterCallback to filters_. Most FilterCallbacks are |
| 246 // Callbacks to FieldMatches<>(). Search() iterates over given DownloadItems, | 250 // Callbacks to FieldMatches<>(). Search() iterates over given DownloadItems, |
| 247 // discarding items for which any filter returns false. A DownloadQuery may have | 251 // discarding items for which any filter returns false. A DownloadQuery may have |
| 248 // zero or more FilterCallbacks. | 252 // zero or more FilterCallbacks. |
| 249 | 253 |
| 250 bool DownloadQuery::AddFilter(const DownloadQuery::FilterCallback& value) { | 254 bool DownloadQuery::AddFilter(const DownloadQuery::FilterCallback& value) { |
| 251 if (value.is_null()) return false; | 255 if (value.is_null()) return false; |
| 252 filters_.push_back(value); | 256 filters_.push_back(value); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 385 } |
| 382 } | 386 } |
| 383 CHECK_NE(left->GetId(), right->GetId()); | 387 CHECK_NE(left->GetId(), right->GetId()); |
| 384 return left->GetId() < right->GetId(); | 388 return left->GetId() < right->GetId(); |
| 385 } | 389 } |
| 386 | 390 |
| 387 void DownloadQuery::AddSorter(DownloadQuery::SortType type, | 391 void DownloadQuery::AddSorter(DownloadQuery::SortType type, |
| 388 DownloadQuery::SortDirection direction) { | 392 DownloadQuery::SortDirection direction) { |
| 389 switch (type) { | 393 switch (type) { |
| 390 case SORT_END_TIME: | 394 case SORT_END_TIME: |
| 391 sorters_.push_back(Sorter::Build<int64>(direction, &GetEndTimeMsEpoch)); | 395 sorters_.push_back(Sorter::Build<int64_t>(direction, &GetEndTimeMsEpoch)); |
| 392 break; | 396 break; |
| 393 case SORT_START_TIME: | 397 case SORT_START_TIME: |
| 394 sorters_.push_back(Sorter::Build<int64>(direction, &GetStartTimeMsEpoch)); | 398 sorters_.push_back( |
| 399 Sorter::Build<int64_t>(direction, &GetStartTimeMsEpoch)); |
| 395 break; | 400 break; |
| 396 case SORT_URL: | 401 case SORT_URL: |
| 397 sorters_.push_back(Sorter::Build<std::string>(direction, &GetUrl)); | 402 sorters_.push_back(Sorter::Build<std::string>(direction, &GetUrl)); |
| 398 break; | 403 break; |
| 399 case SORT_FILENAME: | 404 case SORT_FILENAME: |
| 400 sorters_.push_back( | 405 sorters_.push_back( |
| 401 Sorter::Build<base::string16>(direction, &GetFilename)); | 406 Sorter::Build<base::string16>(direction, &GetFilename)); |
| 402 break; | 407 break; |
| 403 case SORT_DANGER: | 408 case SORT_DANGER: |
| 404 sorters_.push_back(Sorter::Build<DownloadDangerType>( | 409 sorters_.push_back(Sorter::Build<DownloadDangerType>( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 results->begin() + std::min(limit_ + skip_, results->size()), | 446 results->begin() + std::min(limit_ + skip_, results->size()), |
| 442 results->end(), | 447 results->end(), |
| 443 DownloadComparator(sorters_)); | 448 DownloadComparator(sorters_)); |
| 444 } | 449 } |
| 445 | 450 |
| 446 results->erase(results->begin(), results->begin() + skip_); | 451 results->erase(results->begin(), results->begin() + skip_); |
| 447 | 452 |
| 448 if (results->size() > limit_) | 453 if (results->size() > limit_) |
| 449 results->resize(limit_); | 454 results->resize(limit_); |
| 450 } | 455 } |
| OLD | NEW |