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/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/containers/flat_map.h" | |
17 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
19 #include "base/json/json_writer.h" | 20 #include "base/json/json_writer.h" |
20 #include "base/lazy_instance.h" | 21 #include "base/lazy_instance.h" |
21 #include "base/location.h" | 22 #include "base/location.h" |
22 #include "base/logging.h" | 23 #include "base/logging.h" |
23 #include "base/macros.h" | 24 #include "base/macros.h" |
24 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
25 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
26 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { | 355 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { |
355 switch (pixel_size) { | 356 switch (pixel_size) { |
356 case 16: return IconLoader::SMALL; | 357 case 16: return IconLoader::SMALL; |
357 case 32: return IconLoader::NORMAL; | 358 case 32: return IconLoader::NORMAL; |
358 default: | 359 default: |
359 NOTREACHED(); | 360 NOTREACHED(); |
360 return IconLoader::NORMAL; | 361 return IconLoader::NORMAL; |
361 } | 362 } |
362 } | 363 } |
363 | 364 |
364 typedef base::hash_map<std::string, DownloadQuery::FilterType> FilterTypeMap; | 365 using FilterTypeMap = base::flat_map<std::string, DownloadQuery::FilterType>; |
366 void AppendFilter(const char* name, | |
367 DownloadQuery::FilterType type, | |
368 std::vector<FilterTypeMap::value_type>* v) { | |
369 v->emplace_back(name, type); | |
370 } | |
365 | 371 |
366 void InitFilterTypeMap(FilterTypeMap* filter_types_ptr) { | 372 void InitFilterTypeMap(FilterTypeMap* filter_types_ptr) { |
367 FilterTypeMap& filter_types = *filter_types_ptr; | 373 // Initialize the map in one shot by storing to a vector and assigning. |
368 filter_types[kBytesReceivedKey] = DownloadQuery::FILTER_BYTES_RECEIVED; | 374 std::vector<FilterTypeMap::value_type> v; |
369 filter_types[kExistsKey] = DownloadQuery::FILTER_EXISTS; | 375 |
370 filter_types[kFilenameKey] = DownloadQuery::FILTER_FILENAME; | 376 AppendFilter(kBytesReceivedKey, DownloadQuery::FILTER_BYTES_RECEIVED, &v); |
371 filter_types[kFilenameRegexKey] = DownloadQuery::FILTER_FILENAME_REGEX; | 377 |
372 filter_types[kMimeKey] = DownloadQuery::FILTER_MIME; | 378 AppendFilter(kBytesReceivedKey, DownloadQuery::FILTER_BYTES_RECEIVED, &v); |
373 filter_types[kPausedKey] = DownloadQuery::FILTER_PAUSED; | 379 AppendFilter(kExistsKey, DownloadQuery::FILTER_EXISTS, &v); |
374 filter_types[kQueryKey] = DownloadQuery::FILTER_QUERY; | 380 AppendFilter(kFilenameKey, DownloadQuery::FILTER_FILENAME, &v); |
375 filter_types[kEndedAfterKey] = DownloadQuery::FILTER_ENDED_AFTER; | 381 AppendFilter(kFilenameRegexKey, DownloadQuery::FILTER_FILENAME_REGEX, &v); |
376 filter_types[kEndedBeforeKey] = DownloadQuery::FILTER_ENDED_BEFORE; | 382 AppendFilter(kMimeKey, DownloadQuery::FILTER_MIME, &v); |
377 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME; | 383 AppendFilter(kPausedKey, DownloadQuery::FILTER_PAUSED, &v); |
378 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER; | 384 AppendFilter(kQueryKey, DownloadQuery::FILTER_QUERY, &v); |
379 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE; | 385 AppendFilter(kEndedAfterKey, DownloadQuery::FILTER_ENDED_AFTER, &v); |
380 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME; | 386 AppendFilter(kEndedBeforeKey, DownloadQuery::FILTER_ENDED_BEFORE, &v); |
381 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES; | 387 AppendFilter(kEndTimeKey, DownloadQuery::FILTER_END_TIME, &v); |
382 filter_types[kTotalBytesGreaterKey] = | 388 AppendFilter(kStartedAfterKey, DownloadQuery::FILTER_STARTED_AFTER, &v); |
383 DownloadQuery::FILTER_TOTAL_BYTES_GREATER; | 389 AppendFilter(kStartedBeforeKey, DownloadQuery::FILTER_STARTED_BEFORE, &v); |
384 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS; | 390 AppendFilter(kStartTimeKey, DownloadQuery::FILTER_START_TIME, &v); |
385 filter_types[kUrlKey] = DownloadQuery::FILTER_ORIGINAL_URL; | 391 AppendFilter(kTotalBytesKey, DownloadQuery::FILTER_TOTAL_BYTES, &v); |
386 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_ORIGINAL_URL_REGEX; | 392 AppendFilter(kTotalBytesGreaterKey, DownloadQuery::FILTER_TOTAL_BYTES_GREATER, |
387 filter_types[kFinalUrlKey] = DownloadQuery::FILTER_URL; | 393 &v); |
388 filter_types[kFinalUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX; | 394 AppendFilter(kTotalBytesLessKey, DownloadQuery::FILTER_TOTAL_BYTES_LESS, &v); |
395 AppendFilter(kUrlKey, DownloadQuery::FILTER_ORIGINAL_URL, &v); | |
396 AppendFilter(kUrlRegexKey, DownloadQuery::FILTER_ORIGINAL_URL_REGEX, &v); | |
397 AppendFilter(kFinalUrlKey, DownloadQuery::FILTER_URL, &v); | |
398 AppendFilter(kFinalUrlRegexKey, DownloadQuery::FILTER_URL_REGEX, &v); | |
399 | |
400 *filter_types_ptr = FilterTypeMap(std::move(v), base::KEEP_FIRST_OF_DUPES); | |
389 } | 401 } |
390 | 402 |
391 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap; | 403 using SortTypeMap = base::flat_map<std::string, DownloadQuery::SortType>; |
404 void AppendFilter(const char* name, | |
405 DownloadQuery::SortType type, | |
406 std::vector<SortTypeMap::value_type>* v) { | |
407 v->emplace_back(name, type); | |
408 } | |
392 | 409 |
393 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) { | 410 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) { |
394 SortTypeMap& sorter_types = *sorter_types_ptr; | 411 // Initialize the map in one shot by storing to a vector and assigning. |
395 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED; | 412 std::vector<SortTypeMap::value_type> v; |
396 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER; | 413 |
397 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME; | 414 AppendFilter(kBytesReceivedKey, DownloadQuery::SORT_BYTES_RECEIVED, &v); |
chrisha
2017/05/23 20:07:59
AppendSortQuery? AppendSortType?
| |
398 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS; | 415 AppendFilter(kDangerKey, DownloadQuery::SORT_DANGER, &v); |
399 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME; | 416 AppendFilter(kEndTimeKey, DownloadQuery::SORT_END_TIME, &v); |
400 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME; | 417 AppendFilter(kExistsKey, DownloadQuery::SORT_EXISTS, &v); |
401 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED; | 418 AppendFilter(kFilenameKey, DownloadQuery::SORT_FILENAME, &v); |
402 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; | 419 AppendFilter(kMimeKey, DownloadQuery::SORT_MIME, &v); |
403 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; | 420 AppendFilter(kPausedKey, DownloadQuery::SORT_PAUSED, &v); |
404 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; | 421 AppendFilter(kStartTimeKey, DownloadQuery::SORT_START_TIME, &v); |
405 sorter_types[kUrlKey] = DownloadQuery::SORT_ORIGINAL_URL; | 422 AppendFilter(kStateKey, DownloadQuery::SORT_STATE, &v); |
406 sorter_types[kFinalUrlKey] = DownloadQuery::SORT_URL; | 423 AppendFilter(kTotalBytesKey, DownloadQuery::SORT_TOTAL_BYTES, &v); |
424 AppendFilter(kUrlKey, DownloadQuery::SORT_ORIGINAL_URL, &v); | |
425 AppendFilter(kFinalUrlKey, DownloadQuery::SORT_URL, &v); | |
426 | |
427 *sorter_types_ptr = SortTypeMap(std::move(v), base::KEEP_FIRST_OF_DUPES); | |
407 } | 428 } |
chrisha
2017/05/23 20:07:59
At a higher level: Should both of the short lists
brettw
2017/06/28 23:58:39
I did the downloads one in a separate CL: https://
| |
408 | 429 |
409 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { | 430 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { |
410 return !download_item.IsTemporary(); | 431 return !download_item.IsTemporary(); |
411 } | 432 } |
412 | 433 |
413 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to | 434 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to |
414 // the off-record DownloadManager if one exists and is requested via | 435 // the off-record DownloadManager if one exists and is requested via |
415 // |include_incognito|. This should work regardless of whether |profile| is | 436 // |include_incognito|. This should work regardless of whether |profile| is |
416 // original or incognito. | 437 // original or incognito. |
417 void GetManagers(content::BrowserContext* context, | 438 void GetManagers(content::BrowserContext* context, |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1926 return; | 1947 return; |
1927 base::Time now(base::Time::Now()); | 1948 base::Time now(base::Time::Now()); |
1928 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); | 1949 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); |
1929 if (delta <= kFileExistenceRateLimitSeconds) | 1950 if (delta <= kFileExistenceRateLimitSeconds) |
1930 return; | 1951 return; |
1931 last_checked_removal_ = now; | 1952 last_checked_removal_ = now; |
1932 manager->CheckForHistoryFilesRemoval(); | 1953 manager->CheckForHistoryFilesRemoval(); |
1933 } | 1954 } |
1934 | 1955 |
1935 } // namespace extensions | 1956 } // namespace extensions |
OLD | NEW |