OLD | NEW |
---|---|
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/base_search_provider.h" | 5 #include "chrome/browser/autocomplete/base_search_provider.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 match.RecordAdditionalInfo( | 239 match.RecordAdditionalInfo( |
240 kACMatchPropertyContentsStartIndex, | 240 kACMatchPropertyContentsStartIndex, |
241 static_cast<int>( | 241 static_cast<int>( |
242 suggestion.suggestion().length() - match.contents.length())); | 242 suggestion.suggestion().length() - match.contents.length())); |
243 } | 243 } |
244 | 244 |
245 if (!suggestion.annotation().empty()) | 245 if (!suggestion.annotation().empty()) |
246 match.description = suggestion.annotation(); | 246 match.description = suggestion.annotation(); |
247 | 247 |
248 // suggestion.match_contents() should have already been collapsed. | 248 // suggestion.match_contents() should have already been collapsed. |
249 match.allowed_to_be_default_match = | 249 match.allowed_to_be_default_match = |
msw
2014/08/14 02:57:22
Should this also consider never_allowed_to_be_defa
Mark P
2014/08/15 00:05:56
No. Something equivalent to verbatim is always al
| |
250 (base::CollapseWhitespace(input.text(), false) == | 250 (base::CollapseWhitespace(input.text(), false) == |
251 suggestion.match_contents()); | 251 suggestion.match_contents()); |
252 | 252 |
253 // When the user forced a query, we need to make sure all the fill_into_edit | 253 // When the user forced a query, we need to make sure all the fill_into_edit |
254 // values preserve that property. Otherwise, if the user starts editing a | 254 // values preserve that property. Otherwise, if the user starts editing a |
255 // suggestion, non-Search results will suddenly appear. | 255 // suggestion, non-Search results will suddenly appear. |
256 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) | 256 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) |
257 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); | 257 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); |
258 if (suggestion.from_keyword_provider()) | 258 if (suggestion.from_keyword_provider()) |
259 match.fill_into_edit.append(match.keyword + base::char16(' ')); | 259 match.fill_into_edit.append(match.keyword + base::char16(' ')); |
260 if (!input.prevent_inline_autocomplete() && | 260 if (!suggestion.never_allowed_to_be_default_match() && |
261 !input.prevent_inline_autocomplete() && | |
261 StartsWith(suggestion.suggestion(), input.text(), false)) { | 262 StartsWith(suggestion.suggestion(), input.text(), false)) { |
262 match.inline_autocompletion = | 263 match.inline_autocompletion = |
263 suggestion.suggestion().substr(input.text().length()); | 264 suggestion.suggestion().substr(input.text().length()); |
264 match.allowed_to_be_default_match = true; | 265 match.allowed_to_be_default_match = true; |
265 } | 266 } |
266 match.fill_into_edit.append(suggestion.suggestion()); | 267 match.fill_into_edit.append(suggestion.suggestion()); |
267 | 268 |
268 const TemplateURLRef& search_url = template_url->url_ref(); | 269 const TemplateURLRef& search_url = template_url->url_ref(); |
269 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 270 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
270 match.search_terms_args.reset( | 271 match.search_terms_args.reset( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 bool results_updated = false; | 390 bool results_updated = false; |
390 if (request_succeeded) { | 391 if (request_succeeded) { |
391 std::string json_data = SearchSuggestionParser::ExtractJsonData(source); | 392 std::string json_data = SearchSuggestionParser::ExtractJsonData(source); |
392 scoped_ptr<base::Value> data( | 393 scoped_ptr<base::Value> data( |
393 SearchSuggestionParser::DeserializeJsonData(json_data)); | 394 SearchSuggestionParser::DeserializeJsonData(json_data)); |
394 if (data && StoreSuggestionResponse(json_data, *data.get())) | 395 if (data && StoreSuggestionResponse(json_data, *data.get())) |
395 return; | 396 return; |
396 | 397 |
397 results_updated = data.get() && ParseSuggestResults( | 398 results_updated = data.get() && ParseSuggestResults( |
398 *data.get(), is_keyword, GetResultsToFill(is_keyword)); | 399 *data.get(), is_keyword, GetResultsToFill(is_keyword)); |
400 if (results_updated) | |
401 HandleReceivedResults(is_keyword); | |
msw
2014/08/14 02:57:22
Is HandleReceivedResults really needed if we call
Mark P
2014/08/15 00:05:56
Huh. I guess not.
| |
399 } | 402 } |
400 | 403 |
401 UpdateMatches(); | 404 UpdateMatches(); |
402 if (done_ || results_updated) | 405 if (done_ || results_updated) |
403 listener_->OnProviderUpdate(results_updated); | 406 listener_->OnProviderUpdate(results_updated); |
404 } | 407 } |
405 | 408 |
406 void BaseSearchProvider::AddMatchToMap( | 409 void BaseSearchProvider::AddMatchToMap( |
407 const SearchSuggestionParser::SuggestResult& result, | 410 const SearchSuggestionParser::SuggestResult& result, |
408 const std::string& metadata, | 411 const std::string& metadata, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 void BaseSearchProvider::SortResults(bool is_keyword, | 512 void BaseSearchProvider::SortResults(bool is_keyword, |
510 SearchSuggestionParser::Results* results) { | 513 SearchSuggestionParser::Results* results) { |
511 } | 514 } |
512 | 515 |
513 bool BaseSearchProvider::StoreSuggestionResponse( | 516 bool BaseSearchProvider::StoreSuggestionResponse( |
514 const std::string& json_data, | 517 const std::string& json_data, |
515 const base::Value& parsed_data) { | 518 const base::Value& parsed_data) { |
516 return false; | 519 return false; |
517 } | 520 } |
518 | 521 |
522 void BaseSearchProvider::HandleReceivedResults(bool is_keyword) { | |
523 } | |
524 | |
519 void BaseSearchProvider::ModifyProviderInfo( | 525 void BaseSearchProvider::ModifyProviderInfo( |
520 metrics::OmniboxEventProto_ProviderInfo* provider_info) const { | 526 metrics::OmniboxEventProto_ProviderInfo* provider_info) const { |
521 } | 527 } |
522 | 528 |
523 void BaseSearchProvider::DeleteMatchFromMatches( | 529 void BaseSearchProvider::DeleteMatchFromMatches( |
524 const AutocompleteMatch& match) { | 530 const AutocompleteMatch& match) { |
525 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 531 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
526 // Find the desired match to delete by checking the type and contents. | 532 // Find the desired match to delete by checking the type and contents. |
527 // We can't check the destination URL, because the autocomplete controller | 533 // We can't check the destination URL, because the autocomplete controller |
528 // may have reformulated that. Not that while checking for matching | 534 // may have reformulated that. Not that while checking for matching |
529 // contents works for personalized suggestions, if more match types gain | 535 // contents works for personalized suggestions, if more match types gain |
530 // deletion support, this algorithm may need to be re-examined. | 536 // deletion support, this algorithm may need to be re-examined. |
531 if (i->contents == match.contents && i->type == match.type) { | 537 if (i->contents == match.contents && i->type == match.type) { |
532 matches_.erase(i); | 538 matches_.erase(i); |
533 break; | 539 break; |
534 } | 540 } |
535 } | 541 } |
536 } | 542 } |
537 | 543 |
538 void BaseSearchProvider::OnDeletionComplete( | 544 void BaseSearchProvider::OnDeletionComplete( |
539 bool success, SuggestionDeletionHandler* handler) { | 545 bool success, SuggestionDeletionHandler* handler) { |
540 RecordDeletionResult(success); | 546 RecordDeletionResult(success); |
541 SuggestionDeletionHandlers::iterator it = std::find( | 547 SuggestionDeletionHandlers::iterator it = std::find( |
542 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 548 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
543 DCHECK(it != deletion_handlers_.end()); | 549 DCHECK(it != deletion_handlers_.end()); |
544 deletion_handlers_.erase(it); | 550 deletion_handlers_.erase(it); |
545 } | 551 } |
OLD | NEW |