OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete_input.h" | 13 #include "chrome/browser/autocomplete/autocomplete_input.h" |
14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
15 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 15 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
16 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 16 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
17 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
18 #include "chrome/common/autocomplete_match_type.h" | 18 #include "chrome/common/autocomplete_match_type.h" |
19 #include "components/metrics/proto/omnibox_input_type.pb.h" | |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 // This class implements a special version of AutocompleteMatch::MoreRelevant | 22 // This class implements a special version of AutocompleteMatch::MoreRelevant |
24 // that allows matches of particular types to be demoted in AutocompleteResult. | 23 // that allows matches of particular types to be demoted in AutocompleteResult. |
25 class CompareWithDemoteByType { | 24 class CompareWithDemoteByType { |
26 public: | 25 public: |
27 CompareWithDemoteByType( | 26 CompareWithDemoteByType( |
28 AutocompleteInput::PageClassification current_page_classification); | 27 AutocompleteInput::PageClassification current_page_classification); |
29 | 28 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 base::ASCIIToUTF16(", input=") + | 247 base::ASCIIToUTF16(", input=") + |
249 input.text(); | 248 input.text(); |
250 DCHECK(default_match_->allowed_to_be_default_match) << debug_info; | 249 DCHECK(default_match_->allowed_to_be_default_match) << debug_info; |
251 // If the default match is valid (i.e., not a prompt/placeholder), make | 250 // If the default match is valid (i.e., not a prompt/placeholder), make |
252 // sure the type of destination is what the user would expect given the | 251 // sure the type of destination is what the user would expect given the |
253 // input. | 252 // input. |
254 if (default_match_->destination_url.is_valid()) { | 253 if (default_match_->destination_url.is_valid()) { |
255 // We shouldn't get query matches for URL inputs, or non-query matches | 254 // We shouldn't get query matches for URL inputs, or non-query matches |
256 // for query inputs. | 255 // for query inputs. |
257 if (AutocompleteMatch::IsSearchType(default_match_->type)) { | 256 if (AutocompleteMatch::IsSearchType(default_match_->type)) { |
258 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info; | 257 DCHECK_NE(AutocompleteInput::URL, input.type()) << debug_info; |
259 } else { | 258 } else { |
260 DCHECK_NE(metrics::OmniboxInputType::FORCED_QUERY, input.type()) | 259 DCHECK_NE(AutocompleteInput::FORCED_QUERY, input.type()) << debug_info; |
261 << debug_info; | |
262 } | 260 } |
263 } | 261 } |
264 } | 262 } |
265 | 263 |
266 // Set the alternate nav URL. | 264 // Set the alternate nav URL. |
267 alternate_nav_url_ = (default_match_ == matches_.end()) ? | 265 alternate_nav_url_ = (default_match_ == matches_.end()) ? |
268 GURL() : ComputeAlternateNavUrl(input, *default_match_); | 266 GURL() : ComputeAlternateNavUrl(input, *default_match_); |
269 } | 267 } |
270 | 268 |
271 bool AutocompleteResult::HasCopiedMatches() const { | 269 bool AutocompleteResult::HasCopiedMatches() const { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 void AutocompleteResult::Validate() const { | 347 void AutocompleteResult::Validate() const { |
350 for (const_iterator i(begin()); i != end(); ++i) | 348 for (const_iterator i(begin()); i != end(); ++i) |
351 i->Validate(); | 349 i->Validate(); |
352 } | 350 } |
353 #endif | 351 #endif |
354 | 352 |
355 // static | 353 // static |
356 GURL AutocompleteResult::ComputeAlternateNavUrl( | 354 GURL AutocompleteResult::ComputeAlternateNavUrl( |
357 const AutocompleteInput& input, | 355 const AutocompleteInput& input, |
358 const AutocompleteMatch& match) { | 356 const AutocompleteMatch& match) { |
359 return ((input.type() == metrics::OmniboxInputType::UNKNOWN) && | 357 return ((input.type() == AutocompleteInput::UNKNOWN) && |
360 (AutocompleteMatch::IsSearchType(match.type)) && | 358 (AutocompleteMatch::IsSearchType(match.type)) && |
361 (match.transition != content::PAGE_TRANSITION_KEYWORD) && | 359 (match.transition != content::PAGE_TRANSITION_KEYWORD) && |
362 (input.canonicalized_url() != match.destination_url)) ? | 360 (input.canonicalized_url() != match.destination_url)) ? |
363 input.canonicalized_url() : GURL(); | 361 input.canonicalized_url() : GURL(); |
364 } | 362 } |
365 | 363 |
366 void AutocompleteResult::DedupMatchesByDestination( | 364 void AutocompleteResult::DedupMatchesByDestination( |
367 AutocompleteInput::PageClassification page_classification, | 365 AutocompleteInput::PageClassification page_classification, |
368 bool set_duplicate_matches, | 366 bool set_duplicate_matches, |
369 ACMatches* matches) { | 367 ACMatches* matches) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 i != old_matches.rend() && delta > 0; ++i) { | 457 i != old_matches.rend() && delta > 0; ++i) { |
460 if (!HasMatchByDestination(*i, new_matches)) { | 458 if (!HasMatchByDestination(*i, new_matches)) { |
461 AutocompleteMatch match = *i; | 459 AutocompleteMatch match = *i; |
462 match.relevance = std::min(max_relevance, match.relevance); | 460 match.relevance = std::min(max_relevance, match.relevance); |
463 match.from_previous = true; | 461 match.from_previous = true; |
464 AddMatch(page_classification, match); | 462 AddMatch(page_classification, match); |
465 delta--; | 463 delta--; |
466 } | 464 } |
467 } | 465 } |
468 } | 466 } |
OLD | NEW |