| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" | 
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 119 } | 119 } | 
| 120 | 120 | 
| 121 // Used by both autocomplete passes, and therefore called on multiple different | 121 // Used by both autocomplete passes, and therefore called on multiple different | 
| 122 // threads (though not simultaneously). | 122 // threads (though not simultaneously). | 
| 123 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, | 123 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, | 
| 124                                         history::URLDatabase* db, | 124                                         history::URLDatabase* db, | 
| 125                                         HistoryURLProviderParams* params) { | 125                                         HistoryURLProviderParams* params) { | 
| 126   // Create a What You Typed match, which we'll need below. | 126   // Create a What You Typed match, which we'll need below. | 
| 127   bool have_what_you_typed_match = | 127   bool have_what_you_typed_match = | 
| 128       params->input.canonicalized_url().is_valid() && | 128       params->input.canonicalized_url().is_valid() && | 
| 129       (params->input.type() != AutocompleteInput::UNKNOWN); | 129       (params->input.type() != AutocompleteInput::UNKNOWN) && | 
|  | 130       (params->input.type() != AutocompleteInput::QUERY); | 
| 130   AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input, | 131   AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input, | 
| 131                                                            params->trim_http)); | 132                                                            params->trim_http)); | 
| 132 | 133 | 
| 133   // Get the matching URLs from the DB | 134   // Get the matching URLs from the DB | 
| 134   typedef std::vector<history::URLRow> URLRowVector; | 135   typedef std::vector<history::URLRow> URLRowVector; | 
| 135   URLRowVector url_matches; | 136   URLRowVector url_matches; | 
| 136   HistoryMatches history_matches; | 137   HistoryMatches history_matches; | 
| 137   for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); | 138   for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); | 
| 138        ++i) { | 139        ++i) { | 
| 139     if (params->cancel) | 140     if (params->cancel) | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 165   // Try to promote a match as an exact/inline autocomplete match.  This also | 166   // Try to promote a match as an exact/inline autocomplete match.  This also | 
| 166   // moves it to the front of |history_matches|, so skip over it when | 167   // moves it to the front of |history_matches|, so skip over it when | 
| 167   // converting the rest of the matches. | 168   // converting the rest of the matches. | 
| 168   size_t first_match = 1; | 169   size_t first_match = 1; | 
| 169   size_t exact_suggestion = 0; | 170   size_t exact_suggestion = 0; | 
| 170   // Checking |is_history_what_you_typed_match| tells us whether | 171   // Checking |is_history_what_you_typed_match| tells us whether | 
| 171   // SuggestExactInput() succeeded in constructing a valid match. | 172   // SuggestExactInput() succeeded in constructing a valid match. | 
| 172   if (what_you_typed_match.is_history_what_you_typed_match && | 173   if (what_you_typed_match.is_history_what_you_typed_match && | 
| 173       FixupExactSuggestion(db, params->input, &what_you_typed_match, | 174       FixupExactSuggestion(db, params->input, &what_you_typed_match, | 
| 174                            &history_matches)) { | 175                            &history_matches)) { | 
| 175     // Got an exact match for the user's input.  Treat is as the best match | 176     // Got an exact match for the user's input.  Treat it as the best match | 
| 176     // regardless of the input type. | 177     // regardless of the input type. | 
| 177     exact_suggestion = 1; | 178     exact_suggestion = 1; | 
| 178     params->matches.push_back(what_you_typed_match); | 179     params->matches.push_back(what_you_typed_match); | 
| 179   } else if (params->input.prevent_inline_autocomplete() || | 180   } else if (params->input.prevent_inline_autocomplete() || | 
| 180       history_matches.empty() || | 181       history_matches.empty() || | 
| 181       !PromoteMatchForInlineAutocomplete(params, history_matches.front())) { | 182       !PromoteMatchForInlineAutocomplete(params, history_matches.front())) { | 
| 182     // Failed to promote any URLs for inline autocompletion.  Use the What You | 183     // Failed to promote any URLs for inline autocompletion.  Use the What You | 
| 183     // Typed match, if we have it and the input wasn't UNKNOWN. | 184     // Typed match, if we have it and the input looked like a URL. | 
| 184     first_match = 0; | 185     first_match = 0; | 
| 185     if (have_what_you_typed_match) | 186     if (have_what_you_typed_match) | 
| 186       params->matches.push_back(what_you_typed_match); | 187       params->matches.push_back(what_you_typed_match); | 
| 187   } | 188   } | 
| 188 | 189 | 
| 189   // This is the end of the synchronous pass. | 190   // This is the end of the synchronous pass. | 
| 190   if (!backend) | 191   if (!backend) | 
| 191     return; | 192     return; | 
| 192 | 193 | 
| 193   // Remove redirects and trim list to size.  We want to provide up to | 194   // Remove redirects and trim list to size.  We want to provide up to | 
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 457 | 458 | 
| 458 // static | 459 // static | 
| 459 int HistoryURLProvider::CalculateRelevance(AutocompleteInput::Type input_type, | 460 int HistoryURLProvider::CalculateRelevance(AutocompleteInput::Type input_type, | 
| 460                                            MatchType match_type, | 461                                            MatchType match_type, | 
| 461                                            size_t match_number) { | 462                                            size_t match_number) { | 
| 462   switch (match_type) { | 463   switch (match_type) { | 
| 463     case INLINE_AUTOCOMPLETE: | 464     case INLINE_AUTOCOMPLETE: | 
| 464       return 1400; | 465       return 1400; | 
| 465 | 466 | 
| 466     case WHAT_YOU_TYPED: | 467     case WHAT_YOU_TYPED: | 
| 467       return (input_type == AutocompleteInput::REQUESTED_URL) ? 1300 : 1200; | 468       return 1200; | 
| 468 | 469 | 
| 469     default: | 470     default: | 
| 470       return 900 + static_cast<int>(match_number); | 471       return 900 + static_cast<int>(match_number); | 
| 471   } | 472   } | 
| 472 } | 473 } | 
| 473 | 474 | 
| 474 // static | 475 // static | 
| 475 GURL HistoryURLProvider::ConvertToHostOnly(const HistoryMatch& match, | 476 GURL HistoryURLProvider::ConvertToHostOnly(const HistoryMatch& match, | 
| 476                                            const std::wstring& input) { | 477                                            const std::wstring& input) { | 
| 477   // See if we should try to do host-only suggestions for this URL. Nonstandard | 478   // See if we should try to do host-only suggestions for this URL. Nonstandard | 
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 585     matches->push_front(match); | 586     matches->push_front(match); | 
| 586   else | 587   else | 
| 587     matches->push_back(match); | 588     matches->push_back(match); | 
| 588 } | 589 } | 
| 589 | 590 | 
| 590 void HistoryURLProvider::RunAutocompletePasses( | 591 void HistoryURLProvider::RunAutocompletePasses( | 
| 591     const AutocompleteInput& input, | 592     const AutocompleteInput& input, | 
| 592     bool fixup_input_and_run_pass_1) { | 593     bool fixup_input_and_run_pass_1) { | 
| 593   matches_.clear(); | 594   matches_.clear(); | 
| 594 | 595 | 
| 595   if ((input.type() != AutocompleteInput::UNKNOWN) && | 596   if ((input.type() == AutocompleteInput::INVALID) || | 
| 596       (input.type() != AutocompleteInput::REQUESTED_URL) && | 597       (input.type() == AutocompleteInput::FORCED_QUERY)) | 
| 597       (input.type() != AutocompleteInput::URL)) |  | 
| 598     return; | 598     return; | 
| 599 | 599 | 
| 600   // Create a match for exactly what the user typed.  This will only be used as | 600   // Create a match for exactly what the user typed.  This will only be used as | 
| 601   // a fallback in case we can't get the history service or URL DB; otherwise, | 601   // a fallback in case we can't get the history service or URL DB; otherwise, | 
| 602   // we'll run this again in DoAutocomplete() and use that result instead. | 602   // we'll run this again in DoAutocomplete() and use that result instead. | 
| 603   const bool trim_http = !url_util::FindAndCompareScheme( | 603   const bool trim_http = !url_util::FindAndCompareScheme( | 
| 604       WideToUTF8(input.text()), chrome::kHttpScheme, NULL); | 604       WideToUTF8(input.text()), chrome::kHttpScheme, NULL); | 
| 605   if (input.canonicalized_url().is_valid()) | 605   // Don't do this for queries -- while we can sometimes mark up a match for | 
|  | 606   // this, it's not what the user wants, and just adds noise. | 
|  | 607   if ((input.type() != AutocompleteInput::QUERY) && | 
|  | 608       input.canonicalized_url().is_valid()) | 
| 606     matches_.push_back(SuggestExactInput(input, trim_http)); | 609     matches_.push_back(SuggestExactInput(input, trim_http)); | 
| 607 | 610 | 
| 608   // We'll need the history service to run both passes, so try to obtain it. | 611   // We'll need the history service to run both passes, so try to obtain it. | 
| 609   HistoryService* const history_service = profile_ ? | 612   HistoryService* const history_service = profile_ ? | 
| 610       profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : history_service_; | 613       profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : history_service_; | 
| 611   if (!history_service) | 614   if (!history_service) | 
| 612     return; | 615     return; | 
| 613 | 616 | 
| 614   // Create the data structure for the autocomplete passes.  We'll save this off | 617   // Create the data structure for the autocomplete passes.  We'll save this off | 
| 615   // onto the |params_| member for later deletion below if we need to run pass | 618   // onto the |params_| member for later deletion below if we need to run pass | 
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 826       history_match.input_location - offset, params->input.text().length(), | 829       history_match.input_location - offset, params->input.text().length(), | 
| 827       match.contents.length(), ACMatchClassification::URL, | 830       match.contents.length(), ACMatchClassification::URL, | 
| 828       &match.contents_class); | 831       &match.contents_class); | 
| 829   match.description = info.title(); | 832   match.description = info.title(); | 
| 830   AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 833   AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 
| 831                                            ACMatchClassification::NONE, | 834                                            ACMatchClassification::NONE, | 
| 832                                            &match.description_class); | 835                                            &match.description_class); | 
| 833 | 836 | 
| 834   return match; | 837   return match; | 
| 835 } | 838 } | 
| OLD | NEW | 
|---|