Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(686)

Side by Side Diff: chrome/browser/autocomplete/keyword_extensions_delegate_impl.cc

Issue 1411543011: Omnibox: Make Keyword Provide More Generous with Matching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: finish converting AddToMap() calls Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h" 5 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 8 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_util.h" 10 #include "chrome/browser/extensions/extension_util.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for (size_t i = 0; i < suggestions.suggest_results.size(); ++i) { 172 for (size_t i = 0; i < suggestions.suggest_results.size(); ++i) {
173 const omnibox_api::SuggestResult& suggestion = 173 const omnibox_api::SuggestResult& suggestion =
174 *suggestions.suggest_results[i]; 174 *suggestions.suggest_results[i];
175 // We want to order these suggestions in descending order, so start with 175 // We want to order these suggestions in descending order, so start with
176 // the relevance of the first result (added synchronously in Start()), 176 // the relevance of the first result (added synchronously in Start()),
177 // and subtract 1 for each subsequent suggestion from the extension. 177 // and subtract 1 for each subsequent suggestion from the extension.
178 // We recompute the first match's relevance; we know that |complete| 178 // We recompute the first match's relevance; we know that |complete|
179 // is true, because we wouldn't get results from the extension unless 179 // is true, because we wouldn't get results from the extension unless
180 // the full keyword had been typed. 180 // the full keyword had been typed.
181 int first_relevance = KeywordProvider::CalculateRelevance( 181 int first_relevance = KeywordProvider::CalculateRelevance(
182 input.type(), true, true, input.prefer_keyword(), 182 input.type(), true, true, true, input.prefer_keyword(),
183 input.allow_exact_keyword_match()); 183 input.allow_exact_keyword_match());
184 // Because these matches are async, we should never let them become the 184 // Because these matches are async, we should never let them become the
185 // default match, lest we introduce race conditions in the omnibox user 185 // default match, lest we introduce race conditions in the omnibox user
186 // interaction. 186 // interaction.
187 extension_suggest_matches_.push_back( 187 extension_suggest_matches_.push_back(
188 provider_->CreateAutocompleteMatch( 188 provider_->CreateAutocompleteMatch(
189 template_url, input, keyword.length(), 189 template_url, keyword.length(), input, keyword.length(),
190 base::UTF8ToUTF16(suggestion.content), false, 190 base::UTF8ToUTF16(suggestion.content), false,
191 first_relevance - (i + 1))); 191 first_relevance - (i + 1)));
192 192
193 AutocompleteMatch* match = &extension_suggest_matches_.back(); 193 AutocompleteMatch* match = &extension_suggest_matches_.back();
194 match->contents.assign(base::UTF8ToUTF16(suggestion.description)); 194 match->contents.assign(base::UTF8ToUTF16(suggestion.description));
195 match->contents_class = 195 match->contents_class =
196 extensions::StyleTypesToACMatchClassifications(suggestion); 196 extensions::StyleTypesToACMatchClassifications(suggestion);
197 } 197 }
198 198
199 set_done(true); 199 set_done(true);
200 matches()->insert(matches()->end(), 200 matches()->insert(matches()->end(),
201 extension_suggest_matches_.begin(), 201 extension_suggest_matches_.begin(),
202 extension_suggest_matches_.end()); 202 extension_suggest_matches_.end());
203 OnProviderUpdate(!extension_suggest_matches_.empty()); 203 OnProviderUpdate(!extension_suggest_matches_.empty());
204 return; 204 return;
205 } 205 }
206 206
207 default: 207 default:
208 NOTREACHED(); 208 NOTREACHED();
209 return; 209 return;
210 } 210 }
211 } 211 }
212 212
213 void KeywordExtensionsDelegateImpl::OnProviderUpdate(bool updated_matches) { 213 void KeywordExtensionsDelegateImpl::OnProviderUpdate(bool updated_matches) {
214 provider_->listener_->OnProviderUpdate(updated_matches); 214 provider_->listener_->OnProviderUpdate(updated_matches);
215 } 215 }
OLDNEW
« no previous file with comments | « no previous file | components/omnibox/browser/keyword_provider.h » ('j') | components/search_engines/template_url_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698