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