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

Side by Side Diff: components/safe_browsing_db/v4_store.cc

Issue 2231753002: components: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more call site Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // Update the iterator map, which means that we have merged one hash 412 // Update the iterator map, which means that we have merged one hash
413 // prefix of size |next_size_for_old| from the old store. 413 // prefix of size |next_size_for_old| from the old store.
414 old_iterator_map[next_smallest_prefix_size] += next_smallest_prefix_size; 414 old_iterator_map[next_smallest_prefix_size] += next_smallest_prefix_size;
415 415
416 if (!raw_removals || removals_iter == raw_removals->end() || 416 if (!raw_removals || removals_iter == raw_removals->end() ||
417 *removals_iter != total_picked_from_old) { 417 *removals_iter != total_picked_from_old) {
418 // Append the smallest hash to the appropriate list. 418 // Append the smallest hash to the appropriate list.
419 hash_prefix_map_[next_smallest_prefix_size] += next_smallest_prefix_old; 419 hash_prefix_map_[next_smallest_prefix_size] += next_smallest_prefix_old;
420 420
421 if (calculate_checksum) { 421 if (calculate_checksum) {
422 checksum_ctx->Update(string_as_array(&next_smallest_prefix_old), 422 checksum_ctx->Update(base::string_as_array(&next_smallest_prefix_old),
423 next_smallest_prefix_size); 423 next_smallest_prefix_size);
424 } 424 }
425 } else { 425 } else {
426 // Element not added to new map. Move the removals iterator forward. 426 // Element not added to new map. Move the removals iterator forward.
427 removals_iter++; 427 removals_iter++;
428 } 428 }
429 429
430 total_picked_from_old++; 430 total_picked_from_old++;
431 431
432 // Find the next smallest unmerged element in the old store's map. 432 // Find the next smallest unmerged element in the old store's map.
433 old_has_unmerged = GetNextSmallestUnmergedPrefix( 433 old_has_unmerged = GetNextSmallestUnmergedPrefix(
434 old_prefixes_map, old_iterator_map, &next_smallest_prefix_old); 434 old_prefixes_map, old_iterator_map, &next_smallest_prefix_old);
435 } else { 435 } else {
436 next_smallest_prefix_size = next_smallest_prefix_additions.size(); 436 next_smallest_prefix_size = next_smallest_prefix_additions.size();
437 437
438 // Append the smallest hash to the appropriate list. 438 // Append the smallest hash to the appropriate list.
439 hash_prefix_map_[next_smallest_prefix_size] += 439 hash_prefix_map_[next_smallest_prefix_size] +=
440 next_smallest_prefix_additions; 440 next_smallest_prefix_additions;
441 441
442 if (calculate_checksum) { 442 if (calculate_checksum) {
443 checksum_ctx->Update(string_as_array(&next_smallest_prefix_additions), 443 checksum_ctx->Update(
444 next_smallest_prefix_size); 444 base::string_as_array(&next_smallest_prefix_additions),
445 next_smallest_prefix_size);
445 } 446 }
446 447
447 // Update the iterator map, which means that we have merged one hash 448 // Update the iterator map, which means that we have merged one hash
448 // prefix of size |next_smallest_prefix_size| from the update. 449 // prefix of size |next_smallest_prefix_size| from the update.
449 additions_iterator_map[next_smallest_prefix_size] += 450 additions_iterator_map[next_smallest_prefix_size] +=
450 next_smallest_prefix_size; 451 next_smallest_prefix_size;
451 452
452 // Find the next smallest unmerged element in the additions map. 453 // Find the next smallest unmerged element in the additions map.
453 additions_has_unmerged = 454 additions_has_unmerged =
454 GetNextSmallestUnmergedPrefix(additions_map, additions_iterator_map, 455 GetNextSmallestUnmergedPrefix(additions_map, additions_iterator_map,
455 &next_smallest_prefix_additions); 456 &next_smallest_prefix_additions);
456 } 457 }
457 } 458 }
458 459
459 if (raw_removals && removals_iter != raw_removals->end()) { 460 if (raw_removals && removals_iter != raw_removals->end()) {
460 return REMOVALS_INDEX_TOO_LARGE_FAILURE; 461 return REMOVALS_INDEX_TOO_LARGE_FAILURE;
461 } 462 }
462 463
463 if (calculate_checksum) { 464 if (calculate_checksum) {
464 std::string checksum(crypto::kSHA256Length, 0); 465 std::string checksum(crypto::kSHA256Length, 0);
465 checksum_ctx->Finish(string_as_array(&checksum), checksum.size()); 466 checksum_ctx->Finish(base::string_as_array(&checksum), checksum.size());
466 if (checksum != expected_checksum) { 467 if (checksum != expected_checksum) {
467 std::string checksum_base64, expected_checksum_base64; 468 std::string checksum_base64, expected_checksum_base64;
468 base::Base64Encode(checksum, &checksum_base64); 469 base::Base64Encode(checksum, &checksum_base64);
469 base::Base64Encode(expected_checksum, &expected_checksum_base64); 470 base::Base64Encode(expected_checksum, &expected_checksum_base64);
470 DVLOG(1) << "Checksum failed: calculated: " << checksum_base64 471 DVLOG(1) << "Checksum failed: calculated: " << checksum_base64
471 << "expected: " << expected_checksum_base64; 472 << "expected: " << expected_checksum_base64;
472 return CHECKSUM_MISMATCH_FAILURE; 473 return CHECKSUM_MISMATCH_FAILURE;
473 } 474 }
474 } 475 }
475 476
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 if (result == 0) { 594 if (result == 0) {
594 return true; 595 return true;
595 } else if (result < 0) { 596 } else if (result < 0) {
596 return HashPrefixMatches(hash_prefix, begin, mid); 597 return HashPrefixMatches(hash_prefix, begin, mid);
597 } else { 598 } else {
598 return HashPrefixMatches(hash_prefix, mid + prefix_size, end); 599 return HashPrefixMatches(hash_prefix, mid + prefix_size, end);
599 } 600 }
600 } 601 }
601 602
602 } // namespace safe_browsing 603 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/database_manager.cc ('k') | components/search_engines/default_search_policy_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698