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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 2829163004: Remove uses of base::hash_map from //chrome (Closed)
Patch Set: Downloads back Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { 356 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) {
356 switch (pixel_size) { 357 switch (pixel_size) {
357 case 16: return IconLoader::SMALL; 358 case 16: return IconLoader::SMALL;
358 case 32: return IconLoader::NORMAL; 359 case 32: return IconLoader::NORMAL;
359 default: 360 default:
360 NOTREACHED(); 361 NOTREACHED();
361 return IconLoader::NORMAL; 362 return IconLoader::NORMAL;
362 } 363 }
363 } 364 }
364 365
365 typedef base::hash_map<std::string, DownloadQuery::FilterType> FilterTypeMap; 366 using FilterTypeMap = base::flat_map<std::string, DownloadQuery::FilterType>;
367 void AppendFilter(const char* name,
368 DownloadQuery::FilterType type,
369 std::vector<FilterTypeMap::value_type>* v) {
370 v->emplace_back(name, type);
371 }
366 372
367 void InitFilterTypeMap(FilterTypeMap* filter_types_ptr) { 373 void InitFilterTypeMap(FilterTypeMap* filter_types_ptr) {
368 FilterTypeMap& filter_types = *filter_types_ptr; 374 // Initialize the map in one shot by storing to a vector and assigning.
369 filter_types[kBytesReceivedKey] = DownloadQuery::FILTER_BYTES_RECEIVED; 375 std::vector<FilterTypeMap::value_type> v;
370 filter_types[kExistsKey] = DownloadQuery::FILTER_EXISTS; 376
371 filter_types[kFilenameKey] = DownloadQuery::FILTER_FILENAME; 377 AppendFilter(kBytesReceivedKey, DownloadQuery::FILTER_BYTES_RECEIVED, &v);
372 filter_types[kFilenameRegexKey] = DownloadQuery::FILTER_FILENAME_REGEX; 378
373 filter_types[kMimeKey] = DownloadQuery::FILTER_MIME; 379 AppendFilter(kBytesReceivedKey, DownloadQuery::FILTER_BYTES_RECEIVED, &v);
374 filter_types[kPausedKey] = DownloadQuery::FILTER_PAUSED; 380 AppendFilter(kExistsKey, DownloadQuery::FILTER_EXISTS, &v);
375 filter_types[kQueryKey] = DownloadQuery::FILTER_QUERY; 381 AppendFilter(kFilenameKey, DownloadQuery::FILTER_FILENAME, &v);
376 filter_types[kEndedAfterKey] = DownloadQuery::FILTER_ENDED_AFTER; 382 AppendFilter(kFilenameRegexKey, DownloadQuery::FILTER_FILENAME_REGEX, &v);
377 filter_types[kEndedBeforeKey] = DownloadQuery::FILTER_ENDED_BEFORE; 383 AppendFilter(kMimeKey, DownloadQuery::FILTER_MIME, &v);
378 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME; 384 AppendFilter(kPausedKey, DownloadQuery::FILTER_PAUSED, &v);
379 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER; 385 AppendFilter(kQueryKey, DownloadQuery::FILTER_QUERY, &v);
380 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE; 386 AppendFilter(kEndedAfterKey, DownloadQuery::FILTER_ENDED_AFTER, &v);
381 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME; 387 AppendFilter(kEndedBeforeKey, DownloadQuery::FILTER_ENDED_BEFORE, &v);
382 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES; 388 AppendFilter(kEndTimeKey, DownloadQuery::FILTER_END_TIME, &v);
383 filter_types[kTotalBytesGreaterKey] = 389 AppendFilter(kStartedAfterKey, DownloadQuery::FILTER_STARTED_AFTER, &v);
384 DownloadQuery::FILTER_TOTAL_BYTES_GREATER; 390 AppendFilter(kStartedBeforeKey, DownloadQuery::FILTER_STARTED_BEFORE, &v);
385 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS; 391 AppendFilter(kStartTimeKey, DownloadQuery::FILTER_START_TIME, &v);
386 filter_types[kUrlKey] = DownloadQuery::FILTER_ORIGINAL_URL; 392 AppendFilter(kTotalBytesKey, DownloadQuery::FILTER_TOTAL_BYTES, &v);
387 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_ORIGINAL_URL_REGEX; 393 AppendFilter(kTotalBytesGreaterKey, DownloadQuery::FILTER_TOTAL_BYTES_GREATER,
388 filter_types[kFinalUrlKey] = DownloadQuery::FILTER_URL; 394 &v);
389 filter_types[kFinalUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX; 395 AppendFilter(kTotalBytesLessKey, DownloadQuery::FILTER_TOTAL_BYTES_LESS, &v);
396 AppendFilter(kUrlKey, DownloadQuery::FILTER_ORIGINAL_URL, &v);
397 AppendFilter(kUrlRegexKey, DownloadQuery::FILTER_ORIGINAL_URL_REGEX, &v);
398 AppendFilter(kFinalUrlKey, DownloadQuery::FILTER_URL, &v);
399 AppendFilter(kFinalUrlRegexKey, DownloadQuery::FILTER_URL_REGEX, &v);
400
401 *filter_types_ptr = FilterTypeMap(std::move(v), base::KEEP_FIRST_OF_DUPES);
390 } 402 }
391 403
392 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap; 404 using SortTypeMap = base::flat_map<std::string, DownloadQuery::SortType>;
405 void AppendFilter(const char* name,
406 DownloadQuery::SortType type,
407 std::vector<SortTypeMap::value_type>* v) {
408 v->emplace_back(name, type);
409 }
393 410
394 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) { 411 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) {
395 SortTypeMap& sorter_types = *sorter_types_ptr; 412 // Initialize the map in one shot by storing to a vector and assigning.
396 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED; 413 std::vector<SortTypeMap::value_type> v;
397 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER; 414
398 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME; 415 AppendFilter(kBytesReceivedKey, DownloadQuery::SORT_BYTES_RECEIVED, &v);
399 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS; 416 AppendFilter(kDangerKey, DownloadQuery::SORT_DANGER, &v);
400 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME; 417 AppendFilter(kEndTimeKey, DownloadQuery::SORT_END_TIME, &v);
401 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME; 418 AppendFilter(kExistsKey, DownloadQuery::SORT_EXISTS, &v);
402 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED; 419 AppendFilter(kFilenameKey, DownloadQuery::SORT_FILENAME, &v);
403 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; 420 AppendFilter(kMimeKey, DownloadQuery::SORT_MIME, &v);
404 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; 421 AppendFilter(kPausedKey, DownloadQuery::SORT_PAUSED, &v);
405 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; 422 AppendFilter(kStartTimeKey, DownloadQuery::SORT_START_TIME, &v);
406 sorter_types[kUrlKey] = DownloadQuery::SORT_ORIGINAL_URL; 423 AppendFilter(kStateKey, DownloadQuery::SORT_STATE, &v);
407 sorter_types[kFinalUrlKey] = DownloadQuery::SORT_URL; 424 AppendFilter(kTotalBytesKey, DownloadQuery::SORT_TOTAL_BYTES, &v);
425 AppendFilter(kUrlKey, DownloadQuery::SORT_ORIGINAL_URL, &v);
426 AppendFilter(kFinalUrlKey, DownloadQuery::SORT_URL, &v);
427
428 *sorter_types_ptr = SortTypeMap(std::move(v), base::KEEP_FIRST_OF_DUPES);
408 } 429 }
409 430
410 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) { 431 bool IsNotTemporaryDownloadFilter(const DownloadItem& download_item) {
411 return !download_item.IsTemporary(); 432 return !download_item.IsTemporary();
412 } 433 }
413 434
414 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to 435 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to
415 // the off-record DownloadManager if one exists and is requested via 436 // the off-record DownloadManager if one exists and is requested via
416 // |include_incognito|. This should work regardless of whether |profile| is 437 // |include_incognito|. This should work regardless of whether |profile| is
417 // original or incognito. 438 // original or incognito.
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1961 return; 1982 return;
1962 base::Time now(base::Time::Now()); 1983 base::Time now(base::Time::Now());
1963 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT(); 1984 int delta = now.ToTimeT() - last_checked_removal_.ToTimeT();
1964 if (delta <= kFileExistenceRateLimitSeconds) 1985 if (delta <= kFileExistenceRateLimitSeconds)
1965 return; 1986 return;
1966 last_checked_removal_ = now; 1987 last_checked_removal_ = now;
1967 manager->CheckForHistoryFilesRemoval(); 1988 manager->CheckForHistoryFilesRemoval();
1968 } 1989 }
1969 1990
1970 } // namespace extensions 1991 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698