OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 } | 206 } |
207 | 207 |
208 | 208 |
209 // SearchProvider::SuggestResult ---------------------------------------------- | 209 // SearchProvider::SuggestResult ---------------------------------------------- |
210 | 210 |
211 SearchProvider::SuggestResult::SuggestResult( | 211 SearchProvider::SuggestResult::SuggestResult( |
212 const string16& suggestion, | 212 const string16& suggestion, |
213 const string16& match_contents, | 213 const string16& match_contents, |
214 const string16& annotation, | 214 const string16& annotation, |
215 const std::string& suggest_query_params, | 215 const std::string& suggest_query_params, |
216 const std::string& deletion_url, | |
216 bool from_keyword_provider, | 217 bool from_keyword_provider, |
217 int relevance, | 218 int relevance, |
218 bool relevance_from_server, | 219 bool relevance_from_server, |
219 bool should_prefetch) | 220 bool should_prefetch) |
220 : Result(from_keyword_provider, relevance, relevance_from_server), | 221 : Result(from_keyword_provider, relevance, relevance_from_server), |
221 suggestion_(suggestion), | 222 suggestion_(suggestion), |
222 match_contents_(match_contents), | 223 match_contents_(match_contents), |
223 annotation_(annotation), | 224 annotation_(annotation), |
224 suggest_query_params_(suggest_query_params), | 225 suggest_query_params_(suggest_query_params), |
226 deletion_url_(deletion_url), | |
225 should_prefetch_(should_prefetch) { | 227 should_prefetch_(should_prefetch) { |
226 } | 228 } |
227 | 229 |
228 SearchProvider::SuggestResult::~SuggestResult() { | 230 SearchProvider::SuggestResult::~SuggestResult() { |
229 } | 231 } |
230 | 232 |
231 bool SearchProvider::SuggestResult::IsInlineable(const string16& input) const { | 233 bool SearchProvider::SuggestResult::IsInlineable(const string16& input) const { |
232 return StartsWith(suggestion_, input, false); | 234 return StartsWith(suggestion_, input, false); |
233 } | 235 } |
234 | 236 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 for (NavigationResults::const_iterator i(navigation_results.begin()); | 316 for (NavigationResults::const_iterator i(navigation_results.begin()); |
315 i != navigation_results.end(); ++i) { | 317 i != navigation_results.end(); ++i) { |
316 if (i->relevance_from_server()) | 318 if (i->relevance_from_server()) |
317 return true; | 319 return true; |
318 } | 320 } |
319 | 321 |
320 return false; | 322 return false; |
321 } | 323 } |
322 | 324 |
323 | 325 |
326 // SearchProvider::SuggestionDeletionHandler --------------------------------- | |
327 SearchProvider::SuggestionDeletionHandler::SuggestionDeletionHandler() { | |
Peter Kasting
2013/11/23 00:08:43
Nit: Blank line above this
Maria
2013/11/26 02:36:27
Done.
| |
328 }; | |
329 | |
330 SearchProvider::SuggestionDeletionHandler::~SuggestionDeletionHandler() { | |
Peter Kasting
2013/11/23 00:08:43
Nit: Function definition order should match the cl
Maria
2013/11/26 02:36:27
Done.
Quick question: that doesn't seem currently
Peter Kasting
2013/11/26 02:46:22
All class definitions in all files should always m
Maria
2013/11/27 02:18:06
Done.
| |
331 }; | |
332 | |
333 void SearchProvider::SuggestionDeletionHandler::StartRequest( | |
334 const std::string& deletion_url, Profile* profile, | |
Peter Kasting
2013/11/23 00:08:43
Nit: One arg per line
Maria
2013/11/26 02:36:27
Done.
| |
335 const base::Callback<void(bool)>& callback) { | |
336 callback_ = callback; | |
337 GURL url = GURL(deletion_url); | |
Peter Kasting
2013/11/23 00:08:43
Nit: GURL url(deletion_url);
Maria
2013/11/26 02:36:27
Done. Sorry, Java habits die hard.
| |
338 if (url.is_valid()) { | |
Peter Kasting
2013/11/23 00:08:43
Perhaps we should check GURL validity in AddMatchT
Maria
2013/11/26 02:36:27
Done.
| |
339 deletion_fetcher_.reset(net::URLFetcher::Create( | |
340 SearchProvider::kDeletionURLFetcherID, | |
341 url, | |
342 net::URLFetcher::GET, | |
343 this)); | |
344 deletion_fetcher_->SetRequestContext(profile->GetRequestContext()); | |
345 deletion_fetcher_->Start(); | |
346 } else { | |
347 callback_.Run(false); | |
348 } | |
349 }; | |
350 | |
351 void SearchProvider::SuggestionDeletionHandler::OnURLFetchComplete( | |
352 const net::URLFetcher* source) { | |
353 DCHECK(source == deletion_fetcher_.get()); | |
354 const bool was_deletion_success = source->GetStatus().is_success() && | |
355 source->GetResponseCode() == 200; | |
Peter Kasting
2013/11/23 00:08:43
Nit: Parens around binary subexprs
Optional: Inli
Maria
2013/11/26 02:36:27
Done.
| |
356 callback_.Run(was_deletion_success); | |
357 delete this; | |
358 }; | |
359 | |
Peter Kasting
2013/11/23 00:08:43
Nit: One more blank line here
Maria
2013/11/26 02:36:27
Done.
| |
324 // SearchProvider ------------------------------------------------------------- | 360 // SearchProvider ------------------------------------------------------------- |
325 | 361 |
326 // static | 362 // static |
327 const int SearchProvider::kDefaultProviderURLFetcherID = 1; | 363 const int SearchProvider::kDefaultProviderURLFetcherID = 1; |
328 const int SearchProvider::kKeywordProviderURLFetcherID = 2; | 364 const int SearchProvider::kKeywordProviderURLFetcherID = 2; |
365 const int SearchProvider::kDeletionURLFetcherID = 3; | |
329 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; | 366 int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100; |
330 const char SearchProvider::kRelevanceFromServerKey[] = "relevance_from_server"; | 367 const char SearchProvider::kRelevanceFromServerKey[] = "relevance_from_server"; |
331 const char SearchProvider::kShouldPrefetchKey[] = "should_prefetch"; | 368 const char SearchProvider::kShouldPrefetchKey[] = "should_prefetch"; |
332 const char SearchProvider::kSuggestMetadataKey[] = "suggest_metadata"; | 369 const char SearchProvider::kSuggestMetadataKey[] = "suggest_metadata"; |
370 const char SearchProvider::kDeletionUrlKey[] = "deletion_url"; | |
333 const char SearchProvider::kTrue[] = "true"; | 371 const char SearchProvider::kTrue[] = "true"; |
334 const char SearchProvider::kFalse[] = "false"; | 372 const char SearchProvider::kFalse[] = "false"; |
335 | 373 |
336 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 374 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
337 Profile* profile) | 375 Profile* profile) |
338 : AutocompleteProvider(listener, profile, | 376 : AutocompleteProvider(listener, profile, |
339 AutocompleteProvider::TYPE_SEARCH), | 377 AutocompleteProvider::TYPE_SEARCH), |
340 providers_(TemplateURLServiceFactory::GetForProfile(profile)), | 378 providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
341 suggest_results_pending_(0), | 379 suggest_results_pending_(0), |
342 field_trial_triggered_(false), | 380 field_trial_triggered_(false), |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 elapsed_time); | 669 elapsed_time); |
632 } | 670 } |
633 } | 671 } |
634 | 672 |
635 bool results_updated = false; | 673 bool results_updated = false; |
636 if (request_succeeded) { | 674 if (request_succeeded) { |
637 const net::HttpResponseHeaders* const response_headers = | 675 const net::HttpResponseHeaders* const response_headers = |
638 source->GetResponseHeaders(); | 676 source->GetResponseHeaders(); |
639 std::string json_data; | 677 std::string json_data; |
640 source->GetResponseAsString(&json_data); | 678 source->GetResponseAsString(&json_data); |
679 | |
641 // JSON is supposed to be UTF-8, but some suggest service providers send | 680 // JSON is supposed to be UTF-8, but some suggest service providers send |
642 // JSON files in non-UTF-8 encodings. The actual encoding is usually | 681 // JSON files in non-UTF-8 encodings. The actual encoding is usually |
643 // specified in the Content-Type header field. | 682 // specified in the Content-Type header field. |
644 if (response_headers) { | 683 if (response_headers) { |
645 std::string charset; | 684 std::string charset; |
646 if (response_headers->GetCharset(&charset)) { | 685 if (response_headers->GetCharset(&charset)) { |
647 string16 data_16; | 686 string16 data_16; |
648 // TODO(jungshik): Switch to CodePageToUTF8 after it's added. | 687 // TODO(jungshik): Switch to CodePageToUTF8 after it's added. |
649 if (base::CodepageToUTF16(json_data, charset.c_str(), | 688 if (base::CodepageToUTF16(json_data, charset.c_str(), |
650 base::OnStringConversionError::FAIL, | 689 base::OnStringConversionError::FAIL, |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1127 results->navigation_results.push_back(NavigationResult( | 1166 results->navigation_results.push_back(NavigationResult( |
1128 *this, url, title, is_keyword, relevance, true)); | 1167 *this, url, title, is_keyword, relevance, true)); |
1129 } | 1168 } |
1130 } else { | 1169 } else { |
1131 bool should_prefetch = static_cast<int>(index) == prefetch_index; | 1170 bool should_prefetch = static_cast<int>(index) == prefetch_index; |
1132 DictionaryValue* suggestion_detail = NULL; | 1171 DictionaryValue* suggestion_detail = NULL; |
1133 string16 match_contents = suggestion; | 1172 string16 match_contents = suggestion; |
1134 string16 disambiguating_query; | 1173 string16 disambiguating_query; |
1135 string16 annotation; | 1174 string16 annotation; |
1136 std::string suggest_query_params; | 1175 std::string suggest_query_params; |
1176 std::string deletion_url; | |
1137 if (suggestion_details && (type == "ENTITY") && | 1177 if (suggestion_details && (type == "ENTITY") && |
1138 suggestion_details->GetDictionary(index, &suggestion_detail) && | 1178 suggestion_details->GetDictionary(index, &suggestion_detail) && |
1139 suggestion_detail) { | 1179 suggestion_detail) { |
1140 suggestion_detail->GetString("a", &annotation); | 1180 suggestion_detail->GetString("a", &annotation); |
1141 if (suggestion_detail->GetString("dq", &disambiguating_query) && | 1181 if (suggestion_detail->GetString("dq", &disambiguating_query) && |
1142 !disambiguating_query.empty()) | 1182 !disambiguating_query.empty()) |
1143 suggestion = disambiguating_query; | 1183 suggestion = disambiguating_query; |
1144 suggestion_detail->GetString("q", &suggest_query_params); | 1184 suggestion_detail->GetString("q", &suggest_query_params); |
1185 } else if (suggestion_details && (type == "PERSONALIZED_QUERY") && | |
1186 suggestion_details->GetDictionary(index, &suggestion_detail) && | |
1187 suggestion_detail) { | |
1188 suggestion_detail->GetString("du", &deletion_url); | |
1145 } | 1189 } |
1146 // TODO(kochi): Improve calculator suggestion presentation. | 1190 // TODO(kochi): Improve calculator suggestion presentation. |
1147 results->suggest_results.push_back(SuggestResult( | 1191 results->suggest_results.push_back(SuggestResult( |
1148 suggestion, match_contents, annotation, suggest_query_params, | 1192 suggestion, match_contents, annotation, suggest_query_params, |
1149 is_keyword, relevance, true, should_prefetch)); | 1193 deletion_url, is_keyword, relevance, true, should_prefetch)); |
1150 } | 1194 } |
1151 } | 1195 } |
1152 | 1196 |
1153 // Ignore suggested scores for non-keyword matches in keyword mode; if the | 1197 // Ignore suggested scores for non-keyword matches in keyword mode; if the |
1154 // server is allowed to score these, it could interfere with the user's | 1198 // server is allowed to score these, it could interfere with the user's |
1155 // ability to get good keyword results. | 1199 // ability to get good keyword results. |
1156 const bool abandon_suggested_scores = | 1200 const bool abandon_suggested_scores = |
1157 !is_keyword && !providers_.keyword_provider().empty(); | 1201 !is_keyword && !providers_.keyword_provider().empty(); |
1158 // Apply calculated relevance scores to suggestions if a valid list was | 1202 // Apply calculated relevance scores to suggestions if a valid list was |
1159 // not provided or we're abandoning suggested scores entirely. | 1203 // not provided or we're abandoning suggested scores entirely. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1199 relevance_from_server, | 1243 relevance_from_server, |
1200 false, | 1244 false, |
1201 std::string(), | 1245 std::string(), |
1202 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1246 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
1203 false, | 1247 false, |
1204 input_.text(), | 1248 input_.text(), |
1205 string16(), | 1249 string16(), |
1206 input_.text(), | 1250 input_.text(), |
1207 did_not_accept_default_suggestion, | 1251 did_not_accept_default_suggestion, |
1208 std::string(), | 1252 std::string(), |
1253 std::string(), | |
1209 &map); | 1254 &map); |
1210 } | 1255 } |
1211 if (!keyword_input_.text().empty()) { | 1256 if (!keyword_input_.text().empty()) { |
1212 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 1257 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
1213 // We only create the verbatim search query match for a keyword | 1258 // We only create the verbatim search query match for a keyword |
1214 // if it's not an extension keyword. Extension keywords are handled | 1259 // if it's not an extension keyword. Extension keywords are handled |
1215 // in KeywordProvider::Start(). (Extensions are complicated...) | 1260 // in KeywordProvider::Start(). (Extensions are complicated...) |
1216 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond | 1261 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
1217 // to the keyword verbatim search query. Do not create other matches | 1262 // to the keyword verbatim search query. Do not create other matches |
1218 // of type SEARCH_OTHER_ENGINE. | 1263 // of type SEARCH_OTHER_ENGINE. |
1219 if (keyword_url && | 1264 if (keyword_url && |
1220 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 1265 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
1221 bool keyword_relevance_from_server; | 1266 bool keyword_relevance_from_server; |
1222 const int keyword_verbatim_relevance = | 1267 const int keyword_verbatim_relevance = |
1223 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); | 1268 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); |
1224 if (keyword_verbatim_relevance > 0) { | 1269 if (keyword_verbatim_relevance > 0) { |
1225 AddMatchToMap(keyword_input_.text(), | 1270 AddMatchToMap(keyword_input_.text(), |
1226 keyword_verbatim_relevance, | 1271 keyword_verbatim_relevance, |
1227 keyword_relevance_from_server, | 1272 keyword_relevance_from_server, |
1228 false, | 1273 false, |
1229 std::string(), | 1274 std::string(), |
1230 AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 1275 AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
1231 true, | 1276 true, |
1232 keyword_input_.text(), | 1277 keyword_input_.text(), |
1233 string16(), | 1278 string16(), |
1234 keyword_input_.text(), | 1279 keyword_input_.text(), |
1235 did_not_accept_keyword_suggestion, | 1280 did_not_accept_keyword_suggestion, |
1236 std::string(), | 1281 std::string(), |
1282 std::string(), | |
1237 &map); | 1283 &map); |
1238 } | 1284 } |
1239 } | 1285 } |
1240 } | 1286 } |
1241 AddHistoryResultsToMap(keyword_history_results_, true, | 1287 AddHistoryResultsToMap(keyword_history_results_, true, |
1242 did_not_accept_keyword_suggestion, &map); | 1288 did_not_accept_keyword_suggestion, &map); |
1243 AddHistoryResultsToMap(default_history_results_, false, | 1289 AddHistoryResultsToMap(default_history_results_, false, |
1244 did_not_accept_default_suggestion, &map); | 1290 did_not_accept_default_suggestion, &map); |
1245 | 1291 |
1246 AddSuggestResultsToMap(keyword_results_.suggest_results, | 1292 AddSuggestResultsToMap(keyword_results_.suggest_results, |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1501 false, | 1547 false, |
1502 false, | 1548 false, |
1503 std::string(), | 1549 std::string(), |
1504 AutocompleteMatchType::SEARCH_HISTORY, | 1550 AutocompleteMatchType::SEARCH_HISTORY, |
1505 is_keyword, | 1551 is_keyword, |
1506 i->suggestion(), | 1552 i->suggestion(), |
1507 string16(), | 1553 string16(), |
1508 i->suggestion(), | 1554 i->suggestion(), |
1509 did_not_accept_suggestion, | 1555 did_not_accept_suggestion, |
1510 std::string(), | 1556 std::string(), |
1557 std::string(), | |
1511 map); | 1558 map); |
1512 } | 1559 } |
1513 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", | 1560 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", |
1514 base::TimeTicks::Now() - start_time); | 1561 base::TimeTicks::Now() - start_time); |
1515 } | 1562 } |
1516 | 1563 |
1517 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( | 1564 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( |
1518 const HistoryResults& results, | 1565 const HistoryResults& results, |
1519 bool base_prevent_inline_autocomplete, | 1566 bool base_prevent_inline_autocomplete, |
1520 bool input_multiple_words, | 1567 bool input_multiple_words, |
(...skipping 30 matching lines...) Expand all Loading... | |
1551 classifier->Classify(i->term, false, false, &match, NULL); | 1598 classifier->Classify(i->term, false, false, &match, NULL); |
1552 prevent_inline_autocomplete = | 1599 prevent_inline_autocomplete = |
1553 !AutocompleteMatch::IsSearchType(match.type); | 1600 !AutocompleteMatch::IsSearchType(match.type); |
1554 } | 1601 } |
1555 | 1602 |
1556 int relevance = CalculateRelevanceForHistory( | 1603 int relevance = CalculateRelevanceForHistory( |
1557 i->time, is_keyword, !prevent_inline_autocomplete, | 1604 i->time, is_keyword, !prevent_inline_autocomplete, |
1558 prevent_search_history_inlining); | 1605 prevent_search_history_inlining); |
1559 scored_results.push_back( | 1606 scored_results.push_back( |
1560 SuggestResult(i->term, string16(), string16(), std::string(), | 1607 SuggestResult(i->term, string16(), string16(), std::string(), |
1561 is_keyword, relevance, false, false)); | 1608 std::string(), is_keyword, relevance, false, false)); |
1562 } | 1609 } |
1563 | 1610 |
1564 // History returns results sorted for us. However, we may have docked some | 1611 // History returns results sorted for us. However, we may have docked some |
1565 // results' scores, so things are no longer in order. Do a stable sort to get | 1612 // results' scores, so things are no longer in order. Do a stable sort to get |
1566 // things back in order without otherwise disturbing results with equal | 1613 // things back in order without otherwise disturbing results with equal |
1567 // scores, then force the scores to be unique, so that the order in which | 1614 // scores, then force the scores to be unique, so that the order in which |
1568 // they're shown is deterministic. | 1615 // they're shown is deterministic. |
1569 std::stable_sort(scored_results.begin(), scored_results.end(), | 1616 std::stable_sort(scored_results.begin(), scored_results.end(), |
1570 CompareScoredResults()); | 1617 CompareScoredResults()); |
1571 int last_relevance = 0; | 1618 int last_relevance = 0; |
(...skipping 18 matching lines...) Expand all Loading... | |
1590 results[i].relevance_from_server(), | 1637 results[i].relevance_from_server(), |
1591 results[i].should_prefetch(), | 1638 results[i].should_prefetch(), |
1592 metadata, | 1639 metadata, |
1593 AutocompleteMatchType::SEARCH_SUGGEST, | 1640 AutocompleteMatchType::SEARCH_SUGGEST, |
1594 is_keyword, | 1641 is_keyword, |
1595 results[i].match_contents(), | 1642 results[i].match_contents(), |
1596 results[i].annotation(), | 1643 results[i].annotation(), |
1597 results[i].suggestion(), | 1644 results[i].suggestion(), |
1598 i, | 1645 i, |
1599 results[i].suggest_query_params(), | 1646 results[i].suggest_query_params(), |
1647 results[i].deletion_url(), | |
1600 map); | 1648 map); |
1601 } | 1649 } |
1602 } | 1650 } |
1603 | 1651 |
1604 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { | 1652 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { |
1605 // Use the suggested verbatim relevance score if it is non-negative (valid), | 1653 // Use the suggested verbatim relevance score if it is non-negative (valid), |
1606 // if inline autocomplete isn't prevented (always show verbatim on backspace), | 1654 // if inline autocomplete isn't prevented (always show verbatim on backspace), |
1607 // and if it won't suppress verbatim, leaving no default provider matches. | 1655 // and if it won't suppress verbatim, leaving no default provider matches. |
1608 // Otherwise, if the default provider returned no matches and was still able | 1656 // Otherwise, if the default provider returned no matches and was still able |
1609 // to suppress verbatim, the user would have no search/nav matches and may be | 1657 // to suppress verbatim, the user would have no search/nav matches and may be |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1702 // Don't let scores go below 0. Negative relevance scores are meaningful in | 1750 // Don't let scores go below 0. Negative relevance scores are meaningful in |
1703 // a different way. | 1751 // a different way. |
1704 int base_score; | 1752 int base_score; |
1705 if (is_primary_provider) | 1753 if (is_primary_provider) |
1706 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; | 1754 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; |
1707 else | 1755 else |
1708 base_score = 200; | 1756 base_score = 200; |
1709 return std::max(0, base_score - score_discount); | 1757 return std::max(0, base_score - score_discount); |
1710 } | 1758 } |
1711 | 1759 |
1760 void SearchProvider::DeleteMatch(const AutocompleteMatch& match) { | |
1761 // TODO(mariakhomenko): Add support for deleting search history suggestions. | |
1762 DCHECK(match.deletable); | |
1763 | |
1764 std::string deletion_url = match.GetAdditionalInfo( | |
1765 SearchProvider::kDeletionUrlKey); | |
1766 // Allocate on the heap, class will delete itself when the request is done. | |
Peter Kasting
2013/11/23 00:08:43
I think the SearchProvider should probably own thi
Maria
2013/11/26 02:36:27
Done.
| |
1767 SuggestionDeletionHandler* deletionHandler = new SuggestionDeletionHandler(); | |
1768 deletionHandler->StartRequest(deletion_url, profile_, | |
1769 base::Bind(&SearchProvider::OnDeletionComplete, base::Unretained(this))); | |
1770 // Immediately updates the list of matches to show the match was deleted, | |
1771 // regardless of whether the server request actually succeeds. | |
1772 DeleteMatchFromMatches(match); | |
1773 } | |
1774 | |
1775 void SearchProvider::OnDeletionComplete(bool success) { | |
Peter Kasting
2013/11/23 00:08:43
If we check URL validity in AddMatchToMap(), then
Maria
2013/11/26 02:36:27
True, but I thought this may be a more flexible ap
Peter Kasting
2013/11/26 02:46:22
I would say, let's add that capability when it bec
Maria
2013/11/27 02:18:06
Now this callback has another use which is to dele
| |
1776 if (success) { | |
1777 UMA_HISTOGRAM_COUNTS("Omnibox.ServerSuggestDelete.Success", 1); | |
Peter Kasting
2013/11/23 00:08:43
Nit: Is it possible to use ?: to simplify this to
Maria
2013/11/26 02:36:27
I read a bit about this and figured we should be u
| |
1778 } else { | |
1779 UMA_HISTOGRAM_COUNTS("Omnibox.ServerSuggestDelete.Failure", 1); | |
1780 } | |
1781 } | |
1782 | |
1783 void SearchProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { | |
Peter Kasting
2013/11/23 00:08:43
The body of this function is akin to the identical
Maria
2013/11/26 02:36:27
It is a similar function, but it's not identical.
Peter Kasting
2013/11/26 02:46:22
Hmm. That actually worries me. With things like
Maria
2013/11/27 02:18:06
Right now the only deletable suggestions in search
| |
1784 bool found = false; | |
1785 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | |
1786 if (i->contents == match.contents && i->type == match.type) { | |
1787 found = true; | |
1788 matches_.erase(i); | |
1789 break; | |
1790 } | |
1791 } | |
1792 DCHECK(found) << "Asked to delete a search suggestion that isn't in our set " | |
1793 << "of matches"; | |
1794 listener_->OnProviderUpdate(true); | |
1795 } | |
1796 | |
1712 void SearchProvider::AddMatchToMap(const string16& input_text, | 1797 void SearchProvider::AddMatchToMap(const string16& input_text, |
1713 int relevance, | 1798 int relevance, |
1714 bool relevance_from_server, | 1799 bool relevance_from_server, |
1715 bool should_prefetch, | 1800 bool should_prefetch, |
1716 const std::string& metadata, | 1801 const std::string& metadata, |
1717 AutocompleteMatch::Type type, | 1802 AutocompleteMatch::Type type, |
1718 bool is_keyword, | 1803 bool is_keyword, |
1719 const string16& match_contents, | 1804 const string16& match_contents, |
1720 const string16& annotation, | 1805 const string16& annotation, |
1721 const string16& query_string, | 1806 const string16& query_string, |
1722 int accepted_suggestion, | 1807 int accepted_suggestion, |
1723 const std::string& suggest_query_params, | 1808 const std::string& suggest_query_params, |
1809 const std::string& deletion_url, | |
1724 MatchMap* map) { | 1810 MatchMap* map) { |
1725 // On non-mobile, ask the instant controller for the appropriate start margin. | 1811 // On non-mobile, ask the instant controller for the appropriate start margin. |
1726 // On mobile the start margin is unused, so leave the value as default there. | 1812 // On mobile the start margin is unused, so leave the value as default there. |
1727 int omnibox_start_margin = chrome::kDisableStartMargin; | 1813 int omnibox_start_margin = chrome::kDisableStartMargin; |
1728 #if !defined(OS_ANDROID) && !defined(IOS) | 1814 #if !defined(OS_ANDROID) && !defined(IOS) |
1729 if (chrome::IsInstantExtendedAPIEnabled()) { | 1815 if (chrome::IsInstantExtendedAPIEnabled()) { |
1730 Browser* browser = | 1816 Browser* browser = |
1731 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); | 1817 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); |
1732 if (browser && browser->instant_controller() && | 1818 if (browser && browser->instant_controller() && |
1733 browser->instant_controller()->instant()) { | 1819 browser->instant_controller()->instant()) { |
(...skipping 12 matching lines...) Expand all Loading... | |
1746 !is_keyword || providers_.default_provider().empty()); | 1832 !is_keyword || providers_.default_provider().empty()); |
1747 if (!match.destination_url.is_valid()) | 1833 if (!match.destination_url.is_valid()) |
1748 return; | 1834 return; |
1749 match.search_terms_args->bookmark_bar_pinned = | 1835 match.search_terms_args->bookmark_bar_pinned = |
1750 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 1836 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
1751 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 1837 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
1752 relevance_from_server ? kTrue : kFalse); | 1838 relevance_from_server ? kTrue : kFalse); |
1753 match.RecordAdditionalInfo(kShouldPrefetchKey, | 1839 match.RecordAdditionalInfo(kShouldPrefetchKey, |
1754 should_prefetch ? kTrue : kFalse); | 1840 should_prefetch ? kTrue : kFalse); |
1755 | 1841 |
1842 if (!deletion_url.empty()) { | |
1843 match.RecordAdditionalInfo(kDeletionUrlKey, deletion_url); | |
1844 match.deletable = true; | |
1845 } | |
1846 | |
1756 // Metadata is needed only for prefetching queries. | 1847 // Metadata is needed only for prefetching queries. |
1757 if (should_prefetch) | 1848 if (should_prefetch) |
1758 match.RecordAdditionalInfo(kSuggestMetadataKey, metadata); | 1849 match.RecordAdditionalInfo(kSuggestMetadataKey, metadata); |
1759 | 1850 |
1760 // Try to add |match| to |map|. If a match for |query_string| is already in | 1851 // Try to add |match| to |map|. If a match for |query_string| is already in |
1761 // |map|, replace it if |match| is more relevant. | 1852 // |map|, replace it if |match| is more relevant. |
1762 // NOTE: Keep this ToLower() call in sync with url_database.cc. | 1853 // NOTE: Keep this ToLower() call in sync with url_database.cc. |
1763 MatchKey match_key( | 1854 MatchKey match_key( |
1764 std::make_pair(base::i18n::ToLower(query_string), | 1855 std::make_pair(base::i18n::ToLower(query_string), |
1765 match.search_terms_args->suggest_query_params)); | 1856 match.search_terms_args->suggest_query_params)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1907 it->set_relevance(max_query_relevance); | 1998 it->set_relevance(max_query_relevance); |
1908 it->set_relevance_from_server(relevance_from_server); | 1999 it->set_relevance_from_server(relevance_from_server); |
1909 } | 2000 } |
1910 } | 2001 } |
1911 | 2002 |
1912 void SearchProvider::UpdateDone() { | 2003 void SearchProvider::UpdateDone() { |
1913 // We're done when the timer isn't running, there are no suggest queries | 2004 // We're done when the timer isn't running, there are no suggest queries |
1914 // pending, and we're not waiting on Instant. | 2005 // pending, and we're not waiting on Instant. |
1915 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 2006 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
1916 } | 2007 } |
OLD | NEW |