| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // if this match is from a keyword provider than the user is in keyword mode. | 120 // if this match is from a keyword provider than the user is in keyword mode. |
| 121 return CreateSearchSuggestion( | 121 return CreateSearchSuggestion( |
| 122 NULL, AutocompleteInput(), from_keyword_provider, | 122 NULL, AutocompleteInput(), from_keyword_provider, |
| 123 SearchSuggestionParser::SuggestResult( | 123 SearchSuggestionParser::SuggestResult( |
| 124 suggestion, type, suggestion, base::string16(), base::string16(), | 124 suggestion, type, suggestion, base::string16(), base::string16(), |
| 125 base::string16(), base::string16(), std::string(), std::string(), | 125 base::string16(), base::string16(), std::string(), std::string(), |
| 126 from_keyword_provider, 0, false, false, base::string16()), | 126 from_keyword_provider, 0, false, false, base::string16()), |
| 127 template_url, search_terms_data, 0, false); | 127 template_url, search_terms_data, 0, false); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void BaseSearchProvider::Stop(bool clear_cached_results) { | |
| 131 StopSuggest(); | |
| 132 done_ = true; | |
| 133 | |
| 134 if (clear_cached_results) | |
| 135 ClearAllResults(); | |
| 136 } | |
| 137 | |
| 138 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { | 130 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 139 DCHECK(match.deletable); | 131 DCHECK(match.deletable); |
| 140 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { | 132 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { |
| 141 deletion_handlers_.push_back(new SuggestionDeletionHandler( | 133 deletion_handlers_.push_back(new SuggestionDeletionHandler( |
| 142 match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey), | 134 match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey), |
| 143 profile_, | 135 profile_, |
| 144 base::Bind(&BaseSearchProvider::OnDeletionComplete, | 136 base::Bind(&BaseSearchProvider::OnDeletionComplete, |
| 145 base::Unretained(this)))); | 137 base::Unretained(this)))); |
| 146 } | 138 } |
| 147 | 139 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 169 std::vector<uint32> field_trial_hashes; | 161 std::vector<uint32> field_trial_hashes; |
| 170 OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes(&field_trial_hashes); | 162 OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes(&field_trial_hashes); |
| 171 for (size_t i = 0; i < field_trial_hashes.size(); ++i) { | 163 for (size_t i = 0; i < field_trial_hashes.size(); ++i) { |
| 172 if (field_trial_triggered_) | 164 if (field_trial_triggered_) |
| 173 new_entry.mutable_field_trial_triggered()->Add(field_trial_hashes[i]); | 165 new_entry.mutable_field_trial_triggered()->Add(field_trial_hashes[i]); |
| 174 if (field_trial_triggered_in_session_) { | 166 if (field_trial_triggered_in_session_) { |
| 175 new_entry.mutable_field_trial_triggered_in_session()->Add( | 167 new_entry.mutable_field_trial_triggered_in_session()->Add( |
| 176 field_trial_hashes[i]); | 168 field_trial_hashes[i]); |
| 177 } | 169 } |
| 178 } | 170 } |
| 179 ModifyProviderInfo(&new_entry); | |
| 180 } | 171 } |
| 181 | 172 |
| 182 // static | 173 // static |
| 183 const char BaseSearchProvider::kRelevanceFromServerKey[] = | 174 const char BaseSearchProvider::kRelevanceFromServerKey[] = |
| 184 "relevance_from_server"; | 175 "relevance_from_server"; |
| 185 const char BaseSearchProvider::kShouldPrefetchKey[] = "should_prefetch"; | 176 const char BaseSearchProvider::kShouldPrefetchKey[] = "should_prefetch"; |
| 186 const char BaseSearchProvider::kSuggestMetadataKey[] = "suggest_metadata"; | 177 const char BaseSearchProvider::kSuggestMetadataKey[] = "suggest_metadata"; |
| 187 const char BaseSearchProvider::kDeletionUrlKey[] = "deletion_url"; | 178 const char BaseSearchProvider::kDeletionUrlKey[] = "deletion_url"; |
| 188 const char BaseSearchProvider::kTrue[] = "true"; | 179 const char BaseSearchProvider::kTrue[] = "true"; |
| 189 const char BaseSearchProvider::kFalse[] = "false"; | 180 const char BaseSearchProvider::kFalse[] = "false"; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 for (std::vector<GURL>::const_iterator it = | 458 for (std::vector<GURL>::const_iterator it = |
| 468 results->answers_image_urls.begin(); | 459 results->answers_image_urls.begin(); |
| 469 it != results->answers_image_urls.end(); ++it) | 460 it != results->answers_image_urls.end(); ++it) |
| 470 image_service->Prefetch(*it); | 461 image_service->Prefetch(*it); |
| 471 | 462 |
| 472 field_trial_triggered_ |= results->field_trial_triggered; | 463 field_trial_triggered_ |= results->field_trial_triggered; |
| 473 field_trial_triggered_in_session_ |= results->field_trial_triggered; | 464 field_trial_triggered_in_session_ |= results->field_trial_triggered; |
| 474 return true; | 465 return true; |
| 475 } | 466 } |
| 476 | 467 |
| 477 void BaseSearchProvider::ModifyProviderInfo( | |
| 478 metrics::OmniboxEventProto_ProviderInfo* provider_info) const { | |
| 479 } | |
| 480 | |
| 481 void BaseSearchProvider::DeleteMatchFromMatches( | 468 void BaseSearchProvider::DeleteMatchFromMatches( |
| 482 const AutocompleteMatch& match) { | 469 const AutocompleteMatch& match) { |
| 483 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 470 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
| 484 // Find the desired match to delete by checking the type and contents. | 471 // Find the desired match to delete by checking the type and contents. |
| 485 // We can't check the destination URL, because the autocomplete controller | 472 // We can't check the destination URL, because the autocomplete controller |
| 486 // may have reformulated that. Not that while checking for matching | 473 // may have reformulated that. Not that while checking for matching |
| 487 // contents works for personalized suggestions, if more match types gain | 474 // contents works for personalized suggestions, if more match types gain |
| 488 // deletion support, this algorithm may need to be re-examined. | 475 // deletion support, this algorithm may need to be re-examined. |
| 489 if (i->contents == match.contents && i->type == match.type) { | 476 if (i->contents == match.contents && i->type == match.type) { |
| 490 matches_.erase(i); | 477 matches_.erase(i); |
| 491 break; | 478 break; |
| 492 } | 479 } |
| 493 } | 480 } |
| 494 } | 481 } |
| 495 | 482 |
| 496 void BaseSearchProvider::OnDeletionComplete( | 483 void BaseSearchProvider::OnDeletionComplete( |
| 497 bool success, SuggestionDeletionHandler* handler) { | 484 bool success, SuggestionDeletionHandler* handler) { |
| 498 RecordDeletionResult(success); | 485 RecordDeletionResult(success); |
| 499 SuggestionDeletionHandlers::iterator it = std::find( | 486 SuggestionDeletionHandlers::iterator it = std::find( |
| 500 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 487 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 501 DCHECK(it != deletion_handlers_.end()); | 488 DCHECK(it != deletion_handlers_.end()); |
| 502 deletion_handlers_.erase(it); | 489 deletion_handlers_.erase(it); |
| 503 } | 490 } |
| OLD | NEW |