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 635573005: Cleanup: Better constify some strings in chrome/browser/{chromeos,extensions}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, nit Created 6 years, 1 month 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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const char kStateInterrupted[] = "interrupted"; 160 const char kStateInterrupted[] = "interrupted";
161 const char kStateKey[] = "state"; 161 const char kStateKey[] = "state";
162 const char kTotalBytesGreaterKey[] = "totalBytesGreater"; 162 const char kTotalBytesGreaterKey[] = "totalBytesGreater";
163 const char kTotalBytesKey[] = "totalBytes"; 163 const char kTotalBytesKey[] = "totalBytes";
164 const char kTotalBytesLessKey[] = "totalBytesLess"; 164 const char kTotalBytesLessKey[] = "totalBytesLess";
165 const char kUrlKey[] = "url"; 165 const char kUrlKey[] = "url";
166 const char kUrlRegexKey[] = "urlRegex"; 166 const char kUrlRegexKey[] = "urlRegex";
167 167
168 // Note: Any change to the danger type strings, should be accompanied by a 168 // Note: Any change to the danger type strings, should be accompanied by a
169 // corresponding change to downloads.json. 169 // corresponding change to downloads.json.
170 const char* kDangerStrings[] = { 170 const char* const kDangerStrings[] = {
171 kDangerSafe, 171 kDangerSafe,
172 kDangerFile, 172 kDangerFile,
173 kDangerUrl, 173 kDangerUrl,
174 kDangerContent, 174 kDangerContent,
175 kDangerSafe, 175 kDangerSafe,
176 kDangerUncommon, 176 kDangerUncommon,
177 kDangerAccepted, 177 kDangerAccepted,
178 kDangerHost, 178 kDangerHost,
179 kDangerUnwanted 179 kDangerUnwanted
180 }; 180 };
181 COMPILE_ASSERT(arraysize(kDangerStrings) == content::DOWNLOAD_DANGER_TYPE_MAX, 181 COMPILE_ASSERT(arraysize(kDangerStrings) == content::DOWNLOAD_DANGER_TYPE_MAX,
182 download_danger_type_enum_changed); 182 download_danger_type_enum_changed);
183 183
184 // Note: Any change to the state strings, should be accompanied by a 184 // Note: Any change to the state strings, should be accompanied by a
185 // corresponding change to downloads.json. 185 // corresponding change to downloads.json.
186 const char* kStateStrings[] = { 186 const char* const kStateStrings[] = {
187 kStateInProgress, 187 kStateInProgress,
188 kStateComplete, 188 kStateComplete,
189 kStateInterrupted, 189 kStateInterrupted,
190 kStateInterrupted, 190 kStateInterrupted,
191 }; 191 };
192 COMPILE_ASSERT(arraysize(kStateStrings) == DownloadItem::MAX_DOWNLOAD_STATE, 192 COMPILE_ASSERT(arraysize(kStateStrings) == DownloadItem::MAX_DOWNLOAD_STATE,
193 download_item_state_enum_changed); 193 download_item_state_enum_changed);
194 194
195 const char* DangerString(content::DownloadDangerType danger) { 195 const char* DangerString(content::DownloadDangerType danger) {
196 DCHECK(danger >= 0); 196 DCHECK(danger >= 0);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 case 16: return IconLoader::SMALL; 340 case 16: return IconLoader::SMALL;
341 case 32: return IconLoader::NORMAL; 341 case 32: return IconLoader::NORMAL;
342 default: 342 default:
343 NOTREACHED(); 343 NOTREACHED();
344 return IconLoader::NORMAL; 344 return IconLoader::NORMAL;
345 } 345 }
346 } 346 }
347 347
348 typedef base::hash_map<std::string, DownloadQuery::FilterType> FilterTypeMap; 348 typedef base::hash_map<std::string, DownloadQuery::FilterType> FilterTypeMap;
349 349
350 void InitFilterTypeMap(FilterTypeMap& filter_types) { 350 void InitFilterTypeMap(FilterTypeMap* filter_types_ptr) {
351 FilterTypeMap& filter_types = *filter_types_ptr;
351 filter_types[kBytesReceivedKey] = DownloadQuery::FILTER_BYTES_RECEIVED; 352 filter_types[kBytesReceivedKey] = DownloadQuery::FILTER_BYTES_RECEIVED;
352 filter_types[kExistsKey] = DownloadQuery::FILTER_EXISTS; 353 filter_types[kExistsKey] = DownloadQuery::FILTER_EXISTS;
353 filter_types[kFilenameKey] = DownloadQuery::FILTER_FILENAME; 354 filter_types[kFilenameKey] = DownloadQuery::FILTER_FILENAME;
354 filter_types[kFilenameRegexKey] = DownloadQuery::FILTER_FILENAME_REGEX; 355 filter_types[kFilenameRegexKey] = DownloadQuery::FILTER_FILENAME_REGEX;
355 filter_types[kMimeKey] = DownloadQuery::FILTER_MIME; 356 filter_types[kMimeKey] = DownloadQuery::FILTER_MIME;
356 filter_types[kPausedKey] = DownloadQuery::FILTER_PAUSED; 357 filter_types[kPausedKey] = DownloadQuery::FILTER_PAUSED;
357 filter_types[kQueryKey] = DownloadQuery::FILTER_QUERY; 358 filter_types[kQueryKey] = DownloadQuery::FILTER_QUERY;
358 filter_types[kEndedAfterKey] = DownloadQuery::FILTER_ENDED_AFTER; 359 filter_types[kEndedAfterKey] = DownloadQuery::FILTER_ENDED_AFTER;
359 filter_types[kEndedBeforeKey] = DownloadQuery::FILTER_ENDED_BEFORE; 360 filter_types[kEndedBeforeKey] = DownloadQuery::FILTER_ENDED_BEFORE;
360 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME; 361 filter_types[kEndTimeKey] = DownloadQuery::FILTER_END_TIME;
361 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER; 362 filter_types[kStartedAfterKey] = DownloadQuery::FILTER_STARTED_AFTER;
362 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE; 363 filter_types[kStartedBeforeKey] = DownloadQuery::FILTER_STARTED_BEFORE;
363 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME; 364 filter_types[kStartTimeKey] = DownloadQuery::FILTER_START_TIME;
364 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES; 365 filter_types[kTotalBytesKey] = DownloadQuery::FILTER_TOTAL_BYTES;
365 filter_types[kTotalBytesGreaterKey] = 366 filter_types[kTotalBytesGreaterKey] =
366 DownloadQuery::FILTER_TOTAL_BYTES_GREATER; 367 DownloadQuery::FILTER_TOTAL_BYTES_GREATER;
367 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS; 368 filter_types[kTotalBytesLessKey] = DownloadQuery::FILTER_TOTAL_BYTES_LESS;
368 filter_types[kUrlKey] = DownloadQuery::FILTER_URL; 369 filter_types[kUrlKey] = DownloadQuery::FILTER_URL;
369 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX; 370 filter_types[kUrlRegexKey] = DownloadQuery::FILTER_URL_REGEX;
370 } 371 }
371 372
372 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap; 373 typedef base::hash_map<std::string, DownloadQuery::SortType> SortTypeMap;
373 374
374 void InitSortTypeMap(SortTypeMap& sorter_types) { 375 void InitSortTypeMap(SortTypeMap* sorter_types_ptr) {
376 SortTypeMap& sorter_types = *sorter_types_ptr;
375 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED; 377 sorter_types[kBytesReceivedKey] = DownloadQuery::SORT_BYTES_RECEIVED;
376 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER; 378 sorter_types[kDangerKey] = DownloadQuery::SORT_DANGER;
377 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME; 379 sorter_types[kEndTimeKey] = DownloadQuery::SORT_END_TIME;
378 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS; 380 sorter_types[kExistsKey] = DownloadQuery::SORT_EXISTS;
379 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME; 381 sorter_types[kFilenameKey] = DownloadQuery::SORT_FILENAME;
380 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME; 382 sorter_types[kMimeKey] = DownloadQuery::SORT_MIME;
381 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED; 383 sorter_types[kPausedKey] = DownloadQuery::SORT_PAUSED;
382 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; 384 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME;
383 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; 385 sorter_types[kStateKey] = DownloadQuery::SORT_STATE;
384 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; 386 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 449 }
448 450
449 void CompileDownloadQueryOrderBy( 451 void CompileDownloadQueryOrderBy(
450 const std::vector<std::string>& order_by_strs, 452 const std::vector<std::string>& order_by_strs,
451 std::string* error, 453 std::string* error,
452 DownloadQuery* query) { 454 DownloadQuery* query) {
453 // TODO(benjhayden): Consider switching from LazyInstance to explicit string 455 // TODO(benjhayden): Consider switching from LazyInstance to explicit string
454 // comparisons. 456 // comparisons.
455 static base::LazyInstance<SortTypeMap> sorter_types = 457 static base::LazyInstance<SortTypeMap> sorter_types =
456 LAZY_INSTANCE_INITIALIZER; 458 LAZY_INSTANCE_INITIALIZER;
457 if (sorter_types.Get().size() == 0) 459 if (sorter_types.Get().empty())
458 InitSortTypeMap(sorter_types.Get()); 460 InitSortTypeMap(sorter_types.Pointer());
459 461
460 for (std::vector<std::string>::const_iterator iter = order_by_strs.begin(); 462 for (std::vector<std::string>::const_iterator iter = order_by_strs.begin();
461 iter != order_by_strs.end(); ++iter) { 463 iter != order_by_strs.end(); ++iter) {
462 std::string term_str = *iter; 464 std::string term_str = *iter;
463 if (term_str.empty()) 465 if (term_str.empty())
464 continue; 466 continue;
465 DownloadQuery::SortDirection direction = DownloadQuery::ASCENDING; 467 DownloadQuery::SortDirection direction = DownloadQuery::ASCENDING;
466 if (term_str[0] == '-') { 468 if (term_str[0] == '-') {
467 direction = DownloadQuery::DESCENDING; 469 direction = DownloadQuery::DESCENDING;
468 term_str = term_str.substr(1); 470 term_str = term_str.substr(1);
(...skipping 11 matching lines...) Expand all
480 void RunDownloadQuery( 482 void RunDownloadQuery(
481 const downloads::DownloadQuery& query_in, 483 const downloads::DownloadQuery& query_in,
482 DownloadManager* manager, 484 DownloadManager* manager,
483 DownloadManager* incognito_manager, 485 DownloadManager* incognito_manager,
484 std::string* error, 486 std::string* error,
485 DownloadQuery::DownloadVector* results) { 487 DownloadQuery::DownloadVector* results) {
486 // TODO(benjhayden): Consider switching from LazyInstance to explicit string 488 // TODO(benjhayden): Consider switching from LazyInstance to explicit string
487 // comparisons. 489 // comparisons.
488 static base::LazyInstance<FilterTypeMap> filter_types = 490 static base::LazyInstance<FilterTypeMap> filter_types =
489 LAZY_INSTANCE_INITIALIZER; 491 LAZY_INSTANCE_INITIALIZER;
490 if (filter_types.Get().size() == 0) 492 if (filter_types.Get().empty())
491 InitFilterTypeMap(filter_types.Get()); 493 InitFilterTypeMap(filter_types.Pointer());
492 494
493 DownloadQuery query_out; 495 DownloadQuery query_out;
494 496
495 size_t limit = 1000; 497 size_t limit = 1000;
496 if (query_in.limit.get()) { 498 if (query_in.limit.get()) {
497 if (*query_in.limit.get() < 0) { 499 if (*query_in.limit.get() < 0) {
498 *error = errors::kInvalidQueryLimit; 500 *error = errors::kInvalidQueryLimit;
499 return; 501 return;
500 } 502 }
501 limit = *query_in.limit.get(); 503 limit = *query_in.limit.get();
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 const Extension* extension, 1932 const Extension* extension,
1931 UnloadedExtensionInfo::Reason reason) { 1933 UnloadedExtensionInfo::Reason reason) {
1932 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1934 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1933 std::set<const Extension*>::iterator iter = 1935 std::set<const Extension*>::iterator iter =
1934 shelf_disabling_extensions_.find(extension); 1936 shelf_disabling_extensions_.find(extension);
1935 if (iter != shelf_disabling_extensions_.end()) 1937 if (iter != shelf_disabling_extensions_.end())
1936 shelf_disabling_extensions_.erase(iter); 1938 shelf_disabling_extensions_.erase(iter);
1937 } 1939 }
1938 1940
1939 } // namespace extensions 1941 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698