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

Side by Side Diff: components/omnibox/browser/search_suggestion_parser.cc

Issue 2755503002: Add a new entry to omnibox_event.proto to log specific type of contextual suggestions (Closed)
Patch Set: Created 3 years, 9 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
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 "components/omnibox/browser/search_suggestion_parser.h" 5 #include "components/omnibox/browser/search_suggestion_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/i18n/icu_string_conversions.h" 11 #include "base/i18n/icu_string_conversions.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_string_value_serializer.h" 13 #include "base/json/json_string_value_serializer.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "components/omnibox/browser/autocomplete_i18n.h" 21 #include "components/omnibox/browser/autocomplete_i18n.h"
22 #include "components/omnibox/browser/autocomplete_input.h" 22 #include "components/omnibox/browser/autocomplete_input.h"
23 #include "components/omnibox/browser/omnibox_field_trial.h"
23 #include "components/omnibox/browser/url_prefix.h" 24 #include "components/omnibox/browser/url_prefix.h"
24 #include "components/url_formatter/url_fixer.h" 25 #include "components/url_formatter/url_fixer.h"
25 #include "components/url_formatter/url_formatter.h" 26 #include "components/url_formatter/url_formatter.h"
26 #include "net/http/http_response_headers.h" 27 #include "net/http/http_response_headers.h"
27 #include "net/url_request/url_fetcher.h" 28 #include "net/url_request/url_fetcher.h"
28 #include "url/url_constants.h" 29 #include "url/url_constants.h"
29 30
30 namespace { 31 namespace {
31 32
32 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { 33 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 223
223 SearchSuggestionParser::NavigationResult::NavigationResult( 224 SearchSuggestionParser::NavigationResult::NavigationResult(
224 const AutocompleteSchemeClassifier& scheme_classifier, 225 const AutocompleteSchemeClassifier& scheme_classifier,
225 const GURL& url, 226 const GURL& url,
226 AutocompleteMatchType::Type type, 227 AutocompleteMatchType::Type type,
227 const base::string16& description, 228 const base::string16& description,
228 const std::string& deletion_url, 229 const std::string& deletion_url,
229 bool from_keyword_provider, 230 bool from_keyword_provider,
230 int relevance, 231 int relevance,
231 bool relevance_from_server, 232 bool relevance_from_server,
232 const base::string16& input_text) 233 const base::string16& input_text,
234 const std::string& zero_suggest_specific_type)
233 : Result(from_keyword_provider, 235 : Result(from_keyword_provider,
234 relevance, 236 relevance,
235 relevance_from_server, 237 relevance_from_server,
236 type, 238 type,
237 deletion_url), 239 deletion_url),
238 url_(url), 240 url_(url),
239 formatted_url_(AutocompleteInput::FormattedStringWithEquivalentMeaning( 241 formatted_url_(AutocompleteInput::FormattedStringWithEquivalentMeaning(
240 url, 242 url,
241 url_formatter::FormatUrl(url, 243 url_formatter::FormatUrl(url,
242 url_formatter::kFormatUrlOmitAll & 244 url_formatter::kFormatUrlOmitAll &
243 ~url_formatter::kFormatUrlOmitHTTP, 245 ~url_formatter::kFormatUrlOmitHTTP,
244 net::UnescapeRule::SPACES, 246 net::UnescapeRule::SPACES,
245 nullptr, 247 nullptr,
246 nullptr, 248 nullptr,
247 nullptr), 249 nullptr),
248 scheme_classifier)), 250 scheme_classifier)),
249 description_(description) { 251 description_(description),
252 zero_suggest_specific_type_(zero_suggest_specific_type) {
250 DCHECK(url_.is_valid()); 253 DCHECK(url_.is_valid());
251 CalculateAndClassifyMatchContents(true, input_text); 254 CalculateAndClassifyMatchContents(true, input_text);
252 } 255 }
253 256
257 SearchSuggestionParser::NavigationResult::NavigationResult(
258 const NavigationResult& nav) = default;
254 SearchSuggestionParser::NavigationResult::~NavigationResult() {} 259 SearchSuggestionParser::NavigationResult::~NavigationResult() {}
255 260
256 void 261 void
257 SearchSuggestionParser::NavigationResult::CalculateAndClassifyMatchContents( 262 SearchSuggestionParser::NavigationResult::CalculateAndClassifyMatchContents(
258 const bool allow_bolding_nothing, 263 const bool allow_bolding_nothing,
259 const base::string16& input_text) { 264 const base::string16& input_text) {
260 if (input_text.empty()) { 265 if (input_text.empty()) {
261 // In case of zero-suggest results, do not highlight matches. 266 // In case of zero-suggest results, do not highlight matches.
262 match_contents_class_.push_back( 267 match_contents_class_.push_back(
263 ACMatchClassification(0, ACMatchClassification::NONE)); 268 ACMatchClassification(0, ACMatchClassification::NONE));
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 if (extras->GetList("google:suggestdetail", &suggestion_details) && 445 if (extras->GetList("google:suggestdetail", &suggestion_details) &&
441 suggestion_details->GetSize() != results_list->GetSize()) 446 suggestion_details->GetSize() != results_list->GetSize())
442 suggestion_details = NULL; 447 suggestion_details = NULL;
443 448
444 // Store the metadata that came with the response in case we need to pass it 449 // Store the metadata that came with the response in case we need to pass it
445 // along with the prefetch query to Instant. 450 // along with the prefetch query to Instant.
446 JSONStringValueSerializer json_serializer(&results->metadata); 451 JSONStringValueSerializer json_serializer(&results->metadata);
447 json_serializer.Serialize(*extras); 452 json_serializer.Serialize(*extras);
448 } 453 }
449 454
455 // Get zero suggest subtypes.
456 const base::ListValue* zero_suggest_subtypes = NULL;
Mark P 2017/03/14 20:17:50 If we're getting stuff from the server, it should
gcomanici 2017/03/14 20:42:55 I agree. Although the server side puts this values
457 if (root_list->GetList(5, &zero_suggest_subtypes) &&
458 zero_suggest_subtypes->GetSize() != results_list->GetSize()) {
459 zero_suggest_subtypes = NULL;
460 }
461
450 // Clear the previous results now that new results are available. 462 // Clear the previous results now that new results are available.
451 results->suggest_results.clear(); 463 results->suggest_results.clear();
452 results->navigation_results.clear(); 464 results->navigation_results.clear();
453 results->answers_image_urls.clear(); 465 results->answers_image_urls.clear();
454 466
455 base::string16 suggestion; 467 base::string16 suggestion;
456 std::string type; 468 std::string type;
457 int relevance = default_result_relevance; 469 int relevance = default_result_relevance;
458 const base::string16& trimmed_input = 470 const base::string16& trimmed_input =
459 base::CollapseWhitespace(input.text(), false); 471 base::CollapseWhitespace(input.text(), false);
(...skipping 19 matching lines...) Expand all
479 491
480 if ((match_type == AutocompleteMatchType::NAVSUGGEST) || 492 if ((match_type == AutocompleteMatchType::NAVSUGGEST) ||
481 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) { 493 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) {
482 // Do not blindly trust the URL coming from the server to be valid. 494 // Do not blindly trust the URL coming from the server to be valid.
483 GURL url(url_formatter::FixupURL(base::UTF16ToUTF8(suggestion), 495 GURL url(url_formatter::FixupURL(base::UTF16ToUTF8(suggestion),
484 std::string())); 496 std::string()));
485 if (url.is_valid()) { 497 if (url.is_valid()) {
486 base::string16 title; 498 base::string16 title;
487 if (descriptions != NULL) 499 if (descriptions != NULL)
488 descriptions->GetString(index, &title); 500 descriptions->GetString(index, &title);
501 // add zero suggest subtype
502 std::string zero_suggest_specific_type;
503 if (zero_suggest_subtypes) {
504 zero_suggest_subtypes->GetString(index, &zero_suggest_specific_type);
Mark P 2017/03/14 20:17:49 I'm curious: why do you have the server send down
gcomanici 2017/03/14 20:42:55 The short answer is that it makes it easy to use t
Mark P 2017/03/14 21:04:09 The elephant in the room here is that regardless o
gcomanici 2017/03/15 01:35:56 I would go with the latter proposal (i.e. use ints
505 }
489 results->navigation_results.push_back(NavigationResult( 506 results->navigation_results.push_back(NavigationResult(
490 scheme_classifier, url, match_type, title, deletion_url, 507 scheme_classifier, url, match_type, title, deletion_url,
491 is_keyword_result, relevance, relevances != NULL, input.text())); 508 is_keyword_result, relevance, relevances != NULL, input.text(),
509 zero_suggest_specific_type));
492 } 510 }
493 } else { 511 } else {
494 // TODO(dschuyler) If the "= " is no longer sent from the back-end 512 // TODO(dschuyler) If the "= " is no longer sent from the back-end
495 // then this may be removed. 513 // then this may be removed.
496 if ((match_type == AutocompleteMatchType::CALCULATOR) && 514 if ((match_type == AutocompleteMatchType::CALCULATOR) &&
497 !suggestion.compare(0, 2, base::UTF8ToUTF16("= "))) 515 !suggestion.compare(0, 2, base::UTF8ToUTF16("= ")))
498 suggestion.erase(0, 2); 516 suggestion.erase(0, 2);
499 517
500 base::string16 match_contents = suggestion; 518 base::string16 match_contents = suggestion;
501 base::string16 match_contents_prefix; 519 base::string16 match_contents_prefix;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 base::CollapseWhitespace(match_contents, false), 567 base::CollapseWhitespace(match_contents, false),
550 match_contents_prefix, annotation, answer_contents, answer_type_str, 568 match_contents_prefix, annotation, answer_contents, answer_type_str,
551 std::move(answer), suggest_query_params, deletion_url, 569 std::move(answer), suggest_query_params, deletion_url,
552 is_keyword_result, relevance, relevances != NULL, should_prefetch, 570 is_keyword_result, relevance, relevances != NULL, should_prefetch,
553 trimmed_input)); 571 trimmed_input));
554 } 572 }
555 } 573 }
556 results->relevances_from_server = relevances != NULL; 574 results->relevances_from_server = relevances != NULL;
557 return true; 575 return true;
558 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698