| 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/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" | |
| 22 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 23 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 24 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
| 25 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 26 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 27 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 29 | 28 |
| 30 #if defined(ENABLE_EXTENSIONS) | 29 #if defined(ENABLE_EXTENSIONS) |
| 31 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h" | 30 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (extensions_delegate_) | 333 if (extensions_delegate_) |
| 335 extensions_delegate_->MaybeEndExtensionKeywordMode(); | 334 extensions_delegate_->MaybeEndExtensionKeywordMode(); |
| 336 } | 335 } |
| 337 | 336 |
| 338 KeywordProvider::~KeywordProvider() {} | 337 KeywordProvider::~KeywordProvider() {} |
| 339 | 338 |
| 340 // static | 339 // static |
| 341 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, | 340 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, |
| 342 base::string16* keyword, | 341 base::string16* keyword, |
| 343 base::string16* remaining_input) { | 342 base::string16* remaining_input) { |
| 344 if ((input.type() == metrics::OmniboxInputType::INVALID) || | 343 if ((input.type() == AutocompleteInput::INVALID) || |
| 345 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) | 344 (input.type() == AutocompleteInput::FORCED_QUERY)) |
| 346 return false; | 345 return false; |
| 347 | 346 |
| 348 *keyword = TemplateURLService::CleanUserInputKeyword( | 347 *keyword = TemplateURLService::CleanUserInputKeyword( |
| 349 SplitKeywordFromInput(input.text(), true, remaining_input)); | 348 SplitKeywordFromInput(input.text(), true, remaining_input)); |
| 350 return !keyword->empty(); | 349 return !keyword->empty(); |
| 351 } | 350 } |
| 352 | 351 |
| 353 // static | 352 // static |
| 354 int KeywordProvider::CalculateRelevance(metrics::OmniboxInputType::Type type, | 353 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, |
| 355 bool complete, | 354 bool complete, |
| 356 bool supports_replacement, | 355 bool supports_replacement, |
| 357 bool prefer_keyword, | 356 bool prefer_keyword, |
| 358 bool allow_exact_keyword_match) { | 357 bool allow_exact_keyword_match) { |
| 359 // This function is responsible for scoring suggestions of keywords | 358 // This function is responsible for scoring suggestions of keywords |
| 360 // themselves and the suggestion of the verbatim query on an | 359 // themselves and the suggestion of the verbatim query on an |
| 361 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim() | 360 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim() |
| 362 // scores verbatim query suggestions for non-extension keywords. | 361 // scores verbatim query suggestions for non-extension keywords. |
| 363 // These two functions are currently in sync, but there's no reason | 362 // These two functions are currently in sync, but there's no reason |
| 364 // we couldn't decide in the future to score verbatim matches | 363 // we couldn't decide in the future to score verbatim matches |
| 365 // differently for extension and non-extension keywords. If you | 364 // differently for extension and non-extension keywords. If you |
| 366 // make such a change, however, you should update this comment to | 365 // make such a change, however, you should update this comment to |
| 367 // describe it, so it's clear why the functions diverge. | 366 // describe it, so it's clear why the functions diverge. |
| 368 if (!complete) | 367 if (!complete) |
| 369 return (type == metrics::OmniboxInputType::URL) ? 700 : 450; | 368 return (type == AutocompleteInput::URL) ? 700 : 450; |
| 370 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) | 369 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) |
| 371 return 1500; | 370 return 1500; |
| 372 return (allow_exact_keyword_match && | 371 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? |
| 373 (type == metrics::OmniboxInputType::QUERY)) ? | |
| 374 1450 : 1100; | 372 1450 : 1100; |
| 375 } | 373 } |
| 376 | 374 |
| 377 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( | 375 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
| 378 const TemplateURL* template_url, | 376 const TemplateURL* template_url, |
| 379 const AutocompleteInput& input, | 377 const AutocompleteInput& input, |
| 380 size_t prefix_length, | 378 size_t prefix_length, |
| 381 const base::string16& remaining_input, | 379 const base::string16& remaining_input, |
| 382 bool allowed_to_be_default_match, | 380 bool allowed_to_be_default_match, |
| 383 int relevance) { | 381 int relevance) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 476 |
| 479 TemplateURLService* KeywordProvider::GetTemplateURLService() const { | 477 TemplateURLService* KeywordProvider::GetTemplateURLService() const { |
| 480 TemplateURLService* service = profile_ ? | 478 TemplateURLService* service = profile_ ? |
| 481 TemplateURLServiceFactory::GetForProfile(profile_) : model_; | 479 TemplateURLServiceFactory::GetForProfile(profile_) : model_; |
| 482 // Make sure the model is loaded. This is cheap and quickly bails out if | 480 // Make sure the model is loaded. This is cheap and quickly bails out if |
| 483 // the model is already loaded. | 481 // the model is already loaded. |
| 484 DCHECK(service); | 482 DCHECK(service); |
| 485 service->Load(); | 483 service->Load(); |
| 486 return service; | 484 return service; |
| 487 } | 485 } |
| OLD | NEW |