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/string16.h" | 10 #include "base/string16.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 remaining_input, -1)); | 342 remaining_input, -1)); |
343 } | 343 } |
344 } | 344 } |
345 } | 345 } |
346 | 346 |
347 void KeywordProvider::Stop(bool clear_cached_results) { | 347 void KeywordProvider::Stop(bool clear_cached_results) { |
348 done_ = true; | 348 done_ = true; |
349 MaybeEndExtensionKeywordMode(); | 349 MaybeEndExtensionKeywordMode(); |
350 } | 350 } |
351 | 351 |
352 // static | |
353 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, | |
Mark P
2013/01/21 20:18:17
This is an exact cut-and-paste.
| |
354 bool complete, | |
355 bool supports_replacement, | |
356 bool prefer_keyword, | |
357 bool allow_exact_keyword_match) { | |
358 if (!complete) | |
359 return (type == AutocompleteInput::URL) ? 700 : 450; | |
360 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) | |
361 return 1500; | |
362 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? | |
363 1450 : 1100; | |
364 } | |
365 | |
352 KeywordProvider::~KeywordProvider() {} | 366 KeywordProvider::~KeywordProvider() {} |
353 | 367 |
354 // static | 368 // static |
355 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, | 369 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, |
356 string16* keyword, | 370 string16* keyword, |
357 string16* remaining_input) { | 371 string16* remaining_input) { |
358 if ((input.type() == AutocompleteInput::INVALID) || | 372 if ((input.type() == AutocompleteInput::INVALID) || |
359 (input.type() == AutocompleteInput::FORCED_QUERY)) | 373 (input.type() == AutocompleteInput::FORCED_QUERY)) |
360 return false; | 374 return false; |
361 | 375 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], | 427 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], |
414 remaining_input.length(), match->contents.length(), | 428 remaining_input.length(), match->contents.length(), |
415 ACMatchClassification::NONE, &match->contents_class); | 429 ACMatchClassification::NONE, &match->contents_class); |
416 } else { | 430 } else { |
417 // See comments on an identical NOTREACHED() in search_provider.cc. | 431 // See comments on an identical NOTREACHED() in search_provider.cc. |
418 NOTREACHED(); | 432 NOTREACHED(); |
419 } | 433 } |
420 } | 434 } |
421 } | 435 } |
422 | 436 |
423 // static | |
424 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, | |
425 bool complete, | |
426 bool supports_replacement, | |
427 bool prefer_keyword, | |
428 bool allow_exact_keyword_match) { | |
429 if (!complete) | |
430 return (type == AutocompleteInput::URL) ? 700 : 450; | |
431 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) | |
432 return 1500; | |
433 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? | |
434 1450 : 1100; | |
435 } | |
436 | |
437 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( | 437 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
438 TemplateURLService* model, | 438 TemplateURLService* model, |
439 const string16& keyword, | 439 const string16& keyword, |
440 const AutocompleteInput& input, | 440 const AutocompleteInput& input, |
441 size_t prefix_length, | 441 size_t prefix_length, |
442 const string16& remaining_input, | 442 const string16& remaining_input, |
443 int relevance) { | 443 int relevance) { |
444 DCHECK(model); | 444 DCHECK(model); |
445 // Get keyword data from data store. | 445 // Get keyword data from data store. |
446 TemplateURL* element = model->GetTemplateURLForKeyword(keyword); | 446 TemplateURL* element = model->GetTemplateURLForKeyword(keyword); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 } | 586 } |
587 | 587 |
588 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 588 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
589 if (!current_keyword_extension_id_.empty()) { | 589 if (!current_keyword_extension_id_.empty()) { |
590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
591 profile_, current_keyword_extension_id_); | 591 profile_, current_keyword_extension_id_); |
592 | 592 |
593 current_keyword_extension_id_.clear(); | 593 current_keyword_extension_id_.clear(); |
594 } | 594 } |
595 } | 595 } |
OLD | NEW |