Commit 6ddc4148 authored by thestig@chromium.org's avatar thestig@chromium.org

Revert 56939 - History provider: style cleanup

BUG=none
TEST=it compiles

Review URL: http://codereview.chromium.org/3177020

TBR=isherman@chromium.org
Review URL: http://codereview.chromium.org/3192006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56943 0039d316-1c4b-4281-b951-d872f2087c98
parent c876c6ed
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/autocomplete/history_provider_util.h"
namespace history {
const int kLowQualityMatchTypedLimit = 1;
const int kLowQualityMatchVisitLimit = 3;
const int kLowQualityMatchAgeLimitInDays = 3;
HistoryMatch::HistoryMatch()
: url_info(),
input_location(std::wstring::npos),
match_in_scheme(false),
innermost_match(true) {
}
HistoryMatch::HistoryMatch(const URLRow& url_info,
size_t input_location,
bool match_in_scheme,
bool innermost_match)
: url_info(url_info),
input_location(input_location),
match_in_scheme(match_in_scheme),
innermost_match(innermost_match) {
}
bool HistoryMatch::operator==(const GURL& url) const {
return url_info.url() == url;
}
base::Time AutocompleteAgeThreshold() {
return (base::Time::Now() -
base::TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays));
}
}
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_UTIL_H_
#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_UTIL_H_
#pragma once
#include <deque>
#include <vector>
#include "chrome/browser/history/history_types.h"
namespace history {
// Constants which specify, when considered altogether, 'significant'
// history items. These are used to filter out insignificant items
// for consideration as autocomplete candidates.
extern const int kLowQualityMatchTypedLimit;
extern const int kLowQualityMatchVisitLimit;
extern const int kLowQualityMatchAgeLimitInDays;
// Used for intermediate history result operations.
struct HistoryMatch {
// Required for STL, we don't use this directly.
HistoryMatch();
HistoryMatch(const URLRow& url_info,
size_t input_location,
bool match_in_scheme,
bool innermost_match);
bool operator==(const GURL& url) const;
URLRow url_info;
// The offset of the user's input within the URL.
size_t input_location;
// Whether this is a match in the scheme. This determines whether we'll go
// ahead and show a scheme on the URL even if the user didn't type one.
// If our best match was in the scheme, not showing the scheme is both
// confusing and, for inline autocomplete of the fill_into_edit, dangerous.
// (If the user types "h" and we match "http://foo/", we need to inline
// autocomplete that, not "foo/", which won't show anything at all, and
// will mislead the user into thinking the What You Typed match is what's
// selected.)
bool match_in_scheme;
// A match after any scheme/"www.", if the user input could match at both
// locations. If the user types "w", an innermost match ("website.com") is
// better than a non-innermost match ("www.google.com"). If the user types
// "x", no scheme in our prefix list (or "www.") begins with x, so all
// matches are, vacuously, "innermost matches".
bool innermost_match;
};
typedef std::deque<HistoryMatch> HistoryMatches;
struct Prefix {
Prefix(const std::wstring& prefix, int num_components)
: prefix(prefix),
num_components(num_components) {}
std::wstring prefix;
// The number of "components" in the prefix. The scheme is a component,
// and the initial "www." or "ftp." is a component. So "http://foo.com"
// and "www.bar.com" each have one component, "ftp://ftp.ftp.com" has two,
// and "mysite.com" has none. This is used to tell whether the user's
// input is an innermost match or not. See comments in HistoryMatch.
int num_components;
};
typedef std::vector<Prefix> Prefixes;
// Returns the date threshold for considering an history item as significant.
base::Time AutocompleteAgeThreshold();
}
#endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_UTIL_H_
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_
#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_ #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_
#pragma once
#include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete.h"
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
using base::Time; using base::Time;
using base::TimeDelta; using base::TimeDelta;
using base::TimeTicks; using base::TimeTicks;
// TODO(mrossetti): Move these to a more appropriate place.
using history::Prefix; using history::Prefix;
using history::Prefixes; using history::Prefixes;
using history::HistoryMatch; using history::HistoryMatch;
...@@ -113,24 +114,6 @@ HistoryURLProviderParams::HistoryURLProviderParams( ...@@ -113,24 +114,6 @@ HistoryURLProviderParams::HistoryURLProviderParams(
languages(languages) { languages(languages) {
} }
HistoryURLProvider::HistoryURLProvider(ACProviderListener* listener,
Profile* profile)
: AutocompleteProvider(listener, profile, "HistoryURL"),
prefixes_(GetPrefixes()),
params_(NULL) {
}
#ifdef UNIT_TEST
HistoryURLProvider::HistoryURLProvider(ACProviderListener* listener,
Profile* profile,
const std::wstring& languages)
: AutocompleteProvider(listener, profile, "History"),
prefixes_(GetPrefixes()),
params_(NULL),
languages_(languages) {
}
#endif
void HistoryURLProvider::Start(const AutocompleteInput& input, void HistoryURLProvider::Start(const AutocompleteInput& input,
bool minimal_changes) { bool minimal_changes) {
// NOTE: We could try hard to do less work in the |minimal_changes| case // NOTE: We could try hard to do less work in the |minimal_changes| case
...@@ -801,8 +784,10 @@ void HistoryURLProvider::CullPoorMatches(HistoryMatches* matches) const { ...@@ -801,8 +784,10 @@ void HistoryURLProvider::CullPoorMatches(HistoryMatches* matches) const {
Time recent_threshold = history::AutocompleteAgeThreshold(); Time recent_threshold = history::AutocompleteAgeThreshold();
for (HistoryMatches::iterator i(matches->begin()); i != matches->end();) { for (HistoryMatches::iterator i(matches->begin()); i != matches->end();) {
const history::URLRow& url_info(i->url_info); const history::URLRow& url_info(i->url_info);
if ((url_info.typed_count() <= history::kLowQualityMatchTypedLimit) && if ((url_info.typed_count() <=
(url_info.visit_count() <= history::kLowQualityMatchVisitLimit) && history::kLowQualityMatchTypedLimit) &&
(url_info.visit_count() <=
history::kLowQualityMatchVisitLimit) &&
(url_info.last_visit() < recent_threshold)) { (url_info.last_visit() < recent_threshold)) {
i = matches->erase(i); i = matches->erase(i);
} else { } else {
......
...@@ -6,18 +6,16 @@ ...@@ -6,18 +6,16 @@
#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_
#pragma once #pragma once
#include <vector>
#include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/history_provider_util.h" #include "chrome/browser/history/history_types.h"
class MessageLoop; class MessageLoop;
class Profile; class Profile;
namespace history { namespace history {
class HistoryBackend;
class HistoryBackend;
class URLDatabase;
class URLRow;
} // namespace history } // namespace history
// How history autocomplete works // How history autocomplete works
...@@ -133,12 +131,21 @@ struct HistoryURLProviderParams { ...@@ -133,12 +131,21 @@ struct HistoryURLProviderParams {
// anything on destruction. // anything on destruction.
class HistoryURLProvider : public AutocompleteProvider { class HistoryURLProvider : public AutocompleteProvider {
public: public:
HistoryURLProvider(ACProviderListener* listener, Profile* profile); HistoryURLProvider(ACProviderListener* listener, Profile* profile)
: AutocompleteProvider(listener, profile, "HistoryURL"),
prefixes_(GetPrefixes()),
params_(NULL) {
}
#ifdef UNIT_TEST #ifdef UNIT_TEST
HistoryURLProvider(ACProviderListener* listener, HistoryURLProvider(ACProviderListener* listener,
Profile* profile, Profile* profile,
const std::wstring& languages); const std::wstring& languages)
: AutocompleteProvider(listener, profile, "History"),
prefixes_(GetPrefixes()),
params_(NULL),
languages_(languages) {
}
#endif #endif
// no destructor (see note above) // no destructor (see note above)
...@@ -294,9 +301,10 @@ class HistoryURLProvider : public AutocompleteProvider { ...@@ -294,9 +301,10 @@ class HistoryURLProvider : public AutocompleteProvider {
// input identified by |source_index|. If |source_index| or an item before // input identified by |source_index|. If |source_index| or an item before
// is removed, the next item will be shifted, and this allows the caller to // is removed, the next item will be shifted, and this allows the caller to
// pick up on the next one when this happens. // pick up on the next one when this happens.
size_t RemoveSubsequentMatchesOf(history::HistoryMatches* matches, size_t RemoveSubsequentMatchesOf(
size_t source_index, history::HistoryMatches* matches,
const std::vector<GURL>& remove) const; size_t source_index,
const std::vector<GURL>& remove) const;
// Converts a line from the database into an autocomplete match for display. // Converts a line from the database into an autocomplete match for display.
AutocompleteMatch HistoryMatchToACMatch( AutocompleteMatch HistoryMatchToACMatch(
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -238,4 +238,10 @@ void QueryResults::AdjustResultMap(size_t begin, size_t end, ptrdiff_t delta) { ...@@ -238,4 +238,10 @@ void QueryResults::AdjustResultMap(size_t begin, size_t end, ptrdiff_t delta) {
} }
} }
Time AutocompleteAgeThreshold() {
Time recent_threshold =
Time::Now() - TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays);
return recent_threshold;
}
} // namespace history } // namespace history
...@@ -540,6 +540,80 @@ struct Images { ...@@ -540,6 +540,80 @@ struct Images {
typedef std::vector<MostVisitedURL> MostVisitedURLList; typedef std::vector<MostVisitedURL> MostVisitedURLList;
// Used for intermediate history result operations.
struct HistoryMatch {
// Required for STL, we don't use this directly.
HistoryMatch()
: url_info(),
input_location(std::wstring::npos),
match_in_scheme(false),
innermost_match(true) {
}
HistoryMatch(const URLRow& url_info,
size_t input_location,
bool match_in_scheme,
bool innermost_match)
: url_info(url_info),
input_location(input_location),
match_in_scheme(match_in_scheme),
innermost_match(innermost_match) {
}
bool operator==(const GURL& url) const {
return url_info.url() == url;
}
URLRow url_info;
// The offset of the user's input within the URL.
size_t input_location;
// Whether this is a match in the scheme. This determines whether we'll go
// ahead and show a scheme on the URL even if the user didn't type one.
// If our best match was in the scheme, not showing the scheme is both
// confusing and, for inline autocomplete of the fill_into_edit, dangerous.
// (If the user types "h" and we match "http://foo/", we need to inline
// autocomplete that, not "foo/", which won't show anything at all, and
// will mislead the user into thinking the What You Typed match is what's
// selected.)
bool match_in_scheme;
// A match after any scheme/"www.", if the user input could match at both
// locations. If the user types "w", an innermost match ("website.com") is
// better than a non-innermost match ("www.google.com"). If the user types
// "x", no scheme in our prefix list (or "www.") begins with x, so all
// matches are, vacuously, "innermost matches".
bool innermost_match;
};
typedef std::deque<HistoryMatch> HistoryMatches;
struct Prefix {
Prefix(std::wstring const& prefix, int num_components)
: prefix(prefix),
num_components(num_components) {}
std::wstring prefix;
// The number of "components" in the prefix. The scheme is a component,
// and the initial "www." or "ftp." is a component. So "http://foo.com"
// and "www.bar.com" each have one component, "ftp://ftp.ftp.com" has two,
// and "mysite.com" has none. This is used to tell whether the user's
// input is an innermost match or not. See comments in HistoryMatch.
int num_components;
};
typedef std::vector<Prefix> Prefixes;
// Constants which specify, when considered altogether, 'significant'
// history items. These are used to filter out insignificant items
// for consideration as autocomplete candidates.
const int kLowQualityMatchTypedLimit = 1;
const int kLowQualityMatchVisitLimit = 3;
const int kLowQualityMatchAgeLimitInDays = 3;
// Returns the date threshold for considering an history item as significant.
base::Time AutocompleteAgeThreshold();
} // namespace history } // namespace history
#endif // CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_ #endif // CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_
...@@ -108,8 +108,6 @@ ...@@ -108,8 +108,6 @@
'browser/autocomplete/autocomplete_popup_view_mac.mm', 'browser/autocomplete/autocomplete_popup_view_mac.mm',
'browser/autocomplete/history_contents_provider.cc', 'browser/autocomplete/history_contents_provider.cc',
'browser/autocomplete/history_contents_provider.h', 'browser/autocomplete/history_contents_provider.h',
'browser/autocomplete/history_provider_util.cc',
'browser/autocomplete/history_provider_util.h',
'browser/autocomplete/history_quick_provider.cc', 'browser/autocomplete/history_quick_provider.cc',
'browser/autocomplete/history_quick_provider.h', 'browser/autocomplete/history_quick_provider.h',
'browser/autocomplete/history_url_provider.cc', 'browser/autocomplete/history_url_provider.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment