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

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

Issue 319523005: Omnibox: Combine Two Input Type Enums into One (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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/keyword_provider.h" 5 #include "chrome/browser/autocomplete/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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
15 #include "chrome/browser/autocomplete/keyword_extensions_delegate.h" 15 #include "chrome/browser/autocomplete/keyword_extensions_delegate.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url.h" 18 #include "chrome/browser/search_engines/template_url.h"
19 #include "chrome/browser/search_engines/template_url_service.h" 19 #include "chrome/browser/search_engines/template_url_service.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 20 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "components/metrics/proto/omnibox_input_type.pb.h"
21 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
23 #include "extensions/browser/extension_system.h" 24 #include "extensions/browser/extension_system.h"
24 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
25 #include "net/base/escape.h" 26 #include "net/base/escape.h"
26 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
27 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
28 29
29 #if defined(ENABLE_EXTENSIONS) 30 #if defined(ENABLE_EXTENSIONS)
30 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h" 31 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (extensions_delegate_) 334 if (extensions_delegate_)
334 extensions_delegate_->MaybeEndExtensionKeywordMode(); 335 extensions_delegate_->MaybeEndExtensionKeywordMode();
335 } 336 }
336 337
337 KeywordProvider::~KeywordProvider() {} 338 KeywordProvider::~KeywordProvider() {}
338 339
339 // static 340 // static
340 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, 341 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input,
341 base::string16* keyword, 342 base::string16* keyword,
342 base::string16* remaining_input) { 343 base::string16* remaining_input) {
343 if ((input.type() == AutocompleteInput::INVALID) || 344 if ((input.type() == metrics::OmniboxInputType::INVALID) ||
344 (input.type() == AutocompleteInput::FORCED_QUERY)) 345 (input.type() == metrics::OmniboxInputType::FORCED_QUERY))
345 return false; 346 return false;
346 347
347 *keyword = TemplateURLService::CleanUserInputKeyword( 348 *keyword = TemplateURLService::CleanUserInputKeyword(
348 SplitKeywordFromInput(input.text(), true, remaining_input)); 349 SplitKeywordFromInput(input.text(), true, remaining_input));
349 return !keyword->empty(); 350 return !keyword->empty();
350 } 351 }
351 352
352 // static 353 // static
353 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, 354 int KeywordProvider::CalculateRelevance(metrics::OmniboxInputType::Type type,
354 bool complete, 355 bool complete,
355 bool supports_replacement, 356 bool supports_replacement,
356 bool prefer_keyword, 357 bool prefer_keyword,
357 bool allow_exact_keyword_match) { 358 bool allow_exact_keyword_match) {
358 // This function is responsible for scoring suggestions of keywords 359 // This function is responsible for scoring suggestions of keywords
359 // themselves and the suggestion of the verbatim query on an 360 // themselves and the suggestion of the verbatim query on an
360 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim() 361 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim()
361 // scores verbatim query suggestions for non-extension keywords. 362 // scores verbatim query suggestions for non-extension keywords.
362 // These two functions are currently in sync, but there's no reason 363 // These two functions are currently in sync, but there's no reason
363 // we couldn't decide in the future to score verbatim matches 364 // we couldn't decide in the future to score verbatim matches
364 // differently for extension and non-extension keywords. If you 365 // differently for extension and non-extension keywords. If you
365 // make such a change, however, you should update this comment to 366 // make such a change, however, you should update this comment to
366 // describe it, so it's clear why the functions diverge. 367 // describe it, so it's clear why the functions diverge.
367 if (!complete) 368 if (!complete)
368 return (type == AutocompleteInput::URL) ? 700 : 450; 369 return (type == metrics::OmniboxInputType::URL) ? 700 : 450;
369 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) 370 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword))
370 return 1500; 371 return 1500;
371 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? 372 return (allow_exact_keyword_match &&
373 (type == metrics::OmniboxInputType::QUERY)) ?
372 1450 : 1100; 374 1450 : 1100;
373 } 375 }
374 376
375 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( 377 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
376 const TemplateURL* template_url, 378 const TemplateURL* template_url,
377 const AutocompleteInput& input, 379 const AutocompleteInput& input,
378 size_t prefix_length, 380 size_t prefix_length,
379 const base::string16& remaining_input, 381 const base::string16& remaining_input,
380 bool allowed_to_be_default_match, 382 bool allowed_to_be_default_match,
381 int relevance) { 383 int relevance) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 478
477 TemplateURLService* KeywordProvider::GetTemplateURLService() const { 479 TemplateURLService* KeywordProvider::GetTemplateURLService() const {
478 TemplateURLService* service = profile_ ? 480 TemplateURLService* service = profile_ ?
479 TemplateURLServiceFactory::GetForProfile(profile_) : model_; 481 TemplateURLServiceFactory::GetForProfile(profile_) : model_;
480 // Make sure the model is loaded. This is cheap and quickly bails out if 482 // Make sure the model is loaded. This is cheap and quickly bails out if
481 // the model is already loaded. 483 // the model is already loaded.
482 DCHECK(service); 484 DCHECK(service);
483 service->Load(); 485 service->Load();
484 return service; 486 return service;
485 } 487 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider.h ('k') | chrome/browser/autocomplete/search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698