| 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_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 14 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 15 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 15 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 16 #include "chrome/browser/search/search.h" | 16 #include "chrome/browser/search/search.h" |
| 17 #include "components/autocomplete/autocomplete_input.h" | 17 #include "components/autocomplete/autocomplete_input.h" |
| 18 #include "components/metrics/proto/omnibox_event.pb.h" | 18 #include "components/metrics/proto/omnibox_event.pb.h" |
| 19 #include "components/metrics/proto/omnibox_input_type.pb.h" | 19 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 20 #include "content/public/common/url_constants.h" |
| 21 #include "url/url_constants.h" |
| 20 | 22 |
| 21 using metrics::OmniboxEventProto; | 23 using metrics::OmniboxEventProto; |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 // This class implements a special version of AutocompleteMatch::MoreRelevant | 27 // This class implements a special version of AutocompleteMatch::MoreRelevant |
| 26 // that allows matches of particular types to be demoted in AutocompleteResult. | 28 // that allows matches of particular types to be demoted in AutocompleteResult. |
| 27 class CompareWithDemoteByType { | 29 class CompareWithDemoteByType { |
| 28 public: | 30 public: |
| 29 CompareWithDemoteByType( | 31 CompareWithDemoteByType( |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // sure the type of destination is what the user would expect given the | 258 // sure the type of destination is what the user would expect given the |
| 257 // input. | 259 // input. |
| 258 if (default_match_->destination_url.is_valid()) { | 260 if (default_match_->destination_url.is_valid()) { |
| 259 // We shouldn't get query matches for URL inputs, or non-query matches | 261 // We shouldn't get query matches for URL inputs, or non-query matches |
| 260 // for query inputs. | 262 // for query inputs. |
| 261 if (AutocompleteMatch::IsSearchType(default_match_->type)) { | 263 if (AutocompleteMatch::IsSearchType(default_match_->type)) { |
| 262 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info; | 264 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info; |
| 263 } else { | 265 } else { |
| 264 DCHECK_NE(metrics::OmniboxInputType::FORCED_QUERY, input.type()) | 266 DCHECK_NE(metrics::OmniboxInputType::FORCED_QUERY, input.type()) |
| 265 << debug_info; | 267 << debug_info; |
| 268 // If the user explicitly typed a scheme, the default match should |
| 269 // have the same scheme. |
| 270 if ((input.type() == metrics::OmniboxInputType::URL) && |
| 271 input.parts().scheme.is_nonempty()) { |
| 272 const std::string& in_scheme = base::UTF16ToUTF8(input.scheme()); |
| 273 const std::string& dest_scheme = |
| 274 default_match_->destination_url.scheme(); |
| 275 DCHECK((in_scheme == dest_scheme) || |
| 276 ((in_scheme == url::kAboutScheme) && |
| 277 (dest_scheme == content::kChromeUIScheme))) << debug_info; |
| 278 } |
| 266 } | 279 } |
| 267 } | 280 } |
| 268 } | 281 } |
| 269 | 282 |
| 270 // Set the alternate nav URL. | 283 // Set the alternate nav URL. |
| 271 alternate_nav_url_ = (default_match_ == matches_.end()) ? | 284 alternate_nav_url_ = (default_match_ == matches_.end()) ? |
| 272 GURL() : ComputeAlternateNavUrl(input, *default_match_); | 285 GURL() : ComputeAlternateNavUrl(input, *default_match_); |
| 273 } | 286 } |
| 274 | 287 |
| 275 bool AutocompleteResult::HasCopiedMatches() const { | 288 bool AutocompleteResult::HasCopiedMatches() const { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 i != old_matches.rend() && delta > 0; ++i) { | 459 i != old_matches.rend() && delta > 0; ++i) { |
| 447 if (!HasMatchByDestination(*i, new_matches)) { | 460 if (!HasMatchByDestination(*i, new_matches)) { |
| 448 AutocompleteMatch match = *i; | 461 AutocompleteMatch match = *i; |
| 449 match.relevance = std::min(max_relevance, match.relevance); | 462 match.relevance = std::min(max_relevance, match.relevance); |
| 450 match.from_previous = true; | 463 match.from_previous = true; |
| 451 matches_.push_back(match); | 464 matches_.push_back(match); |
| 452 delta--; | 465 delta--; |
| 453 } | 466 } |
| 454 } | 467 } |
| 455 } | 468 } |
| OLD | NEW |