| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 if (iterator != host_table_cache_->end()) | 514 if (iterator != host_table_cache_->end()) |
| 515 PopulatePrefetcherRequest(iterator->second, urls); | 515 PopulatePrefetcherRequest(iterator->second, urls); |
| 516 } | 516 } |
| 517 | 517 |
| 518 return !urls->empty(); | 518 return !urls->empty(); |
| 519 } | 519 } |
| 520 | 520 |
| 521 void ResourcePrefetchPredictor::PopulatePrefetcherRequest( | 521 void ResourcePrefetchPredictor::PopulatePrefetcherRequest( |
| 522 const PrefetchData& data, | 522 const PrefetchData& data, |
| 523 std::vector<GURL>* urls) { | 523 std::vector<GURL>* urls) { |
| 524 for (const ResourceData& resource : data.resources) { | 524 for (const ResourceData& resource : data.resources()) { |
| 525 float confidence = | 525 float confidence = |
| 526 static_cast<float>(resource.number_of_hits()) / | 526 static_cast<float>(resource.number_of_hits()) / |
| 527 (resource.number_of_hits() + resource.number_of_misses()); | 527 (resource.number_of_hits() + resource.number_of_misses()); |
| 528 if (confidence < config_.min_resource_confidence_to_trigger_prefetch || | 528 if (confidence < config_.min_resource_confidence_to_trigger_prefetch || |
| 529 resource.number_of_hits() < | 529 resource.number_of_hits() < |
| 530 config_.min_resource_hits_to_trigger_prefetch) { | 530 config_.min_resource_hits_to_trigger_prefetch) { |
| 531 continue; | 531 continue; |
| 532 } | 532 } |
| 533 | 533 |
| 534 urls->push_back(GURL(resource.resource_url())); | 534 urls->push_back(GURL(resource.resource_url())); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 tables_, url_redirects_to_delete, host_redirects_to_delete)); | 704 tables_, url_redirects_to_delete, host_redirects_to_delete)); |
| 705 } | 705 } |
| 706 } | 706 } |
| 707 | 707 |
| 708 void ResourcePrefetchPredictor::RemoveOldestEntryInPrefetchDataMap( | 708 void ResourcePrefetchPredictor::RemoveOldestEntryInPrefetchDataMap( |
| 709 PrefetchKeyType key_type, | 709 PrefetchKeyType key_type, |
| 710 PrefetchDataMap* data_map) { | 710 PrefetchDataMap* data_map) { |
| 711 if (data_map->empty()) | 711 if (data_map->empty()) |
| 712 return; | 712 return; |
| 713 | 713 |
| 714 base::Time oldest_time; | 714 uint64_t oldest_time = UINT64_MAX; |
| 715 std::string key_to_delete; | 715 std::string key_to_delete; |
| 716 for (PrefetchDataMap::iterator it = data_map->begin(); | 716 for (const auto& kv : *data_map) { |
| 717 it != data_map->end(); ++it) { | 717 const PrefetchData& data = kv.second; |
| 718 if (key_to_delete.empty() || it->second.last_visit < oldest_time) { | 718 if (key_to_delete.empty() || data.last_visit_time() < oldest_time) { |
| 719 key_to_delete = it->first; | 719 key_to_delete = data.primary_key(); |
| 720 oldest_time = it->second.last_visit; | 720 oldest_time = data.last_visit_time(); |
| 721 } | 721 } |
| 722 } | 722 } |
| 723 | 723 |
| 724 data_map->erase(key_to_delete); | 724 data_map->erase(key_to_delete); |
| 725 BrowserThread::PostTask( | 725 BrowserThread::PostTask( |
| 726 BrowserThread::DB, FROM_HERE, | 726 BrowserThread::DB, FROM_HERE, |
| 727 base::Bind( | 727 base::Bind( |
| 728 &ResourcePrefetchPredictorTables::DeleteSingleResourceDataPoint, | 728 &ResourcePrefetchPredictorTables::DeleteSingleResourceDataPoint, |
| 729 tables_, key_to_delete, key_type)); | 729 tables_, key_to_delete, key_type)); |
| 730 } | 730 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 // If the primary key is too long reject it. | 802 // If the primary key is too long reject it. |
| 803 if (key.length() > ResourcePrefetchPredictorTables::kMaxStringLength) | 803 if (key.length() > ResourcePrefetchPredictorTables::kMaxStringLength) |
| 804 return; | 804 return; |
| 805 | 805 |
| 806 PrefetchDataMap::iterator cache_entry = data_map->find(key); | 806 PrefetchDataMap::iterator cache_entry = data_map->find(key); |
| 807 if (cache_entry == data_map->end()) { | 807 if (cache_entry == data_map->end()) { |
| 808 // If the table is full, delete an entry. | 808 // If the table is full, delete an entry. |
| 809 if (data_map->size() >= max_data_map_size) | 809 if (data_map->size() >= max_data_map_size) |
| 810 RemoveOldestEntryInPrefetchDataMap(key_type, data_map); | 810 RemoveOldestEntryInPrefetchDataMap(key_type, data_map); |
| 811 | 811 |
| 812 cache_entry = data_map->insert(std::make_pair( | 812 cache_entry = data_map->insert(std::make_pair(key, PrefetchData())).first; |
| 813 key, PrefetchData(key_type, key))).first; | 813 PrefetchData& data = cache_entry->second; |
| 814 cache_entry->second.last_visit = base::Time::Now(); | 814 data.set_primary_key(key); |
| 815 data.set_last_visit_time(base::Time::Now().ToInternalValue()); |
| 815 size_t new_resources_size = new_resources.size(); | 816 size_t new_resources_size = new_resources.size(); |
| 816 std::set<GURL> resources_seen; | 817 std::set<GURL> resources_seen; |
| 817 for (size_t i = 0; i < new_resources_size; ++i) { | 818 for (size_t i = 0; i < new_resources_size; ++i) { |
| 818 if (resources_seen.find(new_resources[i].resource_url) != | 819 const URLRequestSummary& summary = new_resources[i]; |
| 819 resources_seen.end()) { | 820 if (resources_seen.find(summary.resource_url) != resources_seen.end()) |
| 820 continue; | 821 continue; |
| 821 } | 822 |
| 822 ResourceData resource_to_add; | 823 ResourceData* resource_to_add = data.add_resources(); |
| 823 resource_to_add.set_resource_url(new_resources[i].resource_url.spec()); | 824 resource_to_add->set_resource_url(summary.resource_url.spec()); |
| 824 resource_to_add.set_resource_type(static_cast<ResourceData::ResourceType>( | 825 resource_to_add->set_resource_type( |
| 825 new_resources[i].resource_type)); | 826 static_cast<ResourceData::ResourceType>(summary.resource_type)); |
| 826 resource_to_add.set_number_of_hits(1); | 827 resource_to_add->set_number_of_hits(1); |
| 827 resource_to_add.set_average_position(i + 1); | 828 resource_to_add->set_average_position(i + 1); |
| 828 resource_to_add.set_priority( | 829 resource_to_add->set_priority( |
| 829 static_cast<ResourceData::Priority>(new_resources[i].priority)); | 830 static_cast<ResourceData::Priority>(summary.priority)); |
| 830 resource_to_add.set_has_validators(new_resources[i].has_validators); | 831 resource_to_add->set_has_validators(summary.has_validators); |
| 831 resource_to_add.set_always_revalidate(new_resources[i].always_revalidate); | 832 resource_to_add->set_always_revalidate(summary.always_revalidate); |
| 832 cache_entry->second.resources.push_back(resource_to_add); | 833 |
| 833 resources_seen.insert(new_resources[i].resource_url); | 834 resources_seen.insert(summary.resource_url); |
| 834 } | 835 } |
| 835 } else { | 836 } else { |
| 836 std::vector<ResourceData>& old_resources = cache_entry->second.resources; | 837 PrefetchData& data = cache_entry->second; |
| 837 cache_entry->second.last_visit = base::Time::Now(); | 838 data.set_last_visit_time(base::Time::Now().ToInternalValue()); |
| 838 | 839 |
| 839 // Build indices over the data. | 840 // Build indices over the data. |
| 840 std::map<GURL, int> new_index, old_index; | 841 std::map<GURL, int> new_index, old_index; |
| 841 int new_resources_size = static_cast<int>(new_resources.size()); | 842 int new_resources_size = static_cast<int>(new_resources.size()); |
| 842 for (int i = 0; i < new_resources_size; ++i) { | 843 for (int i = 0; i < new_resources_size; ++i) { |
| 843 const URLRequestSummary& summary = new_resources[i]; | 844 const URLRequestSummary& summary = new_resources[i]; |
| 844 // Take the first occurence of every url. | 845 // Take the first occurence of every url. |
| 845 if (new_index.find(summary.resource_url) == new_index.end()) | 846 if (new_index.find(summary.resource_url) == new_index.end()) |
| 846 new_index[summary.resource_url] = i; | 847 new_index[summary.resource_url] = i; |
| 847 } | 848 } |
| 848 int old_resources_size = static_cast<int>(old_resources.size()); | 849 int old_resources_size = static_cast<int>(data.resources_size()); |
| 849 for (int i = 0; i < old_resources_size; ++i) { | 850 for (int i = 0; i < old_resources_size; ++i) { |
| 850 const ResourceData& resource = old_resources[i]; | 851 bool is_new = |
| 851 GURL resource_url(resource.resource_url()); | 852 old_index |
| 852 DCHECK(old_index.find(resource_url) == old_index.end()); | 853 .insert(std::make_pair(GURL(data.resources(i).resource_url()), i)) |
| 853 old_index[resource_url] = i; | 854 .second; |
| 855 DCHECK(is_new); |
| 854 } | 856 } |
| 855 | 857 |
| 856 // Go through the old urls and update their hit/miss counts. | 858 // Go through the old urls and update their hit/miss counts. |
| 857 for (int i = 0; i < old_resources_size; ++i) { | 859 for (int i = 0; i < old_resources_size; ++i) { |
| 858 ResourceData& old_resource = old_resources[i]; | 860 ResourceData* old_resource = data.mutable_resources(i); |
| 859 GURL resource_url(old_resource.resource_url()); | 861 GURL resource_url(old_resource->resource_url()); |
| 860 if (new_index.find(resource_url) == new_index.end()) { | 862 if (new_index.find(resource_url) == new_index.end()) { |
| 861 old_resource.set_number_of_misses(old_resource.number_of_misses() + 1); | 863 old_resource->set_number_of_misses(old_resource->number_of_misses() + |
| 862 old_resource.set_consecutive_misses(old_resource.consecutive_misses() + | 864 1); |
| 863 1); | 865 old_resource->set_consecutive_misses( |
| 866 old_resource->consecutive_misses() + 1); |
| 864 } else { | 867 } else { |
| 865 const URLRequestSummary& new_summary = | 868 const URLRequestSummary& new_summary = |
| 866 new_resources[new_index[resource_url]]; | 869 new_resources[new_index[resource_url]]; |
| 867 | 870 |
| 868 // Update the resource type since it could have changed. | 871 // Update the resource type since it could have changed. |
| 869 if (new_summary.resource_type != content::RESOURCE_TYPE_LAST_TYPE) | 872 if (new_summary.resource_type != content::RESOURCE_TYPE_LAST_TYPE) { |
| 870 old_resource.set_resource_type( | 873 old_resource->set_resource_type( |
| 871 static_cast<ResourceData::ResourceType>( | 874 static_cast<ResourceData::ResourceType>( |
| 872 new_summary.resource_type)); | 875 new_summary.resource_type)); |
| 876 } |
| 873 | 877 |
| 874 old_resource.set_priority( | 878 old_resource->set_priority( |
| 875 static_cast<ResourceData::Priority>(new_summary.priority)); | 879 static_cast<ResourceData::Priority>(new_summary.priority)); |
| 876 | 880 |
| 877 int position = new_index[resource_url] + 1; | 881 int position = new_index[resource_url] + 1; |
| 878 int total = | 882 int total = |
| 879 old_resource.number_of_hits() + old_resource.number_of_misses(); | 883 old_resource->number_of_hits() + old_resource->number_of_misses(); |
| 880 old_resource.set_average_position( | 884 old_resource->set_average_position( |
| 881 ((old_resource.average_position() * total) + position) / | 885 ((old_resource->average_position() * total) + position) / |
| 882 (total + 1)); | 886 (total + 1)); |
| 883 old_resource.set_number_of_hits(old_resource.number_of_hits() + 1); | 887 old_resource->set_number_of_hits(old_resource->number_of_hits() + 1); |
| 884 old_resource.set_consecutive_misses(0); | 888 old_resource->set_consecutive_misses(0); |
| 885 } | 889 } |
| 886 } | 890 } |
| 887 | 891 |
| 888 // Add the new ones that we have not seen before. | 892 // Add the new ones that we have not seen before. |
| 889 for (int i = 0; i < new_resources_size; ++i) { | 893 for (int i = 0; i < new_resources_size; ++i) { |
| 890 const URLRequestSummary& summary = new_resources[i]; | 894 const URLRequestSummary& summary = new_resources[i]; |
| 891 if (old_index.find(summary.resource_url) != old_index.end()) | 895 if (old_index.find(summary.resource_url) != old_index.end()) |
| 892 continue; | 896 continue; |
| 893 | 897 |
| 894 // Only need to add new stuff. | 898 // Only need to add new stuff. |
| 895 ResourceData resource_to_add; | 899 ResourceData* resource_to_add = data.add_resources(); |
| 896 resource_to_add.set_resource_url(summary.resource_url.spec()); | 900 resource_to_add->set_resource_url(summary.resource_url.spec()); |
| 897 resource_to_add.set_resource_type( | 901 resource_to_add->set_resource_type( |
| 898 static_cast<ResourceData::ResourceType>(summary.resource_type)); | 902 static_cast<ResourceData::ResourceType>(summary.resource_type)); |
| 899 resource_to_add.set_number_of_hits(1); | 903 resource_to_add->set_number_of_hits(1); |
| 900 resource_to_add.set_average_position(i + 1); | 904 resource_to_add->set_average_position(i + 1); |
| 901 resource_to_add.set_priority( | 905 resource_to_add->set_priority( |
| 902 static_cast<ResourceData::Priority>(summary.priority)); | 906 static_cast<ResourceData::Priority>(summary.priority)); |
| 903 resource_to_add.set_has_validators(new_resources[i].has_validators); | 907 resource_to_add->set_has_validators(new_resources[i].has_validators); |
| 904 resource_to_add.set_always_revalidate(new_resources[i].always_revalidate); | 908 resource_to_add->set_always_revalidate( |
| 905 old_resources.push_back(resource_to_add); | 909 new_resources[i].always_revalidate); |
| 906 | 910 |
| 907 // To ensure we dont add the same url twice. | 911 // To ensure we dont add the same url twice. |
| 908 old_index[summary.resource_url] = 0; | 912 old_index[summary.resource_url] = 0; |
| 909 } | 913 } |
| 910 } | 914 } |
| 911 | 915 |
| 916 PrefetchData& data = cache_entry->second; |
| 912 // Trim and sort the resources after the update. | 917 // Trim and sort the resources after the update. |
| 913 std::vector<ResourceData>& resources = cache_entry->second.resources; | 918 ResourcePrefetchPredictorTables::TrimResources( |
| 914 for (auto it = resources.begin(); it != resources.end();) { | 919 &data, config_.max_consecutive_misses); |
| 915 if (it->consecutive_misses() >= config_.max_consecutive_misses) | 920 ResourcePrefetchPredictorTables::SortResources(&data); |
| 916 it = resources.erase(it); | 921 if (data.resources_size() > |
| 917 else | 922 static_cast<int>(config_.max_resources_per_entry)) { |
| 918 ++it; | 923 data.mutable_resources()->DeleteSubrange( |
| 924 config_.max_resources_per_entry, |
| 925 data.resources_size() - config_.max_resources_per_entry); |
| 919 } | 926 } |
| 920 ResourcePrefetchPredictorTables::SortResources(&resources); | |
| 921 if (resources.size() > config_.max_resources_per_entry) | |
| 922 resources.resize(config_.max_resources_per_entry); | |
| 923 | 927 |
| 924 // If the row has no resources, remove it from the cache and delete the | 928 // If the row has no resources, remove it from the cache and delete the |
| 925 // entry in the database. Else update the database. | 929 // entry in the database. Else update the database. |
| 926 if (resources.empty()) { | 930 if (data.resources_size() == 0) { |
| 927 data_map->erase(key); | 931 data_map->erase(key); |
| 928 BrowserThread::PostTask( | 932 BrowserThread::PostTask( |
| 929 BrowserThread::DB, FROM_HERE, | 933 BrowserThread::DB, FROM_HERE, |
| 930 base::Bind( | 934 base::Bind( |
| 931 &ResourcePrefetchPredictorTables::DeleteSingleResourceDataPoint, | 935 &ResourcePrefetchPredictorTables::DeleteSingleResourceDataPoint, |
| 932 tables_, key, key_type)); | 936 tables_, key, key_type)); |
| 933 } else { | 937 } else { |
| 938 PrefetchData empty_data; |
| 939 RedirectData empty_redirect_data; |
| 934 bool is_host = key_type == PREFETCH_KEY_TYPE_HOST; | 940 bool is_host = key_type == PREFETCH_KEY_TYPE_HOST; |
| 935 PrefetchData empty_data( | 941 const PrefetchData& host_data = is_host ? data : empty_data; |
| 936 !is_host ? PREFETCH_KEY_TYPE_HOST : PREFETCH_KEY_TYPE_URL, | 942 const PrefetchData& url_data = is_host ? empty_data : data; |
| 937 std::string()); | |
| 938 RedirectData empty_redirect_data; | |
| 939 const PrefetchData& host_data = is_host ? cache_entry->second : empty_data; | |
| 940 const PrefetchData& url_data = is_host ? empty_data : cache_entry->second; | |
| 941 BrowserThread::PostTask( | 943 BrowserThread::PostTask( |
| 942 BrowserThread::DB, FROM_HERE, | 944 BrowserThread::DB, FROM_HERE, |
| 943 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, tables_, | 945 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, tables_, |
| 944 url_data, host_data, empty_redirect_data, | 946 url_data, host_data, empty_redirect_data, |
| 945 empty_redirect_data)); | 947 empty_redirect_data)); |
| 946 } | 948 } |
| 947 | 949 |
| 948 if (key != key_before_redirects) { | 950 if (key != key_before_redirects) { |
| 949 LearnRedirect(key_before_redirects, key_type, key, max_data_map_size, | 951 LearnRedirect(key_before_redirects, key_type, key, max_data_map_size, |
| 950 redirect_map); | 952 redirect_map); |
| 951 } | 953 } |
| 952 } | 954 } |
| 953 | 955 |
| 954 void ResourcePrefetchPredictor::LearnRedirect(const std::string& key, | 956 void ResourcePrefetchPredictor::LearnRedirect(const std::string& key, |
| 955 PrefetchKeyType key_type, | 957 PrefetchKeyType key_type, |
| 956 const std::string& final_redirect, | 958 const std::string& final_redirect, |
| 957 size_t max_redirect_map_size, | 959 size_t max_redirect_map_size, |
| 958 RedirectDataMap* redirect_map) { | 960 RedirectDataMap* redirect_map) { |
| 959 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 961 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 962 // If the primary key is too long reject it. |
| 963 if (key.length() > ResourcePrefetchPredictorTables::kMaxStringLength) |
| 964 return; |
| 960 | 965 |
| 961 RedirectDataMap::iterator cache_entry = redirect_map->find(key); | 966 RedirectDataMap::iterator cache_entry = redirect_map->find(key); |
| 962 if (cache_entry == redirect_map->end()) { | 967 if (cache_entry == redirect_map->end()) { |
| 963 if (redirect_map->size() >= max_redirect_map_size) | 968 if (redirect_map->size() >= max_redirect_map_size) |
| 964 RemoveOldestEntryInRedirectDataMap(key_type, redirect_map); | 969 RemoveOldestEntryInRedirectDataMap(key_type, redirect_map); |
| 965 | 970 |
| 966 RedirectData new_data; | 971 cache_entry = |
| 967 new_data.set_primary_key(key); | 972 redirect_map->insert(std::make_pair(key, RedirectData())).first; |
| 968 cache_entry = redirect_map->insert(std::make_pair(key, new_data)).first; | 973 RedirectData& data = cache_entry->second; |
| 969 cache_entry->second.set_last_visit_time( | 974 data.set_primary_key(key); |
| 970 base::Time::Now().ToInternalValue()); | 975 data.set_last_visit_time(base::Time::Now().ToInternalValue()); |
| 971 RedirectStat* redirect_to_add = | 976 RedirectStat* redirect_to_add = data.add_redirect_endpoints(); |
| 972 cache_entry->second.add_redirect_endpoints(); | |
| 973 redirect_to_add->set_url(final_redirect); | 977 redirect_to_add->set_url(final_redirect); |
| 974 redirect_to_add->set_number_of_hits(1); | 978 redirect_to_add->set_number_of_hits(1); |
| 975 } else { | 979 } else { |
| 980 RedirectData& data = cache_entry->second; |
| 981 data.set_last_visit_time(base::Time::Now().ToInternalValue()); |
| 982 |
| 976 bool need_to_add = true; | 983 bool need_to_add = true; |
| 977 cache_entry->second.set_last_visit_time( | 984 for (RedirectStat& redirect : *(data.mutable_redirect_endpoints())) { |
| 978 base::Time::Now().ToInternalValue()); | |
| 979 | |
| 980 for (RedirectStat& redirect : | |
| 981 *(cache_entry->second.mutable_redirect_endpoints())) { | |
| 982 if (redirect.url() == final_redirect) { | 985 if (redirect.url() == final_redirect) { |
| 983 need_to_add = false; | 986 need_to_add = false; |
| 984 redirect.set_number_of_hits(redirect.number_of_hits() + 1); | 987 redirect.set_number_of_hits(redirect.number_of_hits() + 1); |
| 985 redirect.set_consecutive_misses(0); | 988 redirect.set_consecutive_misses(0); |
| 986 } else { | 989 } else { |
| 987 redirect.set_number_of_misses(redirect.number_of_misses() + 1); | 990 redirect.set_number_of_misses(redirect.number_of_misses() + 1); |
| 988 redirect.set_consecutive_misses(redirect.consecutive_misses() + 1); | 991 redirect.set_consecutive_misses(redirect.consecutive_misses() + 1); |
| 989 } | 992 } |
| 990 } | 993 } |
| 991 | 994 |
| 992 if (need_to_add) { | 995 if (need_to_add) { |
| 993 RedirectStat* redirect_to_add = | 996 RedirectStat* redirect_to_add = data.add_redirect_endpoints(); |
| 994 cache_entry->second.add_redirect_endpoints(); | |
| 995 redirect_to_add->set_url(final_redirect); | 997 redirect_to_add->set_url(final_redirect); |
| 996 redirect_to_add->set_number_of_hits(1); | 998 redirect_to_add->set_number_of_hits(1); |
| 997 } | 999 } |
| 998 } | 1000 } |
| 999 | 1001 |
| 1000 // Trim and sort redirects after update. | 1002 RedirectData& data = cache_entry->second; |
| 1001 std::vector<RedirectStat> redirects; | 1003 // Trim and sort the redirects after the update. |
| 1002 redirects.reserve(cache_entry->second.redirect_endpoints_size()); | 1004 ResourcePrefetchPredictorTables::TrimRedirects( |
| 1003 for (const RedirectStat& redirect : | 1005 &data, config_.max_consecutive_misses); |
| 1004 cache_entry->second.redirect_endpoints()) { | 1006 ResourcePrefetchPredictorTables::SortRedirects(&data); |
| 1005 if (redirect.consecutive_misses() < config_.max_consecutive_misses) | |
| 1006 redirects.push_back(redirect); | |
| 1007 } | |
| 1008 ResourcePrefetchPredictorTables::SortRedirects(&redirects); | |
| 1009 | 1007 |
| 1010 cache_entry->second.clear_redirect_endpoints(); | 1008 if (data.redirect_endpoints_size() == 0) { |
| 1011 for (const RedirectStat& redirect : redirects) | |
| 1012 cache_entry->second.add_redirect_endpoints()->CopyFrom(redirect); | |
| 1013 | |
| 1014 if (redirects.empty()) { | |
| 1015 redirect_map->erase(cache_entry); | 1009 redirect_map->erase(cache_entry); |
| 1016 BrowserThread::PostTask( | 1010 BrowserThread::PostTask( |
| 1017 BrowserThread::DB, FROM_HERE, | 1011 BrowserThread::DB, FROM_HERE, |
| 1018 base::Bind( | 1012 base::Bind( |
| 1019 &ResourcePrefetchPredictorTables::DeleteSingleRedirectDataPoint, | 1013 &ResourcePrefetchPredictorTables::DeleteSingleRedirectDataPoint, |
| 1020 tables_, key, key_type)); | 1014 tables_, key, key_type)); |
| 1021 } else { | 1015 } else { |
| 1016 RedirectData empty_redirect_data; |
| 1017 PrefetchData empty_data; |
| 1022 bool is_host = key_type == PREFETCH_KEY_TYPE_HOST; | 1018 bool is_host = key_type == PREFETCH_KEY_TYPE_HOST; |
| 1023 RedirectData empty_redirect_data; | |
| 1024 PrefetchData empty_url_data(PREFETCH_KEY_TYPE_URL, std::string()); | |
| 1025 PrefetchData empty_host_data(PREFETCH_KEY_TYPE_HOST, std::string()); | |
| 1026 const RedirectData& host_redirect_data = | 1019 const RedirectData& host_redirect_data = |
| 1027 is_host ? cache_entry->second : empty_redirect_data; | 1020 is_host ? data : empty_redirect_data; |
| 1028 const RedirectData& url_redirect_data = | 1021 const RedirectData& url_redirect_data = |
| 1029 is_host ? empty_redirect_data : cache_entry->second; | 1022 is_host ? empty_redirect_data : data; |
| 1030 BrowserThread::PostTask( | 1023 BrowserThread::PostTask( |
| 1031 BrowserThread::DB, FROM_HERE, | 1024 BrowserThread::DB, FROM_HERE, |
| 1032 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, tables_, | 1025 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, tables_, |
| 1033 empty_url_data, empty_host_data, url_redirect_data, | 1026 empty_data, empty_data, url_redirect_data, |
| 1034 host_redirect_data)); | 1027 host_redirect_data)); |
| 1035 } | 1028 } |
| 1036 } | 1029 } |
| 1037 | 1030 |
| 1038 void ResourcePrefetchPredictor::OnURLsDeleted( | 1031 void ResourcePrefetchPredictor::OnURLsDeleted( |
| 1039 history::HistoryService* history_service, | 1032 history::HistoryService* history_service, |
| 1040 bool all_history, | 1033 bool all_history, |
| 1041 bool expired, | 1034 bool expired, |
| 1042 const history::URLRows& deleted_rows, | 1035 const history::URLRows& deleted_rows, |
| 1043 const std::set<GURL>& favicon_urls) { | 1036 const std::set<GURL>& favicon_urls) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 // HistoryService is already loaded. Continue with Initialization. | 1068 // HistoryService is already loaded. Continue with Initialization. |
| 1076 OnHistoryAndCacheLoaded(); | 1069 OnHistoryAndCacheLoaded(); |
| 1077 return; | 1070 return; |
| 1078 } | 1071 } |
| 1079 DCHECK(!history_service_observer_.IsObserving(history_service)); | 1072 DCHECK(!history_service_observer_.IsObserving(history_service)); |
| 1080 history_service_observer_.Add(history_service); | 1073 history_service_observer_.Add(history_service); |
| 1081 return; | 1074 return; |
| 1082 } | 1075 } |
| 1083 | 1076 |
| 1084 } // namespace predictors | 1077 } // namespace predictors |
| OLD | NEW |