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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_tables.cc

Issue 2397943004: predictors: Use redirect data in prefetch. (Closed)
Patch Set: Non-empty check. Created 4 years, 2 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 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_tables.h" 5 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 auto new_end = 108 auto new_end =
109 std::remove_if(data->mutable_redirect_endpoints()->begin(), 109 std::remove_if(data->mutable_redirect_endpoints()->begin(),
110 data->mutable_redirect_endpoints()->end(), 110 data->mutable_redirect_endpoints()->end(),
111 [max_consecutive_misses](const RedirectStat& x) { 111 [max_consecutive_misses](const RedirectStat& x) {
112 return x.consecutive_misses() >= max_consecutive_misses; 112 return x.consecutive_misses() >= max_consecutive_misses;
113 }); 113 });
114 data->mutable_redirect_endpoints()->erase( 114 data->mutable_redirect_endpoints()->erase(
115 new_end, data->mutable_redirect_endpoints()->end()); 115 new_end, data->mutable_redirect_endpoints()->end());
116 } 116 }
117 117
118 // static
119 void ResourcePrefetchPredictorTables::SortRedirects(RedirectData* data) {
120 std::sort(data->mutable_redirect_endpoints()->begin(),
121 data->mutable_redirect_endpoints()->end(),
122 [](const RedirectStat& x, const RedirectStat& y) {
123 // Decreasing score ordering.
124 return ComputeRedirectScore(x) > ComputeRedirectScore(y);
125 });
126 }
127
128 void ResourcePrefetchPredictorTables::GetAllData( 118 void ResourcePrefetchPredictorTables::GetAllData(
129 PrefetchDataMap* url_data_map, 119 PrefetchDataMap* url_data_map,
130 PrefetchDataMap* host_data_map, 120 PrefetchDataMap* host_data_map,
131 RedirectDataMap* url_redirect_data_map, 121 RedirectDataMap* url_redirect_data_map,
132 RedirectDataMap* host_redirect_data_map) { 122 RedirectDataMap* host_redirect_data_map) {
133 DCHECK_CURRENTLY_ON(BrowserThread::DB); 123 DCHECK_CURRENTLY_ON(BrowserThread::DB);
134 if (CantAccessDatabase()) 124 if (CantAccessDatabase())
135 return; 125 return;
136 126
137 DCHECK(url_data_map); 127 DCHECK(url_data_map);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 const char* table_name = GetTableName(key_type, PrefetchDataType::REDIRECT); 271 const char* table_name = GetTableName(key_type, PrefetchDataType::REDIRECT);
282 Statement redirect_reader(DB()->GetUniqueStatement( 272 Statement redirect_reader(DB()->GetUniqueStatement(
283 base::StringPrintf("SELECT * FROM %s", table_name).c_str())); 273 base::StringPrintf("SELECT * FROM %s", table_name).c_str()));
284 274
285 RedirectData data; 275 RedirectData data;
286 std::string key; 276 std::string key;
287 while (StepAndInitializeProtoData(&redirect_reader, &key, &data)) { 277 while (StepAndInitializeProtoData(&redirect_reader, &key, &data)) {
288 data_map->insert(std::make_pair(key, data)); 278 data_map->insert(std::make_pair(key, data));
289 DCHECK_EQ(data.primary_key(), key); 279 DCHECK_EQ(data.primary_key(), key);
290 } 280 }
291
292 // Sort each of the redirect vectors by score.
293 for (auto& kv : *data_map) {
294 SortRedirects(&(kv.second));
295 }
296 } 281 }
297 282
298 bool ResourcePrefetchPredictorTables::UpdateDataHelper( 283 bool ResourcePrefetchPredictorTables::UpdateDataHelper(
299 PrefetchKeyType key_type, 284 PrefetchKeyType key_type,
300 PrefetchDataType data_type, 285 PrefetchDataType data_type,
301 const std::string& key, 286 const std::string& key,
302 const MessageLite& data) { 287 const MessageLite& data) {
303 // Delete the older data from the table. 288 // Delete the older data from the table.
304 std::unique_ptr<Statement> deleter( 289 std::unique_ptr<Statement> deleter(
305 GetTableUpdateStatement(key_type, data_type, TableOperationType::REMOVE)); 290 GetTableUpdateStatement(key_type, data_type, TableOperationType::REMOVE));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 type_multiplier = 1; 350 type_multiplier = 1;
366 } 351 }
367 352
368 constexpr int kMaxResourcesPerType = 100; 353 constexpr int kMaxResourcesPerType = 100;
369 return kMaxResourcesPerType * 354 return kMaxResourcesPerType *
370 (priority_multiplier * 100 + type_multiplier * 10) - 355 (priority_multiplier * 100 + type_multiplier * 10) -
371 data.average_position(); 356 data.average_position();
372 } 357 }
373 358
374 // static 359 // static
375 float ResourcePrefetchPredictorTables::ComputeRedirectScore(
376 const RedirectStat& data) {
377 // TODO(alexilin): Invent some scoring.
378 return 0.0;
379 }
380
381 // static
382 bool ResourcePrefetchPredictorTables::DropTablesIfOutdated( 360 bool ResourcePrefetchPredictorTables::DropTablesIfOutdated(
383 sql::Connection* db) { 361 sql::Connection* db) {
384 int version = GetDatabaseVersion(db); 362 int version = GetDatabaseVersion(db);
385 bool success = true; 363 bool success = true;
386 // Too new is also a problem. 364 // Too new is also a problem.
387 bool incompatible_version = version != kDatabaseVersion; 365 bool incompatible_version = version != kDatabaseVersion;
388 366
389 // These are deprecated tables but they still have to be removed if present. 367 // These are deprecated tables but they still have to be removed if present.
390 const char kUrlMetadataTableName[] = 368 const char kUrlMetadataTableName[] =
391 "resource_prefetch_predictor_url_metadata"; 369 "resource_prefetch_predictor_url_metadata";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 return is_host ? kHostResourceTableName : kUrlResourceTableName; 495 return is_host ? kHostResourceTableName : kUrlResourceTableName;
518 case PrefetchDataType::REDIRECT: 496 case PrefetchDataType::REDIRECT:
519 return is_host ? kHostRedirectTableName : kUrlRedirectTableName; 497 return is_host ? kHostRedirectTableName : kUrlRedirectTableName;
520 } 498 }
521 499
522 NOTREACHED(); 500 NOTREACHED();
523 return nullptr; 501 return nullptr;
524 } 502 }
525 503
526 } // namespace predictors 504 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698