| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <fstream> | 9 #include <fstream> |
| 10 #include <numeric> |
| 10 | 11 |
| 11 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/i18n/case_conversion.h" | 16 #include "base/i18n/case_conversion.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 | 732 |
| 732 struct ItemGroup { | 733 struct ItemGroup { |
| 733 history::URLID min_id; | 734 history::URLID min_id; |
| 734 history::URLID max_id; | 735 history::URLID max_id; |
| 735 int typed_count; | 736 int typed_count; |
| 736 int visit_count; | 737 int visit_count; |
| 737 base::TimeDelta days_ago; | 738 base::TimeDelta days_ago; |
| 738 }; | 739 }; |
| 739 | 740 |
| 740 auto GetHistoryIdsUpTo = [&](HistoryID max) { | 741 auto GetHistoryIdsUpTo = [&](HistoryID max) { |
| 741 HistoryIDSet res; | 742 HistoryIDVector res(max - kMinRowId); |
| 742 // All ids are inserted in the end so the implicit hint would work. | 743 std::iota(res.begin(), res.end(), kMinRowId); |
| 743 for (HistoryID id = kMinRowId; id < max; ++id) | |
| 744 res.insert(id); | |
| 745 return res; | 744 return res; |
| 746 }; | 745 }; |
| 747 | 746 |
| 748 auto CountGroupElementsInIds = [](const ItemGroup& group, | 747 auto CountGroupElementsInIds = [](const ItemGroup& group, |
| 749 const HistoryIDSet& ids) { | 748 const HistoryIDVector& ids) { |
| 750 return std::count_if(ids.begin(), ids.end(), [&](history::URLID id) { | 749 return std::count_if(ids.begin(), ids.end(), [&](history::URLID id) { |
| 751 return group.min_id <= id && id < group.max_id; | 750 return group.min_id <= id && id < group.max_id; |
| 752 }); | 751 }); |
| 753 }; | 752 }; |
| 754 | 753 |
| 755 // Test body -------------------------------------------------------------- | 754 // Test body -------------------------------------------------------------- |
| 756 | 755 |
| 757 // Groups of items ordered by increasing priority. | 756 // Groups of items ordered by increasing priority. |
| 758 ItemGroup item_groups[] = { | 757 ItemGroup item_groups[] = { |
| 759 {0, 0, kLowTypedCount, kLowVisitCount, kOld}, | 758 {0, 0, kLowTypedCount, kLowVisitCount, kOld}, |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); | 1441 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); |
| 1443 std::vector<base::FilePath::StringType> actual_parts; | 1442 std::vector<base::FilePath::StringType> actual_parts; |
| 1444 full_file_path.GetComponents(&actual_parts); | 1443 full_file_path.GetComponents(&actual_parts); |
| 1445 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1444 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
| 1446 size_t count = expected_parts.size(); | 1445 size_t count = expected_parts.size(); |
| 1447 for (size_t i = 0; i < count; ++i) | 1446 for (size_t i = 0; i < count; ++i) |
| 1448 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1447 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
| 1449 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1448 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
| 1450 set_history_dir(base::FilePath()); | 1449 set_history_dir(base::FilePath()); |
| 1451 } | 1450 } |
| OLD | NEW |