| 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 "components/history/core/browser/url_database.h" | 5 #include "components/history/core/browser/url_database.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/history/core/browser/keyword_search_term.h" | 14 #include "components/history/core/browser/keyword_search_term.h" |
| 16 #include "components/url_formatter/url_formatter.h" | 15 #include "components/url_formatter/url_formatter.h" |
| 17 #include "sql/statement.h" | 16 #include "sql/statement.h" |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 19 | 18 |
| 20 namespace history { | 19 namespace history { |
| 21 | 20 |
| 22 const char URLDatabase::kURLRowFields[] = HISTORY_URL_ROW_FIELDS; | 21 const char URLDatabase::kURLRowFields[] = HISTORY_URL_ROW_FIELDS; |
| 23 const int URLDatabase::kNumURLRowFields = 9; | 22 const int URLDatabase::kNumURLRowFields = 9; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 bool URLDatabase::GetTextMatches(const base::string16& query, | 355 bool URLDatabase::GetTextMatches(const base::string16& query, |
| 357 URLRows* results) { | 356 URLRows* results) { |
| 358 return GetTextMatchesWithAlgorithm( | 357 return GetTextMatchesWithAlgorithm( |
| 359 query, query_parser::MatchingAlgorithm::DEFAULT, results); | 358 query, query_parser::MatchingAlgorithm::DEFAULT, results); |
| 360 } | 359 } |
| 361 | 360 |
| 362 bool URLDatabase::GetTextMatchesWithAlgorithm( | 361 bool URLDatabase::GetTextMatchesWithAlgorithm( |
| 363 const base::string16& query, | 362 const base::string16& query, |
| 364 query_parser::MatchingAlgorithm algorithm, | 363 query_parser::MatchingAlgorithm algorithm, |
| 365 URLRows* results) { | 364 URLRows* results) { |
| 366 ScopedVector<query_parser::QueryNode> query_nodes; | 365 query_parser::QueryNodeVector query_nodes; |
| 367 query_parser_.ParseQueryNodes(query, algorithm, &query_nodes.get()); | 366 query_parser_.ParseQueryNodes(query, algorithm, &query_nodes); |
| 368 | 367 |
| 369 results->clear(); | 368 results->clear(); |
| 370 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 369 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 371 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls WHERE hidden = 0")); | 370 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls WHERE hidden = 0")); |
| 372 | 371 |
| 373 while (statement.Step()) { | 372 while (statement.Step()) { |
| 374 query_parser::QueryWordVector query_words; | 373 query_parser::QueryWordVector query_words; |
| 375 base::string16 url = base::i18n::ToLower(statement.ColumnString16(1)); | 374 base::string16 url = base::i18n::ToLower(statement.ColumnString16(1)); |
| 376 query_parser_.ExtractQueryWords(url, &query_words); | 375 query_parser_.ExtractQueryWords(url, &query_words); |
| 377 GURL gurl(url); | 376 GURL gurl(url); |
| 378 if (gurl.is_valid()) { | 377 if (gurl.is_valid()) { |
| 379 // Decode punycode to match IDN. | 378 // Decode punycode to match IDN. |
| 380 base::string16 ascii = base::ASCIIToUTF16(gurl.host()); | 379 base::string16 ascii = base::ASCIIToUTF16(gurl.host()); |
| 381 base::string16 utf = url_formatter::IDNToUnicode(gurl.host()); | 380 base::string16 utf = url_formatter::IDNToUnicode(gurl.host()); |
| 382 if (ascii != utf) | 381 if (ascii != utf) |
| 383 query_parser_.ExtractQueryWords(utf, &query_words); | 382 query_parser_.ExtractQueryWords(utf, &query_words); |
| 384 } | 383 } |
| 385 base::string16 title = base::i18n::ToLower(statement.ColumnString16(2)); | 384 base::string16 title = base::i18n::ToLower(statement.ColumnString16(2)); |
| 386 query_parser_.ExtractQueryWords(title, &query_words); | 385 query_parser_.ExtractQueryWords(title, &query_words); |
| 387 | 386 |
| 388 if (query_parser_.DoesQueryMatch(query_words, query_nodes.get())) { | 387 if (query_parser_.DoesQueryMatch(query_words, query_nodes)) { |
| 389 URLResult info; | 388 URLResult info; |
| 390 FillURLRow(statement, &info); | 389 FillURLRow(statement, &info); |
| 391 if (info.url().is_valid()) | 390 if (info.url().is_valid()) |
| 392 results->push_back(info); | 391 results->push_back(info); |
| 393 } | 392 } |
| 394 } | 393 } |
| 395 return !results->empty(); | 394 return !results->empty(); |
| 396 } | 395 } |
| 397 | 396 |
| 398 bool URLDatabase::InitKeywordSearchTermsTable() { | 397 bool URLDatabase::InitKeywordSearchTermsTable() { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 bool RowQualifiesAsSignificant(const URLRow& row, | 630 bool RowQualifiesAsSignificant(const URLRow& row, |
| 632 const base::Time& threshold) { | 631 const base::Time& threshold) { |
| 633 const base::Time& real_threshold = | 632 const base::Time& real_threshold = |
| 634 threshold.is_null() ? AutocompleteAgeThreshold() : threshold; | 633 threshold.is_null() ? AutocompleteAgeThreshold() : threshold; |
| 635 return (row.typed_count() >= kLowQualityMatchTypedLimit) || | 634 return (row.typed_count() >= kLowQualityMatchTypedLimit) || |
| 636 (row.visit_count() >= kLowQualityMatchVisitLimit) || | 635 (row.visit_count() >= kLowQualityMatchVisitLimit) || |
| 637 (row.last_visit() >= real_threshold); | 636 (row.last_visit() >= real_threshold); |
| 638 } | 637 } |
| 639 | 638 |
| 640 } // namespace history | 639 } // namespace history |
| OLD | NEW |