| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/history/history.h" | 14 #include "chrome/browser/history/history.h" |
| 15 #include "chrome/browser/history/history_backend.h" | 15 #include "chrome/browser/history/history_backend.h" |
| 16 #include "chrome/browser/history/history_database.h" | 16 #include "chrome/browser/history/history_database.h" |
| 17 #include "chrome/browser/net/url_fixer_upper.h" | 17 #include "chrome/browser/net/url_fixer_upper.h" |
| 18 #include "chrome/browser/pref_service.h" | 18 #include "chrome/browser/pref_service.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 23 #include "googleurl/src/url_parse.h" | 23 #include "googleurl/src/url_parse.h" |
| 24 #include "googleurl/src/url_util.h" | 24 #include "googleurl/src/url_util.h" |
| 25 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 26 | 26 |
| 27 using base::Time; | 27 using base::Time; |
| 28 using base::TimeDelta; | 28 using base::TimeDelta; |
| 29 using base::TimeTicks; | 29 using base::TimeTicks; |
| 30 // TODO(mrossetti): Move these to a more appropriate place. |
| 30 using history::Prefix; | 31 using history::Prefix; |
| 31 using history::Prefixes; | 32 using history::Prefixes; |
| 32 using history::HistoryMatch; | 33 using history::HistoryMatch; |
| 33 using history::HistoryMatches; | 34 using history::HistoryMatches; |
| 34 | 35 |
| 35 namespace history { | 36 namespace history { |
| 36 | 37 |
| 37 // Returns true if |url| is just a host (e.g. "http://www.google.com/") and | 38 // Returns true if |url| is just a host (e.g. "http://www.google.com/") and |
| 38 // not some other subpage (e.g. "http://www.google.com/foo.html"). | 39 // not some other subpage (e.g. "http://www.google.com/foo.html"). |
| 39 bool IsHostOnly(const GURL& url) { | 40 bool IsHostOnly(const GURL& url) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 bool trim_http, | 107 bool trim_http, |
| 107 const std::wstring& languages) | 108 const std::wstring& languages) |
| 108 : message_loop(MessageLoop::current()), | 109 : message_loop(MessageLoop::current()), |
| 109 input(input), | 110 input(input), |
| 110 trim_http(trim_http), | 111 trim_http(trim_http), |
| 111 cancel(false), | 112 cancel(false), |
| 112 failed(false), | 113 failed(false), |
| 113 languages(languages) { | 114 languages(languages) { |
| 114 } | 115 } |
| 115 | 116 |
| 116 HistoryURLProvider::HistoryURLProvider(ACProviderListener* listener, | |
| 117 Profile* profile) | |
| 118 : AutocompleteProvider(listener, profile, "HistoryURL"), | |
| 119 prefixes_(GetPrefixes()), | |
| 120 params_(NULL) { | |
| 121 } | |
| 122 | |
| 123 #ifdef UNIT_TEST | |
| 124 HistoryURLProvider::HistoryURLProvider(ACProviderListener* listener, | |
| 125 Profile* profile, | |
| 126 const std::wstring& languages) | |
| 127 : AutocompleteProvider(listener, profile, "History"), | |
| 128 prefixes_(GetPrefixes()), | |
| 129 params_(NULL), | |
| 130 languages_(languages) { | |
| 131 } | |
| 132 #endif | |
| 133 | |
| 134 void HistoryURLProvider::Start(const AutocompleteInput& input, | 117 void HistoryURLProvider::Start(const AutocompleteInput& input, |
| 135 bool minimal_changes) { | 118 bool minimal_changes) { |
| 136 // NOTE: We could try hard to do less work in the |minimal_changes| case | 119 // NOTE: We could try hard to do less work in the |minimal_changes| case |
| 137 // here; some clever caching would let us reuse the raw matches from the | 120 // here; some clever caching would let us reuse the raw matches from the |
| 138 // history DB without re-querying. However, we'd still have to go back to | 121 // history DB without re-querying. However, we'd still have to go back to |
| 139 // the history thread to mark these up properly, and if pass 2 is currently | 122 // the history thread to mark these up properly, and if pass 2 is currently |
| 140 // running, we'd need to wait for it to return to the main thread before | 123 // running, we'd need to wait for it to return to the main thread before |
| 141 // doing this (we can't just write new data for it to read due to thread | 124 // doing this (we can't just write new data for it to read due to thread |
| 142 // safety issues). At that point it's just as fast, and easier, to simply | 125 // safety issues). At that point it's just as fast, and easier, to simply |
| 143 // re-run the query from scratch and ignore |minimal_changes|. | 126 // re-run the query from scratch and ignore |minimal_changes|. |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 else | 777 else |
| 795 ++j; | 778 ++j; |
| 796 } | 779 } |
| 797 } | 780 } |
| 798 } | 781 } |
| 799 | 782 |
| 800 void HistoryURLProvider::CullPoorMatches(HistoryMatches* matches) const { | 783 void HistoryURLProvider::CullPoorMatches(HistoryMatches* matches) const { |
| 801 Time recent_threshold = history::AutocompleteAgeThreshold(); | 784 Time recent_threshold = history::AutocompleteAgeThreshold(); |
| 802 for (HistoryMatches::iterator i(matches->begin()); i != matches->end();) { | 785 for (HistoryMatches::iterator i(matches->begin()); i != matches->end();) { |
| 803 const history::URLRow& url_info(i->url_info); | 786 const history::URLRow& url_info(i->url_info); |
| 804 if ((url_info.typed_count() <= history::kLowQualityMatchTypedLimit) && | 787 if ((url_info.typed_count() <= |
| 805 (url_info.visit_count() <= history::kLowQualityMatchVisitLimit) && | 788 history::kLowQualityMatchTypedLimit) && |
| 789 (url_info.visit_count() <= |
| 790 history::kLowQualityMatchVisitLimit) && |
| 806 (url_info.last_visit() < recent_threshold)) { | 791 (url_info.last_visit() < recent_threshold)) { |
| 807 i = matches->erase(i); | 792 i = matches->erase(i); |
| 808 } else { | 793 } else { |
| 809 ++i; | 794 ++i; |
| 810 } | 795 } |
| 811 } | 796 } |
| 812 } | 797 } |
| 813 | 798 |
| 814 void HistoryURLProvider::CullRedirects(history::HistoryBackend* backend, | 799 void HistoryURLProvider::CullRedirects(history::HistoryBackend* backend, |
| 815 HistoryMatches* matches, | 800 HistoryMatches* matches, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 &match.contents_class); | 898 &match.contents_class); |
| 914 } | 899 } |
| 915 match.description = UTF16ToWide(info.title()); | 900 match.description = UTF16ToWide(info.title()); |
| 916 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 901 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
| 917 UTF16ToWide(info.title()), | 902 UTF16ToWide(info.title()), |
| 918 ACMatchClassification::NONE, | 903 ACMatchClassification::NONE, |
| 919 &match.description_class); | 904 &match.description_class); |
| 920 | 905 |
| 921 return match; | 906 return match; |
| 922 } | 907 } |
| OLD | NEW |