| 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/safe_browsing/safe_browsing_store_file.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
| 6 | 6 |
| 7 #include "base/md5.h" | 7 #include "base/md5.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 return false; | 469 return false; |
| 470 | 470 |
| 471 ++chunks_written_; | 471 ++chunks_written_; |
| 472 | 472 |
| 473 // Clear everything to save memory. | 473 // Clear everything to save memory. |
| 474 return ClearChunkBuffers(); | 474 return ClearChunkBuffers(); |
| 475 } | 475 } |
| 476 | 476 |
| 477 bool SafeBrowsingStoreFile::DoUpdate( | 477 bool SafeBrowsingStoreFile::DoUpdate( |
| 478 const std::vector<SBAddFullHash>& pending_adds, | 478 const std::vector<SBAddFullHash>& pending_adds, |
| 479 const std::set<SBPrefix>& prefix_misses, | |
| 480 SBAddPrefixes* add_prefixes_result, | 479 SBAddPrefixes* add_prefixes_result, |
| 481 std::vector<SBAddFullHash>* add_full_hashes_result) { | 480 std::vector<SBAddFullHash>* add_full_hashes_result) { |
| 482 DCHECK(file_.get() || empty_); | 481 DCHECK(file_.get() || empty_); |
| 483 DCHECK(new_file_.get()); | 482 DCHECK(new_file_.get()); |
| 484 CHECK(add_prefixes_result); | 483 CHECK(add_prefixes_result); |
| 485 CHECK(add_full_hashes_result); | 484 CHECK(add_full_hashes_result); |
| 486 | 485 |
| 487 SBAddPrefixes add_prefixes; | 486 SBAddPrefixes add_prefixes; |
| 488 SBSubPrefixes sub_prefixes; | 487 SBSubPrefixes sub_prefixes; |
| 489 std::vector<SBAddFullHash> add_full_hashes; | 488 std::vector<SBAddFullHash> add_full_hashes; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 new_file_.get(), NULL) || | 592 new_file_.get(), NULL) || |
| 594 !ReadToContainer(&sub_full_hashes, header.sub_hash_count, | 593 !ReadToContainer(&sub_full_hashes, header.sub_hash_count, |
| 595 new_file_.get(), NULL)) | 594 new_file_.get(), NULL)) |
| 596 return false; | 595 return false; |
| 597 } | 596 } |
| 598 | 597 |
| 599 // Append items from |pending_adds|. | 598 // Append items from |pending_adds|. |
| 600 add_full_hashes.insert(add_full_hashes.end(), | 599 add_full_hashes.insert(add_full_hashes.end(), |
| 601 pending_adds.begin(), pending_adds.end()); | 600 pending_adds.begin(), pending_adds.end()); |
| 602 | 601 |
| 603 // Check how often a prefix was checked which wasn't in the | |
| 604 // database. | |
| 605 SBCheckPrefixMisses(add_prefixes, prefix_misses); | |
| 606 | |
| 607 // Knock the subs from the adds and process deleted chunks. | 602 // Knock the subs from the adds and process deleted chunks. |
| 608 SBProcessSubs(&add_prefixes, &sub_prefixes, | 603 SBProcessSubs(&add_prefixes, &sub_prefixes, |
| 609 &add_full_hashes, &sub_full_hashes, | 604 &add_full_hashes, &sub_full_hashes, |
| 610 add_del_cache_, sub_del_cache_); | 605 add_del_cache_, sub_del_cache_); |
| 611 | 606 |
| 612 // We no longer need to track deleted chunks. | 607 // We no longer need to track deleted chunks. |
| 613 DeleteChunksFromSet(add_del_cache_, &add_chunks_cache_); | 608 DeleteChunksFromSet(add_del_cache_, &add_chunks_cache_); |
| 614 DeleteChunksFromSet(sub_del_cache_, &sub_chunks_cache_); | 609 DeleteChunksFromSet(sub_del_cache_, &sub_chunks_cache_); |
| 615 | 610 |
| 616 // Write the new data to new_file_. | 611 // Write the new data to new_file_. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 663 |
| 669 // Pass the resulting data off to the caller. | 664 // Pass the resulting data off to the caller. |
| 670 add_prefixes_result->swap(add_prefixes); | 665 add_prefixes_result->swap(add_prefixes); |
| 671 add_full_hashes_result->swap(add_full_hashes); | 666 add_full_hashes_result->swap(add_full_hashes); |
| 672 | 667 |
| 673 return true; | 668 return true; |
| 674 } | 669 } |
| 675 | 670 |
| 676 bool SafeBrowsingStoreFile::FinishUpdate( | 671 bool SafeBrowsingStoreFile::FinishUpdate( |
| 677 const std::vector<SBAddFullHash>& pending_adds, | 672 const std::vector<SBAddFullHash>& pending_adds, |
| 678 const std::set<SBPrefix>& prefix_misses, | |
| 679 SBAddPrefixes* add_prefixes_result, | 673 SBAddPrefixes* add_prefixes_result, |
| 680 std::vector<SBAddFullHash>* add_full_hashes_result) { | 674 std::vector<SBAddFullHash>* add_full_hashes_result) { |
| 681 DCHECK(add_prefixes_result); | 675 DCHECK(add_prefixes_result); |
| 682 DCHECK(add_full_hashes_result); | 676 DCHECK(add_full_hashes_result); |
| 683 | 677 |
| 684 bool ret = DoUpdate(pending_adds, prefix_misses, | 678 if (!DoUpdate(pending_adds, add_prefixes_result, add_full_hashes_result)) { |
| 685 add_prefixes_result, add_full_hashes_result); | |
| 686 | |
| 687 if (!ret) { | |
| 688 CancelUpdate(); | 679 CancelUpdate(); |
| 689 return false; | 680 return false; |
| 690 } | 681 } |
| 691 | 682 |
| 692 DCHECK(!new_file_.get()); | 683 DCHECK(!new_file_.get()); |
| 693 DCHECK(!file_.get()); | 684 DCHECK(!file_.get()); |
| 694 | 685 |
| 695 return Close(); | 686 return Close(); |
| 696 } | 687 } |
| 697 | 688 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 // With SQLite support gone, one way to get to this code is if the | 742 // With SQLite support gone, one way to get to this code is if the |
| 752 // existing file is a SQLite file. Make sure the journal file is | 743 // existing file is a SQLite file. Make sure the journal file is |
| 753 // also removed. | 744 // also removed. |
| 754 const base::FilePath journal_filename( | 745 const base::FilePath journal_filename( |
| 755 basename.value() + FILE_PATH_LITERAL("-journal")); | 746 basename.value() + FILE_PATH_LITERAL("-journal")); |
| 756 if (base::PathExists(journal_filename)) | 747 if (base::PathExists(journal_filename)) |
| 757 base::DeleteFile(journal_filename, false); | 748 base::DeleteFile(journal_filename, false); |
| 758 | 749 |
| 759 return true; | 750 return true; |
| 760 } | 751 } |
| OLD | NEW |