| 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> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "sql/statement.h" | 17 #include "sql/statement.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 using sql::Statement; | 20 using sql::Statement; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 using ResourceRow = predictors::ResourcePrefetchPredictorTables::ResourceRow; |
| 25 |
| 24 const char kUrlResourceTableName[] = "resource_prefetch_predictor_url"; | 26 const char kUrlResourceTableName[] = "resource_prefetch_predictor_url"; |
| 25 const char kUrlMetadataTableName[] = "resource_prefetch_predictor_url_metadata"; | 27 const char kUrlMetadataTableName[] = "resource_prefetch_predictor_url_metadata"; |
| 26 const char kHostResourceTableName[] = "resource_prefetch_predictor_host"; | 28 const char kHostResourceTableName[] = "resource_prefetch_predictor_host"; |
| 27 const char kHostMetadataTableName[] = | 29 const char kHostMetadataTableName[] = |
| 28 "resource_prefetch_predictor_host_metadata"; | 30 "resource_prefetch_predictor_host_metadata"; |
| 29 | 31 |
| 30 const char kInsertResourceTableStatementTemplate[] = | 32 const char kInsertResourceTableStatementTemplate[] = |
| 31 "INSERT INTO %s " | 33 "INSERT INTO %s (main_page_url, resource_url, proto) VALUES (?,?,?)"; |
| 32 "(main_page_url, resource_url, resource_type, number_of_hits, " | 34 const char kInsertMetadataTableStatementTemplate[] = |
| 33 "number_of_misses, consecutive_misses, average_position, priority, " | 35 "INSERT INTO %s (main_page_url, last_visit_time) VALUES (?,?)"; |
| 34 "has_validators, always_revalidate) " | 36 const char kDeleteStatementTemplate[] = "DELETE FROM %s WHERE main_page_url=?"; |
| 35 "VALUES (?,?,?,?,?,?,?,?,?,?)"; | |
| 36 | 37 |
| 37 void BindResourceRowToStatement( | 38 void BindResourceRowToStatement(const ResourceRow& row, |
| 38 const predictors::ResourcePrefetchPredictorTables::ResourceRow& row, | 39 const std::string& primary_key, |
| 39 const std::string& primary_key, | 40 Statement* statement) { |
| 40 Statement* statement) { | 41 chrome_browser_predictors::ResourceData proto; |
| 42 row.ToProto(&proto); |
| 43 int size = proto.ByteSize(); |
| 44 std::vector<char> proto_buffer(size); |
| 45 proto.SerializeToArray(&proto_buffer[0], size); |
| 46 |
| 41 statement->BindString(0, primary_key); | 47 statement->BindString(0, primary_key); |
| 42 statement->BindString(1, row.resource_url.spec()); | 48 statement->BindString(1, row.resource_url.spec()); |
| 43 statement->BindInt(2, static_cast<int>(row.resource_type)); | 49 statement->BindBlob(2, &proto_buffer[0], size); |
| 44 statement->BindInt(3, row.number_of_hits); | |
| 45 statement->BindInt(4, row.number_of_misses); | |
| 46 statement->BindInt(5, row.consecutive_misses); | |
| 47 statement->BindDouble(6, row.average_position); | |
| 48 statement->BindInt(7, static_cast<int>(row.priority)); | |
| 49 statement->BindInt(8, static_cast<int>(row.has_validators)); | |
| 50 statement->BindInt(9, static_cast<int>(row.always_revalidate)); | |
| 51 } | 50 } |
| 52 | 51 |
| 53 bool StepAndInitializeResourceRow( | 52 bool StepAndInitializeResourceRow(Statement* statement, ResourceRow* row) { |
| 54 Statement* statement, | |
| 55 predictors::ResourcePrefetchPredictorTables::ResourceRow* row) { | |
| 56 if (!statement->Step()) | 53 if (!statement->Step()) |
| 57 return false; | 54 return false; |
| 58 | 55 |
| 59 row->primary_key = statement->ColumnString(0); | 56 row->primary_key = statement->ColumnString(0); |
| 60 row->resource_url = GURL(statement->ColumnString(1)); | 57 row->resource_url = GURL(statement->ColumnString(1)); |
| 61 row->resource_type = static_cast<content::ResourceType>( | |
| 62 statement->ColumnInt(2)); | |
| 63 row->number_of_hits = statement->ColumnInt(3); | |
| 64 row->number_of_misses = statement->ColumnInt(4); | |
| 65 row->consecutive_misses = statement->ColumnInt(5); | |
| 66 row->average_position = statement->ColumnDouble(6); | |
| 67 row->priority = static_cast<net::RequestPriority>(statement->ColumnInt(7)); | |
| 68 // static_cast<bool> creates a C4800 warning with Visual Studio. | |
| 69 row->has_validators = statement->ColumnInt(8) != 0; | |
| 70 row->always_revalidate = statement->ColumnInt(9) != 0; | |
| 71 | 58 |
| 59 int size = statement->ColumnByteLength(2); |
| 60 const void* data = statement->ColumnBlob(2); |
| 61 DCHECK(data); |
| 62 chrome_browser_predictors::ResourceData proto; |
| 63 proto.ParseFromArray(data, size); |
| 64 |
| 65 ResourceRow::FromProto(proto, row); |
| 72 return true; | 66 return true; |
| 73 } | 67 } |
| 74 | 68 |
| 75 } // namespace | 69 } // namespace |
| 76 | 70 |
| 77 namespace predictors { | 71 namespace predictors { |
| 78 | 72 |
| 79 // static | 73 // static |
| 80 const size_t ResourcePrefetchPredictorTables::kMaxStringLength = 1024; | 74 const size_t ResourcePrefetchPredictorTables::kMaxStringLength = 1024; |
| 81 | 75 |
| 82 ResourcePrefetchPredictorTables::ResourceRow::ResourceRow() | 76 ResourceRow::ResourceRow() |
| 83 : resource_type(content::RESOURCE_TYPE_LAST_TYPE), | 77 : resource_type(content::RESOURCE_TYPE_LAST_TYPE), |
| 84 number_of_hits(0), | 78 number_of_hits(0), |
| 85 number_of_misses(0), | 79 number_of_misses(0), |
| 86 consecutive_misses(0), | 80 consecutive_misses(0), |
| 87 average_position(0.0), | 81 average_position(0.0), |
| 88 priority(net::IDLE), | 82 priority(net::IDLE), |
| 89 has_validators(false), | 83 has_validators(false), |
| 90 always_revalidate(false), | 84 always_revalidate(false), |
| 91 score(0.0) {} | 85 score(0.0) {} |
| 92 | 86 |
| 93 ResourcePrefetchPredictorTables::ResourceRow::ResourceRow( | 87 ResourceRow::ResourceRow(const ResourceRow& other) |
| 94 const ResourceRow& other) | |
| 95 : primary_key(other.primary_key), | 88 : primary_key(other.primary_key), |
| 96 resource_url(other.resource_url), | 89 resource_url(other.resource_url), |
| 97 resource_type(other.resource_type), | 90 resource_type(other.resource_type), |
| 98 number_of_hits(other.number_of_hits), | 91 number_of_hits(other.number_of_hits), |
| 99 number_of_misses(other.number_of_misses), | 92 number_of_misses(other.number_of_misses), |
| 100 consecutive_misses(other.consecutive_misses), | 93 consecutive_misses(other.consecutive_misses), |
| 101 average_position(other.average_position), | 94 average_position(other.average_position), |
| 102 priority(other.priority), | 95 priority(other.priority), |
| 103 has_validators(other.has_validators), | 96 has_validators(other.has_validators), |
| 104 always_revalidate(other.always_revalidate), | 97 always_revalidate(other.always_revalidate), |
| 105 score(other.score) {} | 98 score(other.score) {} |
| 106 | 99 |
| 107 ResourcePrefetchPredictorTables::ResourceRow::ResourceRow( | 100 ResourceRow::ResourceRow(const std::string& i_primary_key, |
| 108 const std::string& i_primary_key, | 101 const std::string& i_resource_url, |
| 109 const std::string& i_resource_url, | 102 content::ResourceType i_resource_type, |
| 110 content::ResourceType i_resource_type, | 103 int i_number_of_hits, |
| 111 int i_number_of_hits, | 104 int i_number_of_misses, |
| 112 int i_number_of_misses, | 105 int i_consecutive_misses, |
| 113 int i_consecutive_misses, | 106 double i_average_position, |
| 114 double i_average_position, | 107 net::RequestPriority i_priority, |
| 115 net::RequestPriority i_priority, | 108 bool i_has_validators, |
| 116 bool i_has_validators, | 109 bool i_always_revalidate) |
| 117 bool i_always_revalidate) | |
| 118 : primary_key(i_primary_key), | 110 : primary_key(i_primary_key), |
| 119 resource_url(i_resource_url), | 111 resource_url(i_resource_url), |
| 120 resource_type(i_resource_type), | 112 resource_type(i_resource_type), |
| 121 number_of_hits(i_number_of_hits), | 113 number_of_hits(i_number_of_hits), |
| 122 number_of_misses(i_number_of_misses), | 114 number_of_misses(i_number_of_misses), |
| 123 consecutive_misses(i_consecutive_misses), | 115 consecutive_misses(i_consecutive_misses), |
| 124 average_position(i_average_position), | 116 average_position(i_average_position), |
| 125 priority(i_priority), | 117 priority(i_priority), |
| 126 has_validators(i_has_validators), | 118 has_validators(i_has_validators), |
| 127 always_revalidate(i_always_revalidate) { | 119 always_revalidate(i_always_revalidate) { |
| 128 UpdateScore(); | 120 UpdateScore(); |
| 129 } | 121 } |
| 130 | 122 |
| 131 void ResourcePrefetchPredictorTables::ResourceRow::UpdateScore() { | 123 void ResourceRow::UpdateScore() { |
| 132 // The score is calculated so that when the rows are sorted, stylesheets, | 124 // The score is calculated so that when the rows are sorted, stylesheets, |
| 133 // scripts and fonts appear first, sorted by position(ascending) and then the | 125 // scripts and fonts appear first, sorted by position(ascending) and then the |
| 134 // rest of the resources sorted by position (ascending). | 126 // rest of the resources sorted by position (ascending). |
| 135 static const int kMaxResourcesPerType = 100; | 127 static const int kMaxResourcesPerType = 100; |
| 136 switch (resource_type) { | 128 switch (resource_type) { |
| 137 case content::RESOURCE_TYPE_STYLESHEET: | 129 case content::RESOURCE_TYPE_STYLESHEET: |
| 138 case content::RESOURCE_TYPE_SCRIPT: | 130 case content::RESOURCE_TYPE_SCRIPT: |
| 139 case content::RESOURCE_TYPE_FONT_RESOURCE: | 131 case content::RESOURCE_TYPE_FONT_RESOURCE: |
| 140 score = (2 * kMaxResourcesPerType) - average_position; | 132 score = (2 * kMaxResourcesPerType) - average_position; |
| 141 break; | 133 break; |
| 142 | 134 |
| 143 case content::RESOURCE_TYPE_IMAGE: | 135 case content::RESOURCE_TYPE_IMAGE: |
| 144 default: | 136 default: |
| 145 score = kMaxResourcesPerType - average_position; | 137 score = kMaxResourcesPerType - average_position; |
| 146 break; | 138 break; |
| 147 } | 139 } |
| 148 // TODO(lizeb): Take priority into account. | 140 // TODO(lizeb): Take priority into account. |
| 149 } | 141 } |
| 150 | 142 |
| 151 bool ResourcePrefetchPredictorTables::ResourceRow::operator==( | 143 bool ResourceRow::operator==(const ResourceRow& rhs) const { |
| 152 const ResourceRow& rhs) const { | |
| 153 return primary_key == rhs.primary_key && resource_url == rhs.resource_url && | 144 return primary_key == rhs.primary_key && resource_url == rhs.resource_url && |
| 154 resource_type == rhs.resource_type && | 145 resource_type == rhs.resource_type && |
| 155 number_of_hits == rhs.number_of_hits && | 146 number_of_hits == rhs.number_of_hits && |
| 156 number_of_misses == rhs.number_of_misses && | 147 number_of_misses == rhs.number_of_misses && |
| 157 consecutive_misses == rhs.consecutive_misses && | 148 consecutive_misses == rhs.consecutive_misses && |
| 158 average_position == rhs.average_position && priority == rhs.priority && | 149 average_position == rhs.average_position && priority == rhs.priority && |
| 159 has_validators == rhs.has_validators && | 150 has_validators == rhs.has_validators && |
| 160 always_revalidate == rhs.always_revalidate && score == rhs.score; | 151 always_revalidate == rhs.always_revalidate && score == rhs.score; |
| 161 } | 152 } |
| 162 | 153 |
| 163 bool ResourcePrefetchPredictorTables::ResourceRowSorter::operator()( | 154 void ResourceRow::ToProto(ResourceData* resource_data) const { |
| 164 const ResourceRow& x, const ResourceRow& y) const { | 155 using chrome_browser_predictors::ResourceData_Priority; |
| 165 return x.score > y.score; | 156 using chrome_browser_predictors::ResourceData_ResourceType; |
| 157 |
| 158 resource_data->set_primary_key(primary_key); |
| 159 resource_data->set_resource_url(resource_url.spec()); |
| 160 resource_data->set_resource_type( |
| 161 static_cast<ResourceData_ResourceType>(resource_type)); |
| 162 resource_data->set_number_of_hits(number_of_hits); |
| 163 resource_data->set_number_of_misses(number_of_misses); |
| 164 resource_data->set_consecutive_misses(consecutive_misses); |
| 165 resource_data->set_average_position(average_position); |
| 166 resource_data->set_priority(static_cast<ResourceData_Priority>(priority)); |
| 167 resource_data->set_has_validators(has_validators); |
| 168 resource_data->set_always_revalidate(always_revalidate); |
| 169 } |
| 170 |
| 171 // static |
| 172 void ResourceRow::FromProto(const ResourceData& proto, ResourceRow* row) { |
| 173 DCHECK(proto.has_primary_key()); |
| 174 row->primary_key = proto.primary_key(); |
| 175 row->resource_url = GURL(proto.resource_url()); |
| 176 row->resource_type = |
| 177 static_cast<content::ResourceType>(proto.resource_type()); |
| 178 row->number_of_hits = proto.number_of_hits(); |
| 179 row->number_of_misses = proto.number_of_misses(); |
| 180 row->consecutive_misses = proto.consecutive_misses(); |
| 181 row->average_position = proto.average_position(); |
| 182 row->priority = static_cast<net::RequestPriority>(proto.priority()); |
| 183 row->has_validators = proto.has_validators(); |
| 184 row->always_revalidate = proto.always_revalidate(); |
| 185 } |
| 186 |
| 187 // static |
| 188 void ResourcePrefetchPredictorTables::SortResourceRows(ResourceRows* rows) { |
| 189 std::sort(rows->begin(), rows->end(), |
| 190 [](const ResourceRow& x, const ResourceRow& y) { |
| 191 return x.score > y.score; |
| 192 }); |
| 166 } | 193 } |
| 167 | 194 |
| 168 ResourcePrefetchPredictorTables::PrefetchData::PrefetchData( | 195 ResourcePrefetchPredictorTables::PrefetchData::PrefetchData( |
| 169 PrefetchKeyType i_key_type, | 196 PrefetchKeyType i_key_type, |
| 170 const std::string& i_primary_key) | 197 const std::string& i_primary_key) |
| 171 : key_type(i_key_type), | 198 : key_type(i_key_type), |
| 172 primary_key(i_primary_key) { | 199 primary_key(i_primary_key) { |
| 173 } | 200 } |
| 174 | 201 |
| 175 ResourcePrefetchPredictorTables::PrefetchData::PrefetchData( | 202 ResourcePrefetchPredictorTables::PrefetchData::PrefetchData( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 if (it == data_map->end()) { | 329 if (it == data_map->end()) { |
| 303 it = data_map->insert(std::make_pair( | 330 it = data_map->insert(std::make_pair( |
| 304 primary_key, PrefetchData(key_type, primary_key))).first; | 331 primary_key, PrefetchData(key_type, primary_key))).first; |
| 305 } | 332 } |
| 306 it->second.resources.push_back(row); | 333 it->second.resources.push_back(row); |
| 307 } | 334 } |
| 308 | 335 |
| 309 // Sort each of the resource row vectors by score. | 336 // Sort each of the resource row vectors by score. |
| 310 for (PrefetchDataMap::iterator it = data_map->begin(); it != data_map->end(); | 337 for (PrefetchDataMap::iterator it = data_map->begin(); it != data_map->end(); |
| 311 ++it) { | 338 ++it) { |
| 312 std::sort(it->second.resources.begin(), | 339 SortResourceRows(&(it->second.resources)); |
| 313 it->second.resources.end(), | |
| 314 ResourceRowSorter()); | |
| 315 } | 340 } |
| 316 | 341 |
| 317 // Read the metadata and keep track of entries that have metadata, but no | 342 // Read the metadata and keep track of entries that have metadata, but no |
| 318 // resource entries, so they can be deleted. | 343 // resource entries, so they can be deleted. |
| 319 const char* metadata_table_name = is_host ? kHostMetadataTableName : | 344 const char* metadata_table_name = is_host ? kHostMetadataTableName : |
| 320 kUrlMetadataTableName; | 345 kUrlMetadataTableName; |
| 321 Statement metadata_reader(DB()->GetUniqueStatement( | 346 Statement metadata_reader(DB()->GetUniqueStatement( |
| 322 base::StringPrintf("SELECT * FROM %s", metadata_table_name).c_str())); | 347 base::StringPrintf("SELECT * FROM %s", metadata_table_name).c_str())); |
| 323 | 348 |
| 324 while (metadata_reader.Step()) { | 349 while (metadata_reader.Step()) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 437 } |
| 413 return true; | 438 return true; |
| 414 } | 439 } |
| 415 | 440 |
| 416 bool ResourcePrefetchPredictorTables::DropTablesIfOutdated( | 441 bool ResourcePrefetchPredictorTables::DropTablesIfOutdated( |
| 417 sql::Connection* db) { | 442 sql::Connection* db) { |
| 418 bool success = true; | 443 bool success = true; |
| 419 for (const char* table_name : | 444 for (const char* table_name : |
| 420 {kUrlResourceTableName, kHostResourceTableName}) { | 445 {kUrlResourceTableName, kHostResourceTableName}) { |
| 421 if (db->DoesTableExist(table_name) && | 446 if (db->DoesTableExist(table_name) && |
| 422 !db->DoesColumnExist(table_name, "always_revalidate")) { | 447 !db->DoesColumnExist(table_name, "proto")) { |
| 423 success &= | 448 success &= |
| 424 db->Execute(base::StringPrintf("DROP TABLE %s", table_name).c_str()); | 449 db->Execute(base::StringPrintf("DROP TABLE %s", table_name).c_str()); |
| 425 } | 450 } |
| 426 } | 451 } |
| 427 return success; | 452 return success; |
| 428 } | 453 } |
| 429 | 454 |
| 430 void ResourcePrefetchPredictorTables::CreateTableIfNonExistent() { | 455 void ResourcePrefetchPredictorTables::CreateTableIfNonExistent() { |
| 431 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 456 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 432 if (CantAccessDatabase()) | 457 if (CantAccessDatabase()) |
| 433 return; | 458 return; |
| 434 | 459 |
| 435 const char resource_table_creator[] = | 460 const char resource_table_creator[] = |
| 436 "CREATE TABLE %s ( " | 461 "CREATE TABLE %s ( " |
| 437 "main_page_url TEXT, " | 462 "main_page_url TEXT, " |
| 438 "resource_url TEXT, " | 463 "resource_url TEXT, " |
| 439 "resource_type INTEGER, " | 464 "proto BLOB, " |
| 440 "number_of_hits INTEGER, " | |
| 441 "number_of_misses INTEGER, " | |
| 442 "consecutive_misses INTEGER, " | |
| 443 "average_position DOUBLE, " | |
| 444 "priority INTEGER, " | |
| 445 "has_validators INTEGER, " | |
| 446 "always_revalidate INTEGER, " | |
| 447 "PRIMARY KEY(main_page_url, resource_url))"; | 465 "PRIMARY KEY(main_page_url, resource_url))"; |
| 448 const char* metadata_table_creator = | 466 const char* metadata_table_creator = |
| 449 "CREATE TABLE %s ( " | 467 "CREATE TABLE %s ( " |
| 450 "main_page_url TEXT, " | 468 "main_page_url TEXT, " |
| 451 "last_visit_time INTEGER, " | 469 "last_visit_time INTEGER, " |
| 452 "PRIMARY KEY(main_page_url))"; | 470 "PRIMARY KEY(main_page_url))"; |
| 453 | 471 |
| 454 sql::Connection* db = DB(); | 472 sql::Connection* db = DB(); |
| 455 bool success = DropTablesIfOutdated(db) && | 473 bool success = DropTablesIfOutdated(db) && |
| 456 (db->DoesTableExist(kUrlResourceTableName) || | 474 (db->DoesTableExist(kUrlResourceTableName) || |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 kHostResourceTableName).c_str())); | 509 kHostResourceTableName).c_str())); |
| 492 if (statement.Step()) | 510 if (statement.Step()) |
| 493 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HostTableRowCount", | 511 UMA_HISTOGRAM_COUNTS("ResourcePrefetchPredictor.HostTableRowCount", |
| 494 statement.ColumnInt(0)); | 512 statement.ColumnInt(0)); |
| 495 } | 513 } |
| 496 | 514 |
| 497 Statement* | 515 Statement* |
| 498 ResourcePrefetchPredictorTables::GetUrlResourceDeleteStatement() { | 516 ResourcePrefetchPredictorTables::GetUrlResourceDeleteStatement() { |
| 499 return new Statement(DB()->GetCachedStatement( | 517 return new Statement(DB()->GetCachedStatement( |
| 500 SQL_FROM_HERE, | 518 SQL_FROM_HERE, |
| 501 base::StringPrintf("DELETE FROM %s WHERE main_page_url=?", | 519 base::StringPrintf(kDeleteStatementTemplate, kUrlResourceTableName) |
| 502 kUrlResourceTableName).c_str())); | 520 .c_str())); |
| 503 } | 521 } |
| 504 | 522 |
| 505 Statement* | 523 Statement* |
| 506 ResourcePrefetchPredictorTables::GetUrlResourceUpdateStatement() { | 524 ResourcePrefetchPredictorTables::GetUrlResourceUpdateStatement() { |
| 507 return new Statement(DB()->GetCachedStatement( | 525 return new Statement(DB()->GetCachedStatement( |
| 508 SQL_FROM_HERE, base::StringPrintf(kInsertResourceTableStatementTemplate, | 526 SQL_FROM_HERE, base::StringPrintf(kInsertResourceTableStatementTemplate, |
| 509 kUrlResourceTableName) | 527 kUrlResourceTableName) |
| 510 .c_str())); | 528 .c_str())); |
| 511 } | 529 } |
| 512 | 530 |
| 513 Statement* | 531 Statement* |
| 514 ResourcePrefetchPredictorTables::GetUrlMetadataDeleteStatement() { | 532 ResourcePrefetchPredictorTables::GetUrlMetadataDeleteStatement() { |
| 515 return new Statement(DB()->GetCachedStatement( | 533 return new Statement(DB()->GetCachedStatement( |
| 516 SQL_FROM_HERE, | 534 SQL_FROM_HERE, |
| 517 base::StringPrintf("DELETE FROM %s WHERE main_page_url=?", | 535 base::StringPrintf(kDeleteStatementTemplate, kUrlMetadataTableName) |
| 518 kUrlMetadataTableName).c_str())); | 536 .c_str())); |
| 519 } | 537 } |
| 520 | 538 |
| 521 Statement* | 539 Statement* |
| 522 ResourcePrefetchPredictorTables::GetUrlMetadataUpdateStatement() { | 540 ResourcePrefetchPredictorTables::GetUrlMetadataUpdateStatement() { |
| 523 return new Statement(DB()->GetCachedStatement( | 541 return new Statement(DB()->GetCachedStatement( |
| 524 SQL_FROM_HERE, | 542 SQL_FROM_HERE, base::StringPrintf(kInsertMetadataTableStatementTemplate, |
| 525 base::StringPrintf( | 543 kUrlMetadataTableName) |
| 526 "INSERT INTO %s (main_page_url, last_visit_time) VALUES (?,?)", | 544 .c_str())); |
| 527 kUrlMetadataTableName).c_str())); | |
| 528 } | 545 } |
| 529 | 546 |
| 530 Statement* | 547 Statement* |
| 531 ResourcePrefetchPredictorTables::GetHostResourceDeleteStatement() { | 548 ResourcePrefetchPredictorTables::GetHostResourceDeleteStatement() { |
| 532 return new Statement(DB()->GetCachedStatement( | 549 return new Statement(DB()->GetCachedStatement( |
| 533 SQL_FROM_HERE, | 550 SQL_FROM_HERE, |
| 534 base::StringPrintf("DELETE FROM %s WHERE main_page_url=?", | 551 base::StringPrintf(kDeleteStatementTemplate, kHostResourceTableName) |
| 535 kHostResourceTableName).c_str())); | 552 .c_str())); |
| 536 } | 553 } |
| 537 | 554 |
| 538 Statement* | 555 Statement* |
| 539 ResourcePrefetchPredictorTables::GetHostResourceUpdateStatement() { | 556 ResourcePrefetchPredictorTables::GetHostResourceUpdateStatement() { |
| 540 return new Statement(DB()->GetCachedStatement( | 557 return new Statement(DB()->GetCachedStatement( |
| 541 SQL_FROM_HERE, base::StringPrintf(kInsertResourceTableStatementTemplate, | 558 SQL_FROM_HERE, base::StringPrintf(kInsertResourceTableStatementTemplate, |
| 542 kHostResourceTableName) | 559 kHostResourceTableName) |
| 543 .c_str())); | 560 .c_str())); |
| 544 } | 561 } |
| 545 | 562 |
| 546 Statement* | 563 Statement* |
| 547 ResourcePrefetchPredictorTables::GetHostMetadataDeleteStatement() { | 564 ResourcePrefetchPredictorTables::GetHostMetadataDeleteStatement() { |
| 548 return new Statement(DB()->GetCachedStatement( | 565 return new Statement(DB()->GetCachedStatement( |
| 549 SQL_FROM_HERE, | 566 SQL_FROM_HERE, |
| 550 base::StringPrintf("DELETE FROM %s WHERE main_page_url=?", | 567 base::StringPrintf(kDeleteStatementTemplate, kHostMetadataTableName) |
| 551 kHostMetadataTableName).c_str())); | 568 .c_str())); |
| 552 } | 569 } |
| 553 | 570 |
| 554 Statement* ResourcePrefetchPredictorTables::GetHostMetadataUpdateStatement() { | 571 Statement* ResourcePrefetchPredictorTables::GetHostMetadataUpdateStatement() { |
| 555 return new Statement(DB()->GetCachedStatement( | 572 return new Statement(DB()->GetCachedStatement( |
| 556 SQL_FROM_HERE, | 573 SQL_FROM_HERE, base::StringPrintf(kInsertMetadataTableStatementTemplate, |
| 557 base::StringPrintf( | 574 kHostMetadataTableName) |
| 558 "INSERT INTO %s (main_page_url, last_visit_time) VALUES (?,?)", | 575 .c_str())); |
| 559 kHostMetadataTableName).c_str())); | |
| 560 } | 576 } |
| 561 | 577 |
| 562 } // namespace predictors | 578 } // namespace predictors |
| OLD | NEW |