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" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 399 |
400 matches_ = rhs.matches_; | 400 matches_ = rhs.matches_; |
401 // Careful! You can't just copy iterators from another container, you have to | 401 // Careful! You can't just copy iterators from another container, you have to |
402 // reconstruct them. | 402 // reconstruct them. |
403 default_match_ = (rhs.default_match_ == rhs.end()) ? | 403 default_match_ = (rhs.default_match_ == rhs.end()) ? |
404 end() : (begin() + (rhs.default_match_ - rhs.begin())); | 404 end() : (begin() + (rhs.default_match_ - rhs.begin())); |
405 | 405 |
406 alternate_nav_url_ = rhs.alternate_nav_url_; | 406 alternate_nav_url_ = rhs.alternate_nav_url_; |
407 } | 407 } |
408 | 408 |
409 void AutocompleteResult::AddMatch( | |
410 AutocompleteInput::PageClassification page_classification, | |
411 const AutocompleteMatch& match) { | |
412 DCHECK(default_match_ != end()); | |
413 DCHECK_EQ(AutocompleteMatch::SanitizeString(match.contents), match.contents); | |
414 DCHECK_EQ(AutocompleteMatch::SanitizeString(match.description), | |
415 match.description); | |
416 CompareWithDemoteByType comparing_object(page_classification); | |
417 ACMatches::iterator insertion_point = | |
418 std::upper_bound(begin(), end(), match, comparing_object); | |
419 matches_difference_type default_offset = default_match_ - begin(); | |
420 if ((insertion_point - begin()) <= default_offset) | |
421 ++default_offset; | |
422 matches_.insert(insertion_point, match); | |
423 default_match_ = begin() + default_offset; | |
424 } | |
425 | |
426 void AutocompleteResult::BuildProviderToMatches( | 409 void AutocompleteResult::BuildProviderToMatches( |
427 ProviderToMatches* provider_to_matches) const { | 410 ProviderToMatches* provider_to_matches) const { |
428 for (ACMatches::const_iterator i(begin()); i != end(); ++i) | 411 for (ACMatches::const_iterator i(begin()); i != end(); ++i) |
429 (*provider_to_matches)[i->provider].push_back(*i); | 412 (*provider_to_matches)[i->provider].push_back(*i); |
430 } | 413 } |
431 | 414 |
432 // static | 415 // static |
433 bool AutocompleteResult::HasMatchByDestination(const AutocompleteMatch& match, | 416 bool AutocompleteResult::HasMatchByDestination(const AutocompleteMatch& match, |
434 const ACMatches& matches) { | 417 const ACMatches& matches) { |
435 for (ACMatches::const_iterator i(matches.begin()); i != matches.end(); ++i) { | 418 for (ACMatches::const_iterator i(matches.begin()); i != matches.end(); ++i) { |
(...skipping 18 matching lines...) Expand all Loading... | |
454 // first. This means that within each provider's "group" of matches, any | 437 // first. This means that within each provider's "group" of matches, any |
455 // synchronous matches (which tend to have the highest scores) will | 438 // synchronous matches (which tend to have the highest scores) will |
456 // "overwrite" the initial matches from that provider's previous results, | 439 // "overwrite" the initial matches from that provider's previous results, |
457 // minimally disturbing the rest of the matches. | 440 // minimally disturbing the rest of the matches. |
458 for (ACMatches::const_reverse_iterator i(old_matches.rbegin()); | 441 for (ACMatches::const_reverse_iterator i(old_matches.rbegin()); |
459 i != old_matches.rend() && delta > 0; ++i) { | 442 i != old_matches.rend() && delta > 0; ++i) { |
460 if (!HasMatchByDestination(*i, new_matches)) { | 443 if (!HasMatchByDestination(*i, new_matches)) { |
461 AutocompleteMatch match = *i; | 444 AutocompleteMatch match = *i; |
462 match.relevance = std::min(max_relevance, match.relevance); | 445 match.relevance = std::min(max_relevance, match.relevance); |
463 match.from_previous = true; | 446 match.from_previous = true; |
464 AddMatch(page_classification, match); | 447 DCHECK_EQ(AutocompleteMatch::SanitizeString(match.contents), |
448 match.contents); | |
449 DCHECK_EQ(AutocompleteMatch::SanitizeString(match.description), | |
450 match.description); | |
Peter Kasting
2014/06/11 20:06:43
I don't think these two DCHECKs are necessary. We
Mark P
2014/06/11 21:40:44
Done.
| |
451 matches_.push_back(match); | |
465 delta--; | 452 delta--; |
466 } | 453 } |
467 } | 454 } |
468 } | 455 } |
OLD | NEW |