Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/autocomplete/base_search_provider.cc

Issue 285343004: [AiS] Extract Answers, store on AutocompleteMatch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/json/json_writer.h"
10 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
15 #include "chrome/browser/autocomplete/url_prefix.h" 16 #include "chrome/browser/autocomplete/url_prefix.h"
16 #include "chrome/browser/history/history_service.h" 17 #include "chrome/browser/history/history_service.h"
17 #include "chrome/browser/history/history_service_factory.h" 18 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/omnibox/omnibox_field_trial.h" 19 #include "chrome/browser/omnibox/omnibox_field_trial.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 136
136 // static 137 // static
137 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( 138 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
138 const base::string16& suggestion, 139 const base::string16& suggestion,
139 AutocompleteMatchType::Type type, 140 AutocompleteMatchType::Type type,
140 bool from_keyword_provider, 141 bool from_keyword_provider,
141 const TemplateURL* template_url) { 142 const TemplateURL* template_url) {
142 return CreateSearchSuggestion( 143 return CreateSearchSuggestion(
143 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult( 144 NULL, AutocompleteInput(), BaseSearchProvider::SuggestResult(
144 suggestion, type, suggestion, base::string16(), base::string16(), 145 suggestion, type, suggestion, base::string16(), base::string16(),
145 std::string(), std::string(), from_keyword_provider, 0, false, false, 146 base::string16(), base::string16(), std::string(), std::string(),
146 base::string16()), 147 from_keyword_provider, 0, false, false, base::string16()),
147 template_url, 0, 0, false, false); 148 template_url, 0, 0, false, false);
148 } 149 }
149 150
150 void BaseSearchProvider::Stop(bool clear_cached_results) { 151 void BaseSearchProvider::Stop(bool clear_cached_results) {
151 StopSuggest(); 152 StopSuggest();
152 done_ = true; 153 done_ = true;
153 154
154 if (clear_cached_results) 155 if (clear_cached_results)
155 ClearAllResults(); 156 ClearAllResults();
156 } 157 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 BaseSearchProvider::Result::~Result() {} 226 BaseSearchProvider::Result::~Result() {}
226 227
227 // BaseSearchProvider::SuggestResult ------------------------------------------- 228 // BaseSearchProvider::SuggestResult -------------------------------------------
228 229
229 BaseSearchProvider::SuggestResult::SuggestResult( 230 BaseSearchProvider::SuggestResult::SuggestResult(
230 const base::string16& suggestion, 231 const base::string16& suggestion,
231 AutocompleteMatchType::Type type, 232 AutocompleteMatchType::Type type,
232 const base::string16& match_contents, 233 const base::string16& match_contents,
233 const base::string16& match_contents_prefix, 234 const base::string16& match_contents_prefix,
234 const base::string16& annotation, 235 const base::string16& annotation,
236 const base::string16& answer_contents,
237 const base::string16& answer_type,
235 const std::string& suggest_query_params, 238 const std::string& suggest_query_params,
236 const std::string& deletion_url, 239 const std::string& deletion_url,
237 bool from_keyword_provider, 240 bool from_keyword_provider,
238 int relevance, 241 int relevance,
239 bool relevance_from_server, 242 bool relevance_from_server,
240 bool should_prefetch, 243 bool should_prefetch,
241 const base::string16& input_text) 244 const base::string16& input_text)
242 : Result(from_keyword_provider, 245 : Result(from_keyword_provider,
243 relevance, 246 relevance,
244 relevance_from_server, 247 relevance_from_server,
245 type, 248 type,
246 deletion_url), 249 deletion_url),
247 suggestion_(suggestion), 250 suggestion_(suggestion),
248 match_contents_prefix_(match_contents_prefix), 251 match_contents_prefix_(match_contents_prefix),
249 annotation_(annotation), 252 annotation_(annotation),
250 suggest_query_params_(suggest_query_params), 253 suggest_query_params_(suggest_query_params),
254 answer_contents_(answer_contents),
255 answer_type_(answer_type),
251 should_prefetch_(should_prefetch) { 256 should_prefetch_(should_prefetch) {
252 match_contents_ = match_contents; 257 match_contents_ = match_contents;
253 DCHECK(!match_contents_.empty()); 258 DCHECK(!match_contents_.empty());
254 ClassifyMatchContents(true, input_text); 259 ClassifyMatchContents(true, input_text);
255 } 260 }
256 261
257 BaseSearchProvider::SuggestResult::~SuggestResult() {} 262 BaseSearchProvider::SuggestResult::~SuggestResult() {}
258 263
259 void BaseSearchProvider::SuggestResult::ClassifyMatchContents( 264 void BaseSearchProvider::SuggestResult::ClassifyMatchContents(
260 const bool allow_bolding_all, 265 const bool allow_bolding_all,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 bool append_extra_query_params, 486 bool append_extra_query_params,
482 bool from_app_list) { 487 bool from_app_list) {
483 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, 488 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false,
484 suggestion.type()); 489 suggestion.type());
485 490
486 if (!template_url) 491 if (!template_url)
487 return match; 492 return match;
488 match.keyword = template_url->keyword(); 493 match.keyword = template_url->keyword();
489 match.contents = suggestion.match_contents(); 494 match.contents = suggestion.match_contents();
490 match.contents_class = suggestion.match_contents_class(); 495 match.contents_class = suggestion.match_contents_class();
496 match.answer_contents = suggestion.answer_contents();
497 match.answer_type = suggestion.answer_type();
491 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { 498 if (suggestion.type() == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) {
492 match.RecordAdditionalInfo( 499 match.RecordAdditionalInfo(
493 kACMatchPropertyInputText, base::UTF16ToUTF8(input.text())); 500 kACMatchPropertyInputText, base::UTF16ToUTF8(input.text()));
494 match.RecordAdditionalInfo( 501 match.RecordAdditionalInfo(
495 kACMatchPropertyContentsPrefix, 502 kACMatchPropertyContentsPrefix,
496 base::UTF16ToUTF8(suggestion.match_contents_prefix())); 503 base::UTF16ToUTF8(suggestion.match_contents_prefix()));
497 match.RecordAdditionalInfo( 504 match.RecordAdditionalInfo(
498 kACMatchPropertyContentsStartIndex, 505 kACMatchPropertyContentsStartIndex,
499 static_cast<int>( 506 static_cast<int>(
500 suggestion.suggestion().length() - match.contents.length())); 507 suggestion.suggestion().length() - match.contents.length()));
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 if (descriptions != NULL) 888 if (descriptions != NULL)
882 descriptions->GetString(index, &title); 889 descriptions->GetString(index, &title);
883 results->navigation_results.push_back(NavigationResult( 890 results->navigation_results.push_back(NavigationResult(
884 *this, url, match_type, title, deletion_url, is_keyword_result, 891 *this, url, match_type, title, deletion_url, is_keyword_result,
885 relevance, relevances != NULL, input.text(), languages)); 892 relevance, relevances != NULL, input.text(), languages));
886 } 893 }
887 } else { 894 } else {
888 base::string16 match_contents = suggestion; 895 base::string16 match_contents = suggestion;
889 base::string16 match_contents_prefix; 896 base::string16 match_contents_prefix;
890 base::string16 annotation; 897 base::string16 annotation;
898 base::string16 answer_contents;
899 base::string16 answer_type;
891 std::string suggest_query_params; 900 std::string suggest_query_params;
892 901
893 if (suggestion_details) { 902 if (suggestion_details) {
894 suggestion_details->GetDictionary(index, &suggestion_detail); 903 suggestion_details->GetDictionary(index, &suggestion_detail);
895 if (suggestion_detail) { 904 if (suggestion_detail) {
896 suggestion_detail->GetString("t", &match_contents); 905 suggestion_detail->GetString("t", &match_contents);
897 suggestion_detail->GetString("mp", &match_contents_prefix); 906 suggestion_detail->GetString("mp", &match_contents_prefix);
898 // Error correction for bad data from server. 907 // Error correction for bad data from server.
899 if (match_contents.empty()) 908 if (match_contents.empty())
900 match_contents = suggestion; 909 match_contents = suggestion;
901 suggestion_detail->GetString("a", &annotation); 910 suggestion_detail->GetString("a", &annotation);
902 suggestion_detail->GetString("q", &suggest_query_params); 911 suggestion_detail->GetString("q", &suggest_query_params);
912
913 // Extract Answers, if provided.
914 const base::DictionaryValue* answer_json = NULL;
915 if (suggestion_detail->GetDictionary("ansa", &answer_json)) {
916 std::string contents;
917 base::JSONWriter::Write(answer_json, &contents);
918 answer_contents = base::UTF8ToUTF16(contents);
919 suggestion_detail->GetString("ansb", &answer_type);
920 }
903 } 921 }
904 } 922 }
905 923
906 bool should_prefetch = static_cast<int>(index) == prefetch_index; 924 bool should_prefetch = static_cast<int>(index) == prefetch_index;
907 // TODO(kochi): Improve calculator suggestion presentation. 925 // TODO(kochi): Improve calculator suggestion presentation.
908 results->suggest_results.push_back(SuggestResult( 926 results->suggest_results.push_back(SuggestResult(
909 base::CollapseWhitespace(suggestion, false), match_type, 927 base::CollapseWhitespace(suggestion, false), match_type,
910 base::CollapseWhitespace(match_contents, false), 928 base::CollapseWhitespace(match_contents, false),
911 match_contents_prefix, annotation, suggest_query_params, 929 match_contents_prefix, annotation, answer_contents, answer_type,
912 deletion_url, is_keyword_result, relevance, relevances != NULL, 930 suggest_query_params, deletion_url, is_keyword_result, relevance,
913 should_prefetch, trimmed_input)); 931 relevances != NULL, should_prefetch, trimmed_input));
914 } 932 }
915 } 933 }
916 SortResults(is_keyword_result, relevances, results); 934 SortResults(is_keyword_result, relevances, results);
917 return true; 935 return true;
918 } 936 }
919 937
920 void BaseSearchProvider::SortResults(bool is_keyword, 938 void BaseSearchProvider::SortResults(bool is_keyword,
921 const base::ListValue* relevances, 939 const base::ListValue* relevances,
922 Results* results) { 940 Results* results) {
923 } 941 }
(...skipping 24 matching lines...) Expand all
948 } 966 }
949 967
950 void BaseSearchProvider::OnDeletionComplete( 968 void BaseSearchProvider::OnDeletionComplete(
951 bool success, SuggestionDeletionHandler* handler) { 969 bool success, SuggestionDeletionHandler* handler) {
952 RecordDeletionResult(success); 970 RecordDeletionResult(success);
953 SuggestionDeletionHandlers::iterator it = std::find( 971 SuggestionDeletionHandlers::iterator it = std::find(
954 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 972 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
955 DCHECK(it != deletion_handlers_.end()); 973 DCHECK(it != deletion_handlers_.end());
956 deletion_handlers_.erase(it); 974 deletion_handlers_.erase(it);
957 } 975 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/base_search_provider.h ('k') | chrome/browser/autocomplete/search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698