OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history/scored_history_match.h" | 5 #include "chrome/browser/history/scored_history_match.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <numeric> | 10 #include <numeric> |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 const string16& url, | 249 const string16& url, |
250 const TermMatches& url_matches, | 250 const TermMatches& url_matches, |
251 const TermMatches& title_matches, | 251 const TermMatches& title_matches, |
252 const RowWordStarts& word_starts) { | 252 const RowWordStarts& word_starts) { |
253 // Because the below thread is not thread safe, we check that we're | 253 // Because the below thread is not thread safe, we check that we're |
254 // only calling it from one thread: the UI thread. Specifically, | 254 // only calling it from one thread: the UI thread. Specifically, |
255 // we check "if we've heard of the UI thread then we'd better | 255 // we check "if we've heard of the UI thread then we'd better |
256 // be on it." The first part is necessary so unit tests pass. (Many | 256 // be on it." The first part is necessary so unit tests pass. (Many |
257 // unit tests don't set up the threading naming system; hence | 257 // unit tests don't set up the threading naming system; hence |
258 // CurrentlyOn(UI thread) will fail.) | 258 // CurrentlyOn(UI thread) will fail.) |
259 DCHECK( | 259 DCHECK(!content::BrowserThread::IsThreadInitialized( |
260 !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || | 260 content::BrowserThread::UI) || |
261 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 261 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
262 if (raw_term_score_to_topicality_score == NULL) { | 262 if (raw_term_score_to_topicality_score == NULL) { |
263 raw_term_score_to_topicality_score = new float[kMaxRawTermScore]; | 263 raw_term_score_to_topicality_score = new float[kMaxRawTermScore]; |
264 FillInTermScoreToTopicalityScoreArray(); | 264 FillInTermScoreToTopicalityScoreArray(); |
265 } | 265 } |
266 // A vector that accumulates per-term scores. The strongest match--a | 266 // A vector that accumulates per-term scores. The strongest match--a |
267 // match in the hostname at a word boundary--is worth 10 points. | 267 // match in the hostname at a word boundary--is worth 10 points. |
268 // Everything else is less. In general, a match that's not at a word | 268 // Everything else is less. In general, a match that's not at a word |
269 // boundary is worth about 1/4th or 1/5th of a match at the word boundary | 269 // boundary is worth about 1/4th or 1/5th of a match at the word boundary |
270 // in the same part of the URL/title. | 270 // in the same part of the URL/title. |
271 DCHECK_GT(num_terms, 0); | 271 DCHECK_GT(num_terms, 0); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 float* ScoredHistoryMatch::days_ago_to_recency_score = NULL; | 393 float* ScoredHistoryMatch::days_ago_to_recency_score = NULL; |
394 | 394 |
395 // static | 395 // static |
396 float ScoredHistoryMatch::GetRecencyScore(int last_visit_days_ago) { | 396 float ScoredHistoryMatch::GetRecencyScore(int last_visit_days_ago) { |
397 // Because the below thread is not thread safe, we check that we're | 397 // Because the below thread is not thread safe, we check that we're |
398 // only calling it from one thread: the UI thread. Specifically, | 398 // only calling it from one thread: the UI thread. Specifically, |
399 // we check "if we've heard of the UI thread then we'd better | 399 // we check "if we've heard of the UI thread then we'd better |
400 // be on it." The first part is necessary so unit tests pass. (Many | 400 // be on it." The first part is necessary so unit tests pass. (Many |
401 // unit tests don't set up the threading naming system; hence | 401 // unit tests don't set up the threading naming system; hence |
402 // CurrentlyOn(UI thread) will fail.) | 402 // CurrentlyOn(UI thread) will fail.) |
403 DCHECK( | 403 DCHECK(!content::BrowserThread::IsThreadInitialized( |
404 !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || | 404 content::BrowserThread::UI) || |
405 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 405 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
406 if (days_ago_to_recency_score == NULL) { | 406 if (days_ago_to_recency_score == NULL) { |
407 days_ago_to_recency_score = new float[kDaysToPrecomputeRecencyScoresFor]; | 407 days_ago_to_recency_score = new float[kDaysToPrecomputeRecencyScoresFor]; |
408 FillInDaysAgoToRecencyScoreArray(); | 408 FillInDaysAgoToRecencyScoreArray(); |
409 } | 409 } |
410 // Lookup the score in days_ago_to_recency_score, treating | 410 // Lookup the score in days_ago_to_recency_score, treating |
411 // everything older than what we've precomputed as the oldest thing | 411 // everything older than what we've precomputed as the oldest thing |
412 // we've precomputed. The std::max is to protect against corruption | 412 // we've precomputed. The std::max is to protect against corruption |
413 // in the database (in case last_visit_days_ago is negative). | 413 // in the database (in case last_visit_days_ago is negative). |
414 return days_ago_to_recency_score[ | 414 return days_ago_to_recency_score[ |
415 std::max( | 415 std::max( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 // and not be demoted, thus outscoring the demoted HQP results. | 524 // and not be demoted, thus outscoring the demoted HQP results. |
525 // When the HQP provides these, we need to clamp the non-inlineable | 525 // When the HQP provides these, we need to clamp the non-inlineable |
526 // results to preserve this behavior. | 526 // results to preserve this behavior. |
527 if (also_do_hup_like_scoring) { | 527 if (also_do_hup_like_scoring) { |
528 max_assigned_score_for_non_inlineable_matches = | 528 max_assigned_score_for_non_inlineable_matches = |
529 HistoryURLProvider::kScoreForBestInlineableResult - 1; | 529 HistoryURLProvider::kScoreForBestInlineableResult - 1; |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 } // namespace history | 533 } // namespace history |
OLD | NEW |