OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/network_action_predictor.h" | 5 #include "chrome/browser/autocomplete/network_action_predictor.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 return ACTION_NONE; | 45 return ACTION_NONE; |
46 | 46 |
47 history::URLRow url_row; | 47 history::URLRow url_row; |
48 history::URLID url_id = url_db->GetRowForURL(match.destination_url, &url_row); | 48 history::URLID url_id = url_db->GetRowForURL(match.destination_url, &url_row); |
49 | 49 |
50 if (url_id == 0) | 50 if (url_id == 0) |
51 return ACTION_NONE; | 51 return ACTION_NONE; |
52 | 52 |
53 const double base_score = 1.0; | 53 const double base_score = 1.0; |
54 | 54 |
55 // This constant is ln(1/0.8) so we end up decaying to 80% of the base score | 55 // This constant is ln(1/0.65) so we end up decaying to 65% of the base score |
56 // for each week that passes. | 56 // for each week that passes. |
57 const double kLnDecayPercent = 0.2231435513142097; | 57 const double kLnDecayPercent = 0.43078291609245; |
58 base::TimeDelta time_passed = base::Time::Now() - url_row.last_visit(); | 58 base::TimeDelta time_passed = base::Time::Now() - url_row.last_visit(); |
59 | 59 |
60 // Clamp to 0. | 60 // Clamp to 0. |
61 const double decay_exponent = std::max(0.0, | 61 const double decay_exponent = std::max(0.0, |
62 kLnDecayPercent * static_cast<double>(time_passed.InMicroseconds()) / | 62 kLnDecayPercent * static_cast<double>(time_passed.InMicroseconds()) / |
63 base::Time::kMicrosecondsPerWeek); | 63 base::Time::kMicrosecondsPerWeek); |
64 | 64 |
65 const double kMaxDecaySpeedDivisor = 5.0; | 65 const double kMaxDecaySpeedDivisor = 5.0; |
66 const double kNumUsesPerDecaySpeedDivisorIncrement = 1.0; | 66 const double kNumUsesPerDecaySpeedDivisorIncrement = 2.0; |
67 const double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 67 const double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
68 (url_row.typed_count() + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 68 (url_row.typed_count() + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
69 kNumUsesPerDecaySpeedDivisorIncrement); | 69 kNumUsesPerDecaySpeedDivisorIncrement); |
70 | 70 |
71 const double confidence = base_score / exp(decay_exponent / decay_divisor); | 71 const double confidence = base_score / exp(decay_exponent / decay_divisor); |
72 | |
73 CHECK(confidence >= 0.0 && confidence <= 1.0); | 72 CHECK(confidence >= 0.0 && confidence <= 1.0); |
74 | 73 |
75 UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.Confidence", | 74 UMA_HISTOGRAM_COUNTS_100("NetworkActionPredictor.Confidence", |
76 confidence * 100); | 75 confidence * 100); |
77 | 76 |
78 for (int i = 0; i < LAST_PREDICT_ACTION; ++i) | 77 for (int i = 0; i < LAST_PREDICT_ACTION; ++i) |
79 if (confidence >= kConfidenceCutoff[i]) | 78 if (confidence >= kConfidenceCutoff[i]) |
80 return static_cast<Action>(i); | 79 return static_cast<Action>(i); |
81 return ACTION_NONE; | 80 return ACTION_NONE; |
82 } | 81 } |
83 | 82 |
84 // Return true if the suggestion type warrants a TCP/IP preconnection. | 83 // Return true if the suggestion type warrants a TCP/IP preconnection. |
85 // i.e., it is now quite likely that the user will select the related domain. | 84 // i.e., it is now quite likely that the user will select the related domain. |
86 // static | 85 // static |
87 bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) { | 86 bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) { |
88 switch (match.type) { | 87 switch (match.type) { |
89 // Matches using the user's default search engine. | 88 // Matches using the user's default search engine. |
90 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: | 89 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: |
91 case AutocompleteMatch::SEARCH_HISTORY: | 90 case AutocompleteMatch::SEARCH_HISTORY: |
92 case AutocompleteMatch::SEARCH_SUGGEST: | 91 case AutocompleteMatch::SEARCH_SUGGEST: |
93 // A match that uses a non-default search engine (e.g. for tab-to-search). | 92 // A match that uses a non-default search engine (e.g. for tab-to-search). |
94 case AutocompleteMatch::SEARCH_OTHER_ENGINE: | 93 case AutocompleteMatch::SEARCH_OTHER_ENGINE: |
95 return true; | 94 return true; |
96 | 95 |
97 default: | 96 default: |
98 return false; | 97 return false; |
99 } | 98 } |
100 } | 99 } |
OLD | NEW |