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/autocomplete/scored_history_match.h" | 5 #include "chrome/browser/autocomplete/scored_history_match.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 // Compute the weighted average |value_of_transition| over the last at | 578 // Compute the weighted average |value_of_transition| over the last at |
579 // most kMaxVisitsToScore visits, where each visit is weighted using | 579 // most kMaxVisitsToScore visits, where each visit is weighted using |
580 // GetRecencyScore() based on how many days ago it happened. Use | 580 // GetRecencyScore() based on how many days ago it happened. Use |
581 // kMaxVisitsToScore as the denominator for the average regardless of | 581 // kMaxVisitsToScore as the denominator for the average regardless of |
582 // how many visits there were in order to penalize a match that has | 582 // how many visits there were in order to penalize a match that has |
583 // fewer visits than kMaxVisitsToScore. | 583 // fewer visits than kMaxVisitsToScore. |
584 float summed_visit_points = 0; | 584 float summed_visit_points = 0; |
585 const size_t max_visit_to_score = | 585 const size_t max_visit_to_score = |
586 std::min(visits.size(), ScoredHistoryMatch::kMaxVisitsToScore); | 586 std::min(visits.size(), ScoredHistoryMatch::kMaxVisitsToScore); |
587 for (size_t i = 0; i < max_visit_to_score; ++i) { | 587 for (size_t i = 0; i < max_visit_to_score; ++i) { |
588 const bool typed_visit = fix_frequency_bugs_ ? | 588 const ui::PageTransition page_transition = fix_frequency_bugs_ ? |
589 (visits[i].second & ui::PAGE_TRANSITION_TYPED) : | 589 ui::PageTransitionStripQualifier(visits[i].second) : visits[i].second; |
590 (visits[i].second == ui::PAGE_TRANSITION_TYPED); | 590 int value_of_transition = |
591 int value_of_transition = typed_visit ? 20 : 1; | 591 (page_transition == ui::PAGE_TRANSITION_TYPED) ? 20 : 1; |
592 if (bookmarked) | 592 if (bookmarked) |
593 value_of_transition = std::max(value_of_transition, bookmark_value_); | 593 value_of_transition = std::max(value_of_transition, bookmark_value_); |
594 const float bucket_weight = | 594 const float bucket_weight = |
595 GetRecencyScore((now - visits[i].first).InDays()); | 595 GetRecencyScore((now - visits[i].first).InDays()); |
596 summed_visit_points += (value_of_transition * bucket_weight); | 596 summed_visit_points += (value_of_transition * bucket_weight); |
597 } | 597 } |
598 if (fix_frequency_bugs_) | 598 if (fix_frequency_bugs_) |
599 return summed_visit_points / ScoredHistoryMatch::kMaxVisitsToScore; | 599 return summed_visit_points / ScoredHistoryMatch::kMaxVisitsToScore; |
600 return visits.size() * summed_visit_points / | 600 return visits.size() * summed_visit_points / |
601 ScoredHistoryMatch::kMaxVisitsToScore; | 601 ScoredHistoryMatch::kMaxVisitsToScore; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 base::StringToDouble(it->first, &bucket.first); | 705 base::StringToDouble(it->first, &bucket.first); |
706 DCHECK(is_valid_intermediate_score); | 706 DCHECK(is_valid_intermediate_score); |
707 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); | 707 bool is_valid_hqp_score = base::StringToInt(it->second, &bucket.second); |
708 DCHECK(is_valid_hqp_score); | 708 DCHECK(is_valid_hqp_score); |
709 hqp_buckets->push_back(bucket); | 709 hqp_buckets->push_back(bucket); |
710 } | 710 } |
711 return true; | 711 return true; |
712 } | 712 } |
713 return false; | 713 return false; |
714 } | 714 } |
OLD | NEW |