| 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/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 using history::ScoredHistoryMatches; | 50 using history::ScoredHistoryMatches; |
| 51 | 51 |
| 52 bool HistoryQuickProvider::disabled_ = false; | 52 bool HistoryQuickProvider::disabled_ = false; |
| 53 | 53 |
| 54 HistoryQuickProvider::HistoryQuickProvider( | 54 HistoryQuickProvider::HistoryQuickProvider( |
| 55 AutocompleteProviderListener* listener, | 55 AutocompleteProviderListener* listener, |
| 56 Profile* profile) | 56 Profile* profile) |
| 57 : HistoryProvider(listener, profile, | 57 : HistoryProvider(listener, profile, |
| 58 AutocompleteProvider::TYPE_HISTORY_QUICK), | 58 AutocompleteProvider::TYPE_HISTORY_QUICK), |
| 59 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), | 59 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), |
| 60 reorder_for_inlining_(false) { | 60 local_reorder_for_inlining_(false), |
| 61 omnibox_will_reorder_for_inlining_( |
| 62 OmniboxFieldTrial::InReorderForInliningGroup()) { |
| 61 enum InliningOption { | 63 enum InliningOption { |
| 62 INLINING_PROHIBITED = 0, | 64 INLINING_PROHIBITED = 0, |
| 63 INLINING_ALLOWED = 1, | 65 INLINING_ALLOWED = 1, |
| 64 INLINING_AUTO_BUT_NOT_IN_FIELD_TRIAL = 2, | 66 INLINING_AUTO_BUT_NOT_IN_FIELD_TRIAL = 2, |
| 65 INLINING_FIELD_TRIAL_DEFAULT_GROUP = 3, | 67 INLINING_FIELD_TRIAL_DEFAULT_GROUP = 3, |
| 66 INLINING_FIELD_TRIAL_EXPERIMENT_GROUP = 4, | 68 INLINING_FIELD_TRIAL_EXPERIMENT_GROUP = 4, |
| 67 NUM_OPTIONS = 5 | 69 NUM_OPTIONS = 5 |
| 68 }; | 70 }; |
| 69 // should always be overwritten | 71 // should always be overwritten |
| 70 InliningOption inlining_option = NUM_OPTIONS; | 72 InliningOption inlining_option = NUM_OPTIONS; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 | 111 |
| 110 // Add a beacon to the logs that'll allow us to identify later what | 112 // Add a beacon to the logs that'll allow us to identify later what |
| 111 // inlining state a user is in. Do this by incrementing a bucket in | 113 // inlining state a user is in. Do this by incrementing a bucket in |
| 112 // a histogram, where the bucket represents the user's inlining state. | 114 // a histogram, where the bucket represents the user's inlining state. |
| 113 UMA_HISTOGRAM_ENUMERATION( | 115 UMA_HISTOGRAM_ENUMERATION( |
| 114 "Omnibox.InlineHistoryQuickProviderFieldTrialBeacon", | 116 "Omnibox.InlineHistoryQuickProviderFieldTrialBeacon", |
| 115 inlining_option, NUM_OPTIONS); | 117 inlining_option, NUM_OPTIONS); |
| 116 | 118 |
| 117 reorder_for_inlining_ = CommandLine::ForCurrentProcess()-> | 119 local_reorder_for_inlining_ = CommandLine::ForCurrentProcess()-> |
| 118 GetSwitchValueASCII(switches:: | 120 GetSwitchValueASCII(switches:: |
| 119 kOmniboxHistoryQuickProviderReorderForInlining) == | 121 kOmniboxHistoryQuickProviderReorderForInlining) == |
| 120 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled; | 122 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled; |
| 121 } | 123 } |
| 122 | 124 |
| 123 void HistoryQuickProvider::Start(const AutocompleteInput& input, | 125 void HistoryQuickProvider::Start(const AutocompleteInput& input, |
| 124 bool minimal_changes) { | 126 bool minimal_changes) { |
| 125 matches_.clear(); | 127 matches_.clear(); |
| 126 if (disabled_) | 128 if (disabled_) |
| 127 return; | 129 return; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 177 |
| 176 // If we're allowed to reorder results in order to get an inlineable | 178 // If we're allowed to reorder results in order to get an inlineable |
| 177 // result to appear first (and hence have a HistoryQuickProvider | 179 // result to appear first (and hence have a HistoryQuickProvider |
| 178 // suggestion possibly appear first), find the first inlineable | 180 // suggestion possibly appear first), find the first inlineable |
| 179 // result and then swap it to the front. Obviously, don't do this | 181 // result and then swap it to the front. Obviously, don't do this |
| 180 // if we're told to prevent inline autocompletion. (If we're told | 182 // if we're told to prevent inline autocompletion. (If we're told |
| 181 // we're going to prevent inline autocompletion, we're going to | 183 // we're going to prevent inline autocompletion, we're going to |
| 182 // later demote the score of all results so none will be inlined. | 184 // later demote the score of all results so none will be inlined. |
| 183 // Hence there's no need to reorder the results so an inlineable one | 185 // Hence there's no need to reorder the results so an inlineable one |
| 184 // appears first.) | 186 // appears first.) |
| 185 if (reorder_for_inlining_ && | 187 if (local_reorder_for_inlining_ && |
| 186 !PreventInlineAutocomplete(autocomplete_input_)) { | 188 !PreventInlineAutocomplete(autocomplete_input_)) { |
| 187 for (ScoredHistoryMatches::iterator i(matches.begin()); | 189 for (ScoredHistoryMatches::iterator i(matches.begin()); |
| 188 (i != matches.end()) && | 190 (i != matches.end()) && |
| 189 (i->raw_score >= AutocompleteResult::kLowestDefaultScore); | 191 (i->raw_score >= AutocompleteResult::kLowestDefaultScore); |
| 190 ++i) { | 192 ++i) { |
| 191 if (i->can_inline) { // this test is only true once because of the break | 193 if (i->can_inline) { // this test is only true once because of the break |
| 192 if (i != matches.begin()) | 194 if (i != matches.begin()) |
| 193 std::rotate(matches.begin(), i, i + 1); | 195 std::rotate(matches.begin(), i, i + 1); |
| 194 break; | 196 break; |
| 195 } | 197 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // visited URLs to beat out any longer URLs, no matter how frequently | 300 // visited URLs to beat out any longer URLs, no matter how frequently |
| 299 // they're visited.) The strength of this last reduction depends on the | 301 // they're visited.) The strength of this last reduction depends on the |
| 300 // likely score for the URL-what-you-typed result. | 302 // likely score for the URL-what-you-typed result. |
| 301 | 303 |
| 302 // |template_url_service| or |template_url| can be NULL in unit tests. | 304 // |template_url_service| or |template_url| can be NULL in unit tests. |
| 303 TemplateURLService* template_url_service = | 305 TemplateURLService* template_url_service = |
| 304 TemplateURLServiceFactory::GetForProfile(profile_); | 306 TemplateURLServiceFactory::GetForProfile(profile_); |
| 305 TemplateURL* template_url = template_url_service ? | 307 TemplateURL* template_url = template_url_service ? |
| 306 template_url_service->GetDefaultSearchProvider() : NULL; | 308 template_url_service->GetDefaultSearchProvider() : NULL; |
| 307 int max_match_score = (PreventInlineAutocomplete(autocomplete_input_) || | 309 int max_match_score = (PreventInlineAutocomplete(autocomplete_input_) || |
| 308 !matches.begin()->can_inline) ? | 310 (!matches.begin()->can_inline && !omnibox_will_reorder_for_inlining_)) ? |
| 309 (AutocompleteResult::kLowestDefaultScore - 1) : | 311 (AutocompleteResult::kLowestDefaultScore - 1) : |
| 310 matches.begin()->raw_score; | 312 matches.begin()->raw_score; |
| 311 if (will_have_url_what_you_typed_match_first) { | 313 if (will_have_url_what_you_typed_match_first) { |
| 312 max_match_score = std::min(max_match_score, | 314 max_match_score = std::min(max_match_score, |
| 313 url_what_you_typed_match_score - 1); | 315 url_what_you_typed_match_score - 1); |
| 314 } | 316 } |
| 315 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); | 317 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); |
| 316 match_iter != matches.end(); ++match_iter) { | 318 match_iter != matches.end(); ++match_iter) { |
| 317 const ScoredHistoryMatch& history_match(*match_iter); | 319 const ScoredHistoryMatch& history_match(*match_iter); |
| 318 // Culls results corresponding to queries from the default search engine. | 320 // Culls results corresponding to queries from the default search engine. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 do { | 419 do { |
| 418 offset += matches[i].length; | 420 offset += matches[i].length; |
| 419 ++i; | 421 ++i; |
| 420 } while ((i < match_count) && (offset == matches[i].offset)); | 422 } while ((i < match_count) && (offset == matches[i].offset)); |
| 421 if (offset < text_length) | 423 if (offset < text_length) |
| 422 spans.push_back(ACMatchClassification(offset, url_style)); | 424 spans.push_back(ACMatchClassification(offset, url_style)); |
| 423 } | 425 } |
| 424 | 426 |
| 425 return spans; | 427 return spans; |
| 426 } | 428 } |
| OLD | NEW |