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

Side by Side Diff: components/omnibox/keyword_provider.cc

Issue 836213002: Assume all providers may give zero suggest responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A style fix Created 5 years, 11 months 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 "components/omnibox/keyword_provider.h" 5 #include "components/omnibox/keyword_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 const base::string16& text, 192 const base::string16& text,
193 const base::string16& keyword, 193 const base::string16& keyword,
194 const AutocompleteInput& input) { 194 const AutocompleteInput& input) {
195 // A verbatim match is allowed to be the default match. 195 // A verbatim match is allowed to be the default match.
196 return CreateAutocompleteMatch( 196 return CreateAutocompleteMatch(
197 GetTemplateURLService()->GetTemplateURLForKeyword(keyword), input, 197 GetTemplateURLService()->GetTemplateURLForKeyword(keyword), input,
198 keyword.length(), SplitReplacementStringFromInput(text, true), true, 0); 198 keyword.length(), SplitReplacementStringFromInput(text, true), true, 0);
199 } 199 }
200 200
201 void KeywordProvider::Start(const AutocompleteInput& input, 201 void KeywordProvider::Start(const AutocompleteInput& input,
202 bool minimal_changes) { 202 bool minimal_changes,
203 bool on_focus) {
203 // This object ensures we end keyword mode if we exit the function without 204 // This object ensures we end keyword mode if we exit the function without
204 // toggling keyword mode to on. 205 // toggling keyword mode to on.
205 ScopedEndExtensionKeywordMode keyword_mode_toggle(extensions_delegate_.get()); 206 ScopedEndExtensionKeywordMode keyword_mode_toggle(extensions_delegate_.get());
206 207
207 matches_.clear(); 208 matches_.clear();
208 209
209 if (!minimal_changes) { 210 if (!minimal_changes) {
210 done_ = true; 211 done_ = true;
211 212
212 // Input has changed. Increment the input ID so that we can discard any 213 // Input has changed. Increment the input ID so that we can discard any
213 // stale extension suggestions that may be incoming. 214 // stale extension suggestions that may be incoming.
214 if (extensions_delegate_) 215 if (extensions_delegate_)
215 extensions_delegate_->IncrementInputId(); 216 extensions_delegate_->IncrementInputId();
216 } 217 }
217 218
218 // Split user input into a keyword and some query input. 219 // Split user input into a keyword and some query input.
219 // 220 //
220 // We want to suggest keywords even when users have started typing URLs, on 221 // We want to suggest keywords even when users have started typing URLs, on
221 // the assumption that they might not realize they no longer need to go to a 222 // the assumption that they might not realize they no longer need to go to a
222 // site to be able to search it. So we call CleanUserInputKeyword() to strip 223 // site to be able to search it. So we call CleanUserInputKeyword() to strip
223 // any initial scheme and/or "www.". NOTE: Any heuristics or UI used to 224 // any initial scheme and/or "www.". NOTE: Any heuristics or UI used to
224 // automatically/manually create keywords will need to be in sync with 225 // automatically/manually create keywords will need to be in sync with
225 // whatever we do here! 226 // whatever we do here!
226 // 227 //
227 // TODO(pkasting): http://crbug/347744 If someday we remember usage frequency 228 // TODO(pkasting): http://crbug/347744 If someday we remember usage frequency
228 // for keywords, we might suggest keywords that haven't even been partially 229 // for keywords, we might suggest keywords that haven't even been partially
229 // typed, if the user uses them enough and isn't obviously typing something 230 // typed, if the user uses them enough and isn't obviously typing something
230 // else. In this case we'd consider all input here to be query input. 231 // else. In this case we'd consider all input here to be query input.
231 base::string16 keyword, remaining_input; 232 base::string16 keyword, remaining_input;
232 if (!ExtractKeywordFromInput(input, &keyword, &remaining_input)) 233 if (on_focus || !ExtractKeywordFromInput(input, &keyword, &remaining_input))
Peter Kasting 2015/01/07 20:16:36 Nit: I would probably do this in a separate condit
Maria 2015/01/08 07:52:38 Done.
233 return; 234 return;
234 235
235 // Get the best matches for this keyword. 236 // Get the best matches for this keyword.
236 // 237 //
237 // NOTE: We could cache the previous keywords and reuse them here in the 238 // NOTE: We could cache the previous keywords and reuse them here in the
238 // |minimal_changes| case, but since we'd still have to recalculate their 239 // |minimal_changes| case, but since we'd still have to recalculate their
239 // relevances and we can just recreate the results synchronously anyway, we 240 // relevances and we can just recreate the results synchronously anyway, we
240 // don't bother. 241 // don't bother.
241 TemplateURLService::TemplateURLVector matches; 242 TemplateURLService::TemplateURLVector matches;
242 GetTemplateURLService()->FindMatchingKeywords( 243 GetTemplateURLService()->FindMatchingKeywords(
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 ACMatchClassification::NONE, &match->contents_class); 463 ACMatchClassification::NONE, &match->contents_class);
463 } 464 }
464 } 465 }
465 466
466 TemplateURLService* KeywordProvider::GetTemplateURLService() const { 467 TemplateURLService* KeywordProvider::GetTemplateURLService() const {
467 // Make sure the model is loaded. This is cheap and quickly bails out if 468 // Make sure the model is loaded. This is cheap and quickly bails out if
468 // the model is already loaded. 469 // the model is already loaded.
469 model_->Load(); 470 model_->Load();
470 return model_; 471 return model_;
471 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698