| 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_tables.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 6 | 6 |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <algorithm> | 7 #include <algorithm> |
| 10 #include <memory> | |
| 11 #include <utility> | 8 #include <utility> |
| 12 | 9 |
| 13 #include "base/logging.h" | 10 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 16 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 17 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 18 #include "sql/meta_table.h" | |
| 19 #include "sql/statement.h" | 15 #include "sql/statement.h" |
| 20 #include "sql/transaction.h" | |
| 21 | 16 |
| 22 using content::BrowserThread; | 17 using google::protobuf::MessageLite; |
| 23 using sql::Statement; | |
| 24 | 18 |
| 25 namespace { | 19 namespace { |
| 26 | 20 |
| 27 using PrefetchData = predictors::PrefetchData; | |
| 28 using RedirectData = predictors::RedirectData; | |
| 29 using ::google::protobuf::MessageLite; | |
| 30 | |
| 31 const char kMetadataTableName[] = "resource_prefetch_predictor_metadata"; | 21 const char kMetadataTableName[] = "resource_prefetch_predictor_metadata"; |
| 32 const char kUrlResourceTableName[] = "resource_prefetch_predictor_url"; | 22 const char kUrlResourceTableName[] = "resource_prefetch_predictor_url"; |
| 33 const char kUrlRedirectTableName[] = "resource_prefetch_predictor_url_redirect"; | 23 const char kUrlRedirectTableName[] = "resource_prefetch_predictor_url_redirect"; |
| 34 const char kHostResourceTableName[] = "resource_prefetch_predictor_host"; | 24 const char kHostResourceTableName[] = "resource_prefetch_predictor_host"; |
| 35 const char kHostRedirectTableName[] = | 25 const char kHostRedirectTableName[] = |
| 36 "resource_prefetch_predictor_host_redirect"; | 26 "resource_prefetch_predictor_host_redirect"; |
| 37 | 27 |
| 38 const char kCreateGlobalMetadataStatementTemplate[] = | 28 const char kCreateGlobalMetadataStatementTemplate[] = |
| 39 "CREATE TABLE %s ( " | 29 "CREATE TABLE %s ( " |
| 40 "key TEXT, value INTEGER, " | 30 "key TEXT, value INTEGER, " |
| 41 "PRIMARY KEY (key))"; | 31 "PRIMARY KEY (key))"; |
| 42 const char kCreateProtoTableStatementTemplate[] = | 32 const char kCreateProtoTableStatementTemplate[] = |
| 43 "CREATE TABLE %s ( " | 33 "CREATE TABLE %s ( " |
| 44 "key TEXT, " | 34 "key TEXT, " |
| 45 "proto BLOB, " | 35 "proto BLOB, " |
| 46 "PRIMARY KEY(key))"; | 36 "PRIMARY KEY(key))"; |
| 47 const char kInsertProtoTableStatementTemplate[] = | 37 const char kInsertProtoTableStatementTemplate[] = |
| 48 "INSERT INTO %s (key, proto) VALUES (?,?)"; | 38 "INSERT INTO %s (key, proto) VALUES (?,?)"; |
| 49 const char kDeleteProtoTableStatementTemplate[] = "DELETE FROM %s WHERE key=?"; | 39 const char kDeleteProtoTableStatementTemplate[] = "DELETE FROM %s WHERE key=?"; |
| 50 | 40 |
| 51 void BindProtoDataToStatement(const std::string& key, | 41 void BindProtoDataToStatement(const std::string& key, |
| 52 const MessageLite& data, | 42 const MessageLite& data, |
| 53 Statement* statement) { | 43 sql::Statement* statement) { |
| 54 int size = data.ByteSize(); | 44 int size = data.ByteSize(); |
| 55 DCHECK_GT(size, 0); | 45 DCHECK_GT(size, 0); |
| 56 std::vector<char> proto_buffer(size); | 46 std::vector<char> proto_buffer(size); |
| 57 data.SerializeToArray(&proto_buffer[0], size); | 47 data.SerializeToArray(&proto_buffer[0], size); |
| 58 | 48 |
| 59 statement->BindString(0, key); | 49 statement->BindString(0, key); |
| 60 statement->BindBlob(1, &proto_buffer[0], size); | 50 statement->BindBlob(1, &proto_buffer[0], size); |
| 61 } | 51 } |
| 62 | 52 |
| 63 bool StepAndInitializeProtoData(Statement* statement, | 53 bool StepAndInitializeProtoData(sql::Statement* statement, |
| 64 std::string* key, | 54 std::string* key, |
| 65 MessageLite* data) { | 55 MessageLite* data) { |
| 66 if (!statement->Step()) | 56 if (!statement->Step()) |
| 67 return false; | 57 return false; |
| 68 | 58 |
| 69 *key = statement->ColumnString(0); | 59 *key = statement->ColumnString(0); |
| 70 | 60 |
| 71 int size = statement->ColumnByteLength(1); | 61 int size = statement->ColumnByteLength(1); |
| 72 const void* blob = statement->ColumnBlob(1); | 62 const void* blob = statement->ColumnBlob(1); |
| 73 DCHECK(blob); | 63 DCHECK(blob); |
| 74 data->ParseFromArray(blob, size); | 64 data->ParseFromArray(blob, size); |
| 75 | 65 |
| 76 return true; | 66 return true; |
| 77 } | 67 } |
| 78 | 68 |
| 79 } // namespace | 69 } // namespace |
| 80 | 70 |
| 81 namespace predictors { | 71 namespace predictors { |
| 82 | 72 |
| 73 using content::BrowserThread; |
| 74 |
| 83 // static | 75 // static |
| 84 void ResourcePrefetchPredictorTables::TrimResources( | 76 void ResourcePrefetchPredictorTables::TrimResources( |
| 85 PrefetchData* data, | 77 PrefetchData* data, |
| 86 size_t max_consecutive_misses) { | 78 size_t max_consecutive_misses) { |
| 87 auto new_end = std::remove_if( | 79 auto new_end = std::remove_if( |
| 88 data->mutable_resources()->begin(), data->mutable_resources()->end(), | 80 data->mutable_resources()->begin(), data->mutable_resources()->end(), |
| 89 [max_consecutive_misses](const ResourceData& x) { | 81 [max_consecutive_misses](const ResourceData& x) { |
| 90 return x.consecutive_misses() >= max_consecutive_misses; | 82 return x.consecutive_misses() >= max_consecutive_misses; |
| 91 }); | 83 }); |
| 92 data->mutable_resources()->erase(new_end, data->mutable_resources()->end()); | 84 data->mutable_resources()->erase(new_end, data->mutable_resources()->end()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return; | 216 return; |
| 225 | 217 |
| 226 DeleteDataHelper(key_type, PrefetchDataType::REDIRECT, {key}); | 218 DeleteDataHelper(key_type, PrefetchDataType::REDIRECT, {key}); |
| 227 } | 219 } |
| 228 | 220 |
| 229 void ResourcePrefetchPredictorTables::DeleteAllData() { | 221 void ResourcePrefetchPredictorTables::DeleteAllData() { |
| 230 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 222 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 231 if (CantAccessDatabase()) | 223 if (CantAccessDatabase()) |
| 232 return; | 224 return; |
| 233 | 225 |
| 234 Statement deleter; | 226 sql::Statement deleter; |
| 235 for (const char* table_name : | 227 for (const char* table_name : |
| 236 {kUrlResourceTableName, kUrlRedirectTableName, kHostResourceTableName, | 228 {kUrlResourceTableName, kUrlRedirectTableName, kHostResourceTableName, |
| 237 kHostRedirectTableName}) { | 229 kHostRedirectTableName}) { |
| 238 deleter.Assign(DB()->GetUniqueStatement( | 230 deleter.Assign(DB()->GetUniqueStatement( |
| 239 base::StringPrintf("DELETE FROM %s", table_name).c_str())); | 231 base::StringPrintf("DELETE FROM %s", table_name).c_str())); |
| 240 deleter.Run(); | 232 deleter.Run(); |
| 241 } | 233 } |
| 242 } | 234 } |
| 243 | 235 |
| 244 ResourcePrefetchPredictorTables::ResourcePrefetchPredictorTables() | 236 ResourcePrefetchPredictorTables::ResourcePrefetchPredictorTables() {} |
| 245 : PredictorTableBase() {} | |
| 246 | 237 |
| 247 ResourcePrefetchPredictorTables::~ResourcePrefetchPredictorTables() {} | 238 ResourcePrefetchPredictorTables::~ResourcePrefetchPredictorTables() {} |
| 248 | 239 |
| 249 void ResourcePrefetchPredictorTables::GetAllResourceDataHelper( | 240 void ResourcePrefetchPredictorTables::GetAllResourceDataHelper( |
| 250 PrefetchKeyType key_type, | 241 PrefetchKeyType key_type, |
| 251 PrefetchDataMap* data_map) { | 242 PrefetchDataMap* data_map) { |
| 252 // Read the resources table and organize it per primary key. | 243 // Read the resources table and organize it per primary key. |
| 253 const char* table_name = GetTableName(key_type, PrefetchDataType::RESOURCE); | 244 const char* table_name = GetTableName(key_type, PrefetchDataType::RESOURCE); |
| 254 Statement resource_reader(DB()->GetUniqueStatement( | 245 sql::Statement resource_reader(DB()->GetUniqueStatement( |
| 255 base::StringPrintf("SELECT * FROM %s", table_name).c_str())); | 246 base::StringPrintf("SELECT * FROM %s", table_name).c_str())); |
| 256 | 247 |
| 257 PrefetchData data; | 248 PrefetchData data; |
| 258 std::string key; | 249 std::string key; |
| 259 while (StepAndInitializeProtoData(&resource_reader, &key, &data)) { | 250 while (StepAndInitializeProtoData(&resource_reader, &key, &data)) { |
| 260 data_map->insert(std::make_pair(key, data)); | 251 data_map->insert(std::make_pair(key, data)); |
| 261 DCHECK_EQ(data.primary_key(), key); | 252 DCHECK_EQ(data.primary_key(), key); |
| 262 } | 253 } |
| 263 | 254 |
| 264 // Sort each of the resource vectors by score. | 255 // Sort each of the resource vectors by score. |
| 265 for (auto& kv : *data_map) { | 256 for (auto& kv : *data_map) { |
| 266 SortResources(&(kv.second)); | 257 SortResources(&(kv.second)); |
| 267 } | 258 } |
| 268 } | 259 } |
| 269 | 260 |
| 270 void ResourcePrefetchPredictorTables::GetAllRedirectDataHelper( | 261 void ResourcePrefetchPredictorTables::GetAllRedirectDataHelper( |
| 271 PrefetchKeyType key_type, | 262 PrefetchKeyType key_type, |
| 272 RedirectDataMap* data_map) { | 263 RedirectDataMap* data_map) { |
| 273 // Read the redirects table and organize it per primary key. | 264 // Read the redirects table and organize it per primary key. |
| 274 const char* table_name = GetTableName(key_type, PrefetchDataType::REDIRECT); | 265 const char* table_name = GetTableName(key_type, PrefetchDataType::REDIRECT); |
| 275 Statement redirect_reader(DB()->GetUniqueStatement( | 266 sql::Statement redirect_reader(DB()->GetUniqueStatement( |
| 276 base::StringPrintf("SELECT * FROM %s", table_name).c_str())); | 267 base::StringPrintf("SELECT * FROM %s", table_name).c_str())); |
| 277 | 268 |
| 278 RedirectData data; | 269 RedirectData data; |
| 279 std::string key; | 270 std::string key; |
| 280 while (StepAndInitializeProtoData(&redirect_reader, &key, &data)) { | 271 while (StepAndInitializeProtoData(&redirect_reader, &key, &data)) { |
| 281 data_map->insert(std::make_pair(key, data)); | 272 data_map->insert(std::make_pair(key, data)); |
| 282 DCHECK_EQ(data.primary_key(), key); | 273 DCHECK_EQ(data.primary_key(), key); |
| 283 } | 274 } |
| 284 } | 275 } |
| 285 | 276 |
| 286 bool ResourcePrefetchPredictorTables::UpdateDataHelper( | 277 bool ResourcePrefetchPredictorTables::UpdateDataHelper( |
| 287 PrefetchKeyType key_type, | 278 PrefetchKeyType key_type, |
| 288 PrefetchDataType data_type, | 279 PrefetchDataType data_type, |
| 289 const std::string& key, | 280 const std::string& key, |
| 290 const MessageLite& data) { | 281 const MessageLite& data) { |
| 291 // Delete the older data from the table. | 282 // Delete the older data from the table. |
| 292 std::unique_ptr<Statement> deleter( | 283 std::unique_ptr<sql::Statement> deleter( |
| 293 GetTableUpdateStatement(key_type, data_type, TableOperationType::REMOVE)); | 284 GetTableUpdateStatement(key_type, data_type, TableOperationType::REMOVE)); |
| 294 deleter->BindString(0, key); | 285 deleter->BindString(0, key); |
| 295 if (!deleter->Run()) | 286 if (!deleter->Run()) |
| 296 return false; | 287 return false; |
| 297 | 288 |
| 298 // Add the new data to the table. | 289 // Add the new data to the table. |
| 299 std::unique_ptr<Statement> inserter( | 290 std::unique_ptr<sql::Statement> inserter( |
| 300 GetTableUpdateStatement(key_type, data_type, TableOperationType::INSERT)); | 291 GetTableUpdateStatement(key_type, data_type, TableOperationType::INSERT)); |
| 301 BindProtoDataToStatement(key, data, inserter.get()); | 292 BindProtoDataToStatement(key, data, inserter.get()); |
| 302 return inserter->Run(); | 293 return inserter->Run(); |
| 303 } | 294 } |
| 304 | 295 |
| 305 void ResourcePrefetchPredictorTables::DeleteDataHelper( | 296 void ResourcePrefetchPredictorTables::DeleteDataHelper( |
| 306 PrefetchKeyType key_type, | 297 PrefetchKeyType key_type, |
| 307 PrefetchDataType data_type, | 298 PrefetchDataType data_type, |
| 308 const std::vector<std::string>& keys) { | 299 const std::vector<std::string>& keys) { |
| 309 for (const std::string& key : keys) { | 300 for (const std::string& key : keys) { |
| 310 std::unique_ptr<Statement> deleter(GetTableUpdateStatement( | 301 std::unique_ptr<sql::Statement> deleter(GetTableUpdateStatement( |
| 311 key_type, data_type, TableOperationType::REMOVE)); | 302 key_type, data_type, TableOperationType::REMOVE)); |
| 312 deleter->BindString(0, key); | 303 deleter->BindString(0, key); |
| 313 deleter->Run(); | 304 deleter->Run(); |
| 314 } | 305 } |
| 315 } | 306 } |
| 316 | 307 |
| 317 // static | 308 // static |
| 318 float ResourcePrefetchPredictorTables::ComputeResourceScore( | 309 float ResourcePrefetchPredictorTables::ComputeResourceScore( |
| 319 const ResourceData& data) { | 310 const ResourceData& data) { |
| 320 // The ranking is done by considering, in this order: | 311 // The ranking is done by considering, in this order: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 352 |
| 362 // static | 353 // static |
| 363 bool ResourcePrefetchPredictorTables::DropTablesIfOutdated( | 354 bool ResourcePrefetchPredictorTables::DropTablesIfOutdated( |
| 364 sql::Connection* db) { | 355 sql::Connection* db) { |
| 365 int version = GetDatabaseVersion(db); | 356 int version = GetDatabaseVersion(db); |
| 366 bool success = true; | 357 bool success = true; |
| 367 // Too new is also a problem. | 358 // Too new is also a problem. |
| 368 bool incompatible_version = version != kDatabaseVersion; | 359 bool incompatible_version = version != kDatabaseVersion; |
| 369 | 360 |
| 370 // These are deprecated tables but they still have to be removed if present. | 361 // These are deprecated tables but they still have to be removed if present. |
| 371 const char kUrlMetadataTableName[] = | 362 static const char kUrlMetadataTableName[] = |
| 372 "resource_prefetch_predictor_url_metadata"; | 363 "resource_prefetch_predictor_url_metadata"; |
| 373 const char kHostMetadataTableName[] = | 364 static const char kHostMetadataTableName[] = |
| 374 "resource_prefetch_predictor_host_metadata"; | 365 "resource_prefetch_predictor_host_metadata"; |
| 375 | 366 |
| 376 if (incompatible_version) { | 367 if (incompatible_version) { |
| 377 for (const char* table_name : | 368 for (const char* table_name : |
| 378 {kMetadataTableName, kUrlResourceTableName, kHostResourceTableName, | 369 {kMetadataTableName, kUrlResourceTableName, kHostResourceTableName, |
| 379 kUrlRedirectTableName, kHostRedirectTableName, kUrlMetadataTableName, | 370 kUrlRedirectTableName, kHostRedirectTableName, kUrlMetadataTableName, |
| 380 kHostMetadataTableName}) { | 371 kHostMetadataTableName}) { |
| 381 success = | 372 success = |
| 382 success && | 373 success && |
| 383 db->Execute(base::StringPrintf("DROP TABLE IF EXISTS %s", table_name) | 374 db->Execute(base::StringPrintf("DROP TABLE IF EXISTS %s", table_name) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 return statement.Run(); | 413 return statement.Run(); |
| 423 } | 414 } |
| 424 | 415 |
| 425 void ResourcePrefetchPredictorTables::CreateTableIfNonExistent() { | 416 void ResourcePrefetchPredictorTables::CreateTableIfNonExistent() { |
| 426 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 417 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 427 if (CantAccessDatabase()) | 418 if (CantAccessDatabase()) |
| 428 return; | 419 return; |
| 429 | 420 |
| 430 // Database initialization is all-or-nothing. | 421 // Database initialization is all-or-nothing. |
| 431 sql::Connection* db = DB(); | 422 sql::Connection* db = DB(); |
| 432 sql::Transaction transaction{db}; | 423 bool success = db->BeginTransaction(); |
| 433 bool success = transaction.Begin(); | |
| 434 | |
| 435 success = success && DropTablesIfOutdated(db); | 424 success = success && DropTablesIfOutdated(db); |
| 436 | 425 |
| 437 for (const char* table_name : | 426 for (const char* table_name : |
| 438 {kUrlResourceTableName, kHostResourceTableName, kUrlRedirectTableName, | 427 {kUrlResourceTableName, kHostResourceTableName, kUrlRedirectTableName, |
| 439 kHostRedirectTableName}) { | 428 kHostRedirectTableName}) { |
| 440 success = success && | 429 success = success && |
| 441 (db->DoesTableExist(table_name) || | 430 (db->DoesTableExist(table_name) || |
| 442 db->Execute(base::StringPrintf( | 431 db->Execute(base::StringPrintf( |
| 443 kCreateProtoTableStatementTemplate, table_name) | 432 kCreateProtoTableStatementTemplate, table_name) |
| 444 .c_str())); | 433 .c_str())); |
| 445 } | 434 } |
| 446 | 435 |
| 447 if (success) | 436 if (success) |
| 448 success = transaction.Commit(); | 437 success = db->CommitTransaction(); |
| 449 else | 438 else |
| 450 transaction.Rollback(); | 439 db->RollbackTransaction(); |
| 451 | 440 |
| 452 if (!success) | 441 if (!success) |
| 453 ResetDB(); | 442 ResetDB(); |
| 454 } | 443 } |
| 455 | 444 |
| 456 void ResourcePrefetchPredictorTables::LogDatabaseStats() { | 445 void ResourcePrefetchPredictorTables::LogDatabaseStats() { |
| 457 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 446 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 458 if (CantAccessDatabase()) | 447 if (CantAccessDatabase()) |
| 459 return; | 448 return; |
| 460 | 449 |
| 461 Statement statement(DB()->GetUniqueStatement( | 450 sql::Statement statement(DB()->GetUniqueStatement( |
| 462 base::StringPrintf("SELECT count(*) FROM %s", | 451 base::StringPrintf("SELECT count(*) FROM %s", kUrlResourceTableName) |
| 463 kUrlResourceTableName).c_str())); | 452 .c_str())); |
| 464 if (statement.Step()) | 453 if (statement.Step()) |
| 465 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.UrlTableRowCount", | 454 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.UrlTableRowCount", |
| 466 statement.ColumnInt(0)); | 455 statement.ColumnInt(0)); |
| 467 | 456 |
| 468 statement.Assign(DB()->GetUniqueStatement( | 457 statement.Assign(DB()->GetUniqueStatement( |
| 469 base::StringPrintf("SELECT count(*) FROM %s", | 458 base::StringPrintf("SELECT count(*) FROM %s", kHostResourceTableName) |
| 470 kHostResourceTableName).c_str())); | 459 .c_str())); |
| 471 if (statement.Step()) | 460 if (statement.Step()) |
| 472 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HostTableRowCount", | 461 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HostTableRowCount", |
| 473 statement.ColumnInt(0)); | 462 statement.ColumnInt(0)); |
| 474 } | 463 } |
| 475 | 464 |
| 476 std::unique_ptr<Statement> | 465 std::unique_ptr<sql::Statement> |
| 477 ResourcePrefetchPredictorTables::GetTableUpdateStatement( | 466 ResourcePrefetchPredictorTables::GetTableUpdateStatement( |
| 478 PrefetchKeyType key_type, | 467 PrefetchKeyType key_type, |
| 479 PrefetchDataType data_type, | 468 PrefetchDataType data_type, |
| 480 TableOperationType op_type) { | 469 TableOperationType op_type) { |
| 481 sql::StatementID id(__FILE__, key_type | (static_cast<int>(data_type) << 1) | | 470 sql::StatementID id(__FILE__, key_type | (static_cast<int>(data_type) << 1) | |
| 482 (static_cast<int>(op_type) << 2)); | 471 (static_cast<int>(op_type) << 2)); |
| 483 const char* statement_template = (op_type == TableOperationType::REMOVE | 472 const char* statement_template = (op_type == TableOperationType::REMOVE |
| 484 ? kDeleteProtoTableStatementTemplate | 473 ? kDeleteProtoTableStatementTemplate |
| 485 : kInsertProtoTableStatementTemplate); | 474 : kInsertProtoTableStatementTemplate); |
| 486 const char* table_name = GetTableName(key_type, data_type); | 475 const char* table_name = GetTableName(key_type, data_type); |
| 487 return base::MakeUnique<Statement>(DB()->GetCachedStatement( | 476 return base::MakeUnique<sql::Statement>(DB()->GetCachedStatement( |
| 488 id, base::StringPrintf(statement_template, table_name).c_str())); | 477 id, base::StringPrintf(statement_template, table_name).c_str())); |
| 489 } | 478 } |
| 490 | 479 |
| 491 // static | 480 // static |
| 492 const char* ResourcePrefetchPredictorTables::GetTableName( | 481 const char* ResourcePrefetchPredictorTables::GetTableName( |
| 493 PrefetchKeyType key_type, | 482 PrefetchKeyType key_type, |
| 494 PrefetchDataType data_type) { | 483 PrefetchDataType data_type) { |
| 495 bool is_host = key_type == PREFETCH_KEY_TYPE_HOST; | 484 bool is_host = key_type == PREFETCH_KEY_TYPE_HOST; |
| 496 switch (data_type) { | 485 switch (data_type) { |
| 497 case PrefetchDataType::RESOURCE: | 486 case PrefetchDataType::RESOURCE: |
| 498 return is_host ? kHostResourceTableName : kUrlResourceTableName; | 487 return is_host ? kHostResourceTableName : kUrlResourceTableName; |
| 499 case PrefetchDataType::REDIRECT: | 488 case PrefetchDataType::REDIRECT: |
| 500 return is_host ? kHostRedirectTableName : kUrlRedirectTableName; | 489 return is_host ? kHostRedirectTableName : kUrlRedirectTableName; |
| 501 } | 490 } |
| 502 | 491 |
| 503 NOTREACHED(); | 492 NOTREACHED(); |
| 504 return nullptr; | 493 return nullptr; |
| 505 } | 494 } |
| 506 | 495 |
| 507 } // namespace predictors | 496 } // namespace predictors |
| OLD | NEW |