Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor_tables.cc |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor_tables.cc b/chrome/browser/predictors/resource_prefetch_predictor_tables.cc |
| index 710325c29397cc661d42149b1af184cdff8f8472..061941d72ac92a3eaa07eb93c31983cc0c912029 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor_tables.cc |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.cc |
| @@ -310,14 +310,9 @@ void ResourcePrefetchPredictorTables::GetAllResourceDataHelper( |
| PrefetchData data; |
| std::string key; |
| while (StepAndInitializeProtoData(&resource_reader, &key, &data)) { |
| - data_map->insert(std::make_pair(key, data)); |
| + data_map->insert({key, data}); |
| DCHECK_EQ(data.primary_key(), key); |
| } |
| - |
| - // Sort each of the resource vectors by score. |
| - for (auto& kv : *data_map) { |
|
alexilin
2017/04/21 12:07:28
Resources are written to the database already sort
Benoit L
2017/04/25 08:59:21
Unless the sorting function changes, right?
alexilin
2017/04/25 13:04:25
We could return this statement back if sorting fun
Benoit L
2017/04/25 15:12:39
Acknowledged.
|
| - SortResources(&(kv.second)); |
| - } |
| } |
| void ResourcePrefetchPredictorTables::GetAllRedirectDataHelper( |
| @@ -331,7 +326,7 @@ void ResourcePrefetchPredictorTables::GetAllRedirectDataHelper( |
| RedirectData data; |
| std::string key; |
| while (StepAndInitializeProtoData(&redirect_reader, &key, &data)) { |
| - data_map->insert(std::make_pair(key, data)); |
| + data_map->insert({key, data}); |
| DCHECK_EQ(data.primary_key(), key); |
| } |
| } |
| @@ -345,7 +340,7 @@ void ResourcePrefetchPredictorTables::GetAllManifestDataHelper( |
| precache::PrecacheManifest data; |
| std::string key; |
| while (StepAndInitializeProtoData(&manifest_reader, &key, &data)) { |
| - manifest_map->insert(std::make_pair(key, data)); |
| + manifest_map->insert({key, data}); |
| } |
| } |
| @@ -447,6 +442,31 @@ float ResourcePrefetchPredictorTables::ComputeResourceScore( |
| data.average_position(); |
| } |
| +// static |
| +float ResourcePrefetchPredictorTables::ComputePrecacheResourceScore( |
| + const precache::PrecacheResource& resource) { |
| + int type_multiplier; |
| + switch (resource.type()) { |
|
Benoit L
2017/04/25 08:59:21
Can we make that consistent with the other scoring
alexilin
2017/04/25 17:37:05
Done.
|
| + case precache::PrecacheResource::RESOURCE_TYPE_FONT: |
| + type_multiplier = 4; |
| + break; |
| + case precache::PrecacheResource::RESOURCE_TYPE_STYLESHEET: |
| + type_multiplier = 3; |
| + break; |
| + case precache::PrecacheResource::RESOURCE_TYPE_SCRIPT: |
| + type_multiplier = 2; |
| + break; |
| + case precache::PrecacheResource::RESOURCE_TYPE_IMAGE: |
| + type_multiplier = 1; |
| + break; |
| + default: |
| + type_multiplier = 0; |
| + } |
| + |
| + return type_multiplier * 10 + resource.weight_ratio(); |
| +} |
| + |
| +// static |
| float ResourcePrefetchPredictorTables::ComputeOriginScore( |
| const OriginStat& origin) { |
| // The ranking is done by considering, in this order: |