summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/template_url.cc17
-rw-r--r--chrome/browser/template_url.h36
-rw-r--r--chrome/browser/template_url_model.cc30
-rw-r--r--chrome/browser/template_url_model.h8
-rw-r--r--chrome/browser/template_url_model_unittest.cc64
-rw-r--r--chrome/browser/template_url_prepopulate_data.cc158
-rw-r--r--chrome/browser/template_url_unittest.cc16
-rw-r--r--chrome/browser/webdata/web_database.cc73
-rw-r--r--chrome/browser/webdata/web_database.h2
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc33
10 files changed, 277 insertions, 160 deletions
diff --git a/chrome/browser/template_url.cc b/chrome/browser/template_url.cc
index 67f42e3c..aab5221 100644
--- a/chrome/browser/template_url.cc
+++ b/chrome/browser/template_url.cc
@@ -34,6 +34,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/google_url_tracker.h"
+#include "chrome/browser/template_url_model.h"
#include "chrome/common/gfx/favicon_size.h"
#include "net/base/escape.h"
@@ -527,6 +528,15 @@ void TemplateURL::SetURL(const std::wstring& url,
url_.Set(url, index_offset, page_offset);
}
+const std::wstring& TemplateURL::keyword() const {
+ if (autogenerate_keyword_ && keyword_.empty()) {
+ // Generate a keyword and cache it.
+ keyword_ = TemplateURLModel::GenerateKeyword(
+ TemplateURLModel::GenerateSearchURL(this).GetWithEmptyPath(), true);
+ }
+ return keyword_;
+}
+
bool TemplateURL::ShowInDefaultList() const {
return show_in_default_list() && url() && url()->SupportsReplacement();
}
@@ -561,3 +571,10 @@ GURL TemplateURL::GetFavIconURL() const {
}
return GURL();
}
+
+void TemplateURL::InvalidateCachedValues() const {
+ url_.InvalidateCachedValues();
+ suggestions_url_.InvalidateCachedValues();
+ if (autogenerate_keyword_)
+ keyword_.clear();
+}
diff --git a/chrome/browser/template_url.h b/chrome/browser/template_url.h
index 274c835..3e50343 100644
--- a/chrome/browser/template_url.h
+++ b/chrome/browser/template_url.h
@@ -134,11 +134,6 @@ class TemplateURLRef {
// {google:baseURL} or {google:baseSuggestURL}.
bool HasGoogleBaseURLs() const;
- // TemplateURLRef internally caches values to make replacement quick. This
- // method invalidates any cached values. You shouldn't have a need to invoke
- // this, it's invoked by TemplateURLModel when the google base url changes.
- void InvalidateCachedValues() const;
-
private:
friend class TemplateURL;
friend class TemplateURLModelTest;
@@ -167,6 +162,10 @@ class TemplateURLRef {
// The list of elements to replace.
typedef std::vector<struct Replacement> Replacements;
+ // TemplateURLRef internally caches values to make replacement quick. This
+ // method invalidates any cached values.
+ void InvalidateCachedValues() const;
+
// Resets the url.
void Set(const std::wstring& url, int index_offset, int page_offset);
@@ -278,7 +277,8 @@ class TemplateURL {
static GURL GenerateFaviconURL(const GURL& url);
TemplateURL()
- : show_in_default_list_(false),
+ : autogenerate_keyword_(false),
+ show_in_default_list_(false),
safe_for_autoreplace_(false),
id_(0),
date_created_(Time::Now()),
@@ -336,8 +336,22 @@ class TemplateURL {
// Case sensitive keyword matching is confusing. As such, we force all
// keywords to be lower case.
keyword_ = l10n_util::ToLower(keyword);
+ autogenerate_keyword_ = false;
+ }
+ const std::wstring& keyword() const;
+
+ // Whether to autogenerate a keyword from the url() in GetKeyword(). Most
+ // consumers should not need this.
+ // NOTE: Calling set_keyword() turns this back off. Manual and automatic
+ // keywords are mutually exclusive.
+ void set_autogenerate_keyword(bool autogenerate_keyword) {
+ autogenerate_keyword_ = autogenerate_keyword;
+ if (autogenerate_keyword_)
+ keyword_.clear();
+ }
+ bool autogenerate_keyword() const {
+ return autogenerate_keyword_;
}
- const std::wstring& keyword() const { return keyword_; }
// Whether this keyword is shown in the default list of search providers. This
// is just a property and does not indicate whether this TemplateURL has
@@ -417,11 +431,13 @@ class TemplateURL {
int prepopulate_id() const { return prepopulate_id_; }
private:
- // For access to set id.
friend class WebDatabaseTest;
friend class WebDatabase;
friend class TemplateURLModel;
+ // Invalidates cached values on this object and its child TemplateURLRefs.
+ void InvalidateCachedValues() const;
+
// Unique identifier, used when archived to the database.
void set_id(IDType id) { id_ = id;}
@@ -430,7 +446,9 @@ class TemplateURL {
TemplateURLRef suggestions_url_;
TemplateURLRef url_;
GURL originating_url_;
- std::wstring keyword_;
+ mutable std::wstring keyword_;
+ bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached
+ // generated keyword if available.
bool show_in_default_list_;
bool safe_for_autoreplace_;
std::vector<ImageRef> image_refs_;
diff --git a/chrome/browser/template_url_model.cc b/chrome/browser/template_url_model.cc
index 85e4a78..ee1e885 100644
--- a/chrome/browser/template_url_model.cc
+++ b/chrome/browser/template_url_model.cc
@@ -424,9 +424,19 @@ void TemplateURLModel::RemoveFromMaps(const TemplateURL* template_url) {
}
}
-void TemplateURLModel::RemoveFromHostMapByPointer(
+void TemplateURLModel::RemoveFromMapsByPointer(
const TemplateURL* template_url) {
DCHECK(template_url);
+ for (KeywordToTemplateMap::iterator i = keyword_to_template_map_.begin();
+ i != keyword_to_template_map_.end(); ++i) {
+ if (i->second == template_url) {
+ keyword_to_template_map_.erase(i);
+ // A given TemplateURL only occurs once in the map. As soon as we find the
+ // entry, stop.
+ break;
+ }
+ }
+
for (HostToURLsMap::iterator i = host_to_urls_map_.begin();
i != host_to_urls_map_.end(); ++i) {
TemplateURLSet::iterator url_set_iterator = i->second.find(template_url);
@@ -435,7 +445,7 @@ void TemplateURLModel::RemoveFromHostMapByPointer(
if (i->second.empty())
host_to_urls_map_.erase(i);
// A given TemplateURL only occurs once in the map. As soon as we find the
- // entry, return.
+ // entry, stop.
return;
}
}
@@ -727,6 +737,8 @@ void TemplateURLModel::MergeEnginesFromPrepopulateData() {
// User edited the entry, preserve the keyword and description.
loaded_urls[i]->set_safe_for_autoreplace(false);
loaded_urls[i]->set_keyword(existing_url->keyword());
+ loaded_urls[i]->set_autogenerate_keyword(
+ existing_url->autogenerate_keyword());
loaded_urls[i]->set_short_name(existing_url->short_name());
}
Replace(existing_url, loaded_urls[i]);
@@ -934,17 +946,21 @@ bool TemplateURLModel::BuildQueryTerms(const GURL& url,
}
void TemplateURLModel::GoogleBaseURLChanged() {
+ bool something_changed = false;
for (size_t i = 0; i < template_urls_.size(); ++i) {
const TemplateURL* t_url = template_urls_[i];
if ((t_url->url() && t_url->url()->HasGoogleBaseURLs()) ||
(t_url->suggestions_url() &&
t_url->suggestions_url()->HasGoogleBaseURLs())) {
- RemoveFromHostMapByPointer(t_url);
- if (t_url->url())
- t_url->url()->InvalidateCachedValues();
- if (t_url->suggestions_url())
- t_url->suggestions_url()->InvalidateCachedValues();
+ RemoveFromMapsByPointer(t_url);
+ t_url->InvalidateCachedValues();
AddToMaps(t_url);
+ something_changed = true;
}
}
+
+ if (something_changed && loaded_) {
+ FOR_EACH_OBSERVER(TemplateURLModelObserver, model_observers_,
+ OnTemplateURLModelChanged());
+ }
}
diff --git a/chrome/browser/template_url_model.h b/chrome/browser/template_url_model.h
index ae90dc5..9ea3137 100644
--- a/chrome/browser/template_url_model.h
+++ b/chrome/browser/template_url_model.h
@@ -244,10 +244,10 @@ class TemplateURLModel : public WebDataServiceConsumer,
void RemoveFromMaps(const TemplateURL* template_url);
- // Removes the supplied template_url from host_to_urls_map. This searches
- // through *all* entries in host_to_urls_map_ and does not generate the host.
- // This is used when the host of the search term of the TemplateURL changes.
- void RemoveFromHostMapByPointer(const TemplateURL* template_url);
+ // Removes the supplied template_url from the maps. This searches through all
+ // entries in the maps and does not generate the host or keyword.
+ // This is used when the cached content of the TemplateURL changes.
+ void RemoveFromMapsByPointer(const TemplateURL* template_url);
void AddToMaps(const TemplateURL* template_url);
diff --git a/chrome/browser/template_url_model_unittest.cc b/chrome/browser/template_url_model_unittest.cc
index 3af0c5c..492ac2b 100644
--- a/chrome/browser/template_url_model_unittest.cc
+++ b/chrome/browser/template_url_model_unittest.cc
@@ -138,14 +138,16 @@ class TemplateURLModelTest : public testing::Test,
TemplateURLRef::google_base_url_ = NULL;
}
- TemplateURL* AddKeywordWithDate(const std::wstring & keyword,
- const std::wstring & url,
- const std::wstring & short_name,
+ TemplateURL* AddKeywordWithDate(const std::wstring& keyword,
+ bool autogenerate_keyword,
+ const std::wstring& url,
+ const std::wstring& short_name,
bool safe_for_autoreplace,
Time created_date) {
TemplateURL* template_url = new TemplateURL();
template_url->SetURL(url, 0, 0);
template_url->set_keyword(keyword);
+ template_url->set_autogenerate_keyword(autogenerate_keyword);
template_url->set_short_name(short_name);
template_url->set_date_created(created_date);
template_url->set_safe_for_autoreplace(safe_for_autoreplace);
@@ -309,14 +311,16 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) {
EXPECT_EQ(0, model_->GetTemplateURLs().size());
// Create one with a 0 time.
- AddKeywordWithDate(L"key1", L"http://foo1", L"name1", true, Time());
+ AddKeywordWithDate(L"key1", false, L"http://foo1", L"name1", true, Time());
// Create one for now and +/- 1 day.
- AddKeywordWithDate(L"key2", L"http://foo2", L"name2", true, now - one_day);
- AddKeywordWithDate(L"key3", L"http://foo3", L"name3", true, now);
- AddKeywordWithDate(L"key4", L"http://foo4", L"name4", true, now + one_day);
+ AddKeywordWithDate(L"key2", false, L"http://foo2", L"name2", true,
+ now - one_day);
+ AddKeywordWithDate(L"key3", false, L"http://foo3", L"name3", true, now);
+ AddKeywordWithDate(L"key4", false, L"http://foo4", L"name4", true,
+ now + one_day);
// Try the other three states.
- AddKeywordWithDate(L"key5", L"http://foo5", L"name5", false, now);
- AddKeywordWithDate(L"key6", L"http://foo6", L"name6", false, month_ago);
+ AddKeywordWithDate(L"key5", false, L"http://foo5", L"name5", false, now);
+ AddKeywordWithDate(L"key6", false, L"http://foo6", L"name6", false, month_ago);
// We just added a few items, validate them.
EXPECT_EQ(6, model_->GetTemplateURLs().size());
@@ -395,8 +399,8 @@ TEST_F(TemplateURLModelTest, DefaultSearchProvider) {
// Add a new TemplateURL.
VerifyLoad();
const size_t initial_count = model_->GetTemplateURLs().size();
- TemplateURL* t_url =
- AddKeywordWithDate(L"key1", L"http://foo1", L"name1", true, Time());
+ TemplateURL* t_url = AddKeywordWithDate(L"key1", false, L"http://foo1",
+ L"name1", true, Time());
changed_count_ = 0;
model_->SetDefaultSearchProvider(t_url);
@@ -427,7 +431,8 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) {
const size_t initial_count = model_->GetTemplateURLs().size();
- AddKeywordWithDate(std::wstring(), L"http://foo1", L"name1", true, Time());
+ AddKeywordWithDate(std::wstring(), false, L"http://foo1", L"name1", true,
+ Time());
// We just added a few items, validate them.
ASSERT_EQ(initial_count + 1, model_->GetTemplateURLs().size());
@@ -449,8 +454,8 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) {
TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) {
ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", std::wstring(), NULL));
- TemplateURL* t_url =
- AddKeywordWithDate(L"foo", L"http://foo1", L"name1", true, Time());
+ TemplateURL* t_url = AddKeywordWithDate(L"foo", false, L"http://foo1",
+ L"name1", true, Time());
// Can still replace, newly added template url is marked safe to replace.
ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", L"http://foo2", NULL));
@@ -465,8 +470,8 @@ TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) {
TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) {
ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", L"http://foo.com", NULL));
- TemplateURL* t_url =
- AddKeywordWithDate(L"foo", L"http://foo.com", L"name1", true, Time());
+ TemplateURL* t_url = AddKeywordWithDate(L"foo", false, L"http://foo.com",
+ L"name1", true, Time());
// Can still replace, newly added template url is marked safe to replace.
ASSERT_TRUE(model_->CanReplaceKeyword(L"bar", L"http://foo.com", NULL));
@@ -594,8 +599,8 @@ TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) {
{ "http://x/foo?q=b&q=xx", L"" },
};
- AddKeywordWithDate(L"x", L"http://x/foo?q={searchTerms}", L"name", false,
- Time());
+ AddKeywordWithDate(L"x", false, L"http://x/foo?q={searchTerms}", L"name",
+ false, Time());
for (size_t i = 0; i < arraysize(data); ++i) {
model_->UpdateKeywordSearchTermsForURL(history::URLRow(GURL(data[i].url)));
@@ -612,7 +617,7 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) {
{ "http://x/foo?y=xx" },
};
- AddKeywordWithDate(L"x", L"http://x/foo", L"name", false, Time());
+ AddKeywordWithDate(L"x", false, L"http://x/foo", L"name", false, Time());
for (size_t i = 0; i < arraysize(data); ++i) {
model_->UpdateKeywordSearchTermsForURL(history::URLRow(GURL(data[i].url)));
@@ -621,21 +626,28 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) {
}
TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) {
+ // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data,
+ // which also has a {google:baseURL} keyword in it, which will confuse this
+ // test.
SetGoogleBaseURL(L"http://google.com/");
- const TemplateURL* t_url =
- AddKeywordWithDate(L"x", L"{google:baseURL}?q={searchTerms}",
- L"name", false, Time());
+ const TemplateURL* t_url = AddKeywordWithDate(std::wstring(), true,
+ L"{google:baseURL}?q={searchTerms}", L"name", false, Time());
ASSERT_EQ(t_url, model_->GetTemplateURLForHost("google.com"));
- ASSERT_EQ("google.com", t_url->url()->GetHost());
+ EXPECT_EQ("google.com", t_url->url()->GetHost());
+ EXPECT_EQ(L"google.com", t_url->keyword());
// Change the Google base url.
+ model_->loaded_ = true; // Hack to make sure we get notified of the base URL
+ // changing.
SetGoogleBaseURL(L"http://foo.com/");
model_->GoogleBaseURLChanged();
+ VerifyObserverCount(1);
// Make sure the host->TemplateURL map was updated appropriately.
ASSERT_EQ(t_url, model_->GetTemplateURLForHost("foo.com"));
- ASSERT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL);
- ASSERT_EQ("foo.com", t_url->url()->GetHost());
- ASSERT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url,
+ EXPECT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL);
+ EXPECT_EQ("foo.com", t_url->url()->GetHost());
+ EXPECT_EQ(L"foo.com", t_url->keyword());
+ EXPECT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url,
L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
}
diff --git a/chrome/browser/template_url_prepopulate_data.cc b/chrome/browser/template_url_prepopulate_data.cc
index d742daa..6f9d484 100644
--- a/chrome/browser/template_url_prepopulate_data.cc
+++ b/chrome/browser/template_url_prepopulate_data.cc
@@ -31,7 +31,6 @@
#include "base/command_line.h"
#include "chrome/browser/template_url.h"
-#include "chrome/browser/template_url_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -45,10 +44,11 @@ namespace {
struct PrepopulatedEngine {
const wchar_t* const name;
- const wchar_t* const keyword; // If NULL, we'll autogenerate a keyword
- // based on the search_url.
- // If the empty string, the engine has no
- // keyword.
+ // If NULL, we'll autogenerate a keyword based on the search_url every time
+ // someone asks. Only entries which need keywords to auto-track a dynamically
+ // generated search URL should use this.
+ // If the empty string, the engine has no keyword.
+ const wchar_t* const keyword;
const wchar_t* const favicon_url; // If NULL, there is no favicon.
const wchar_t* const search_url;
const char* const encoding;
@@ -73,7 +73,7 @@ struct PrepopulatedEngine {
const PrepopulatedEngine abcsok = {
L"ABC S\x00f8k",
- NULL,
+ L"abcsok.no",
L"http://abcsok.no/favicon.ico",
L"http://abcsok.no/index.html?q={searchTerms}",
"UTF-8",
@@ -83,7 +83,7 @@ const PrepopulatedEngine abcsok = {
const PrepopulatedEngine adonde = {
L"Adonde.com",
- NULL,
+ L"adonde.com",
L"http://www.adonde.com/favicon.ico",
L"http://www.adonde.com/peru/peru.html?sitesearch=adonde.com&"
L"client=pub-6263803831447773&ie={inputEncoding}&cof=GALT%3A%23CC0000"
@@ -97,7 +97,7 @@ const PrepopulatedEngine adonde = {
const PrepopulatedEngine aeiou = {
L"AEIOU",
- NULL,
+ L"aeiou.pt",
L"http://aeiou.pt/favicon.ico",
L"http://aeiou.pt/pesquisa/index.php?p={searchTerms}",
"ISO-8859-1",
@@ -107,7 +107,7 @@ const PrepopulatedEngine aeiou = {
const PrepopulatedEngine aladin = {
L"Aladin",
- NULL,
+ L"aladin.info",
L"http://www.aladin.info/favicon.ico",
L"http://www.aladin.info/search/index.php?term={searchTerms}&req=search&"
L"source=2",
@@ -118,7 +118,7 @@ const PrepopulatedEngine aladin = {
const PrepopulatedEngine alltheweb = {
L"AlltheWeb",
- NULL,
+ L"alltheweb.com",
L"http://alltheweb.com/favicon.ico",
L"http://alltheweb.com/search?cs={inputEncoding}&q={searchTerms}",
"ISO-8859-1",
@@ -128,7 +128,7 @@ const PrepopulatedEngine alltheweb = {
const PrepopulatedEngine altavista = {
L"AltaVista",
- NULL,
+ L"altavista.com",
L"http://www.altavista.com/favicon.ico",
L"http://www.altavista.com/web/results?q={searchTerms}",
"UTF-8",
@@ -138,7 +138,7 @@ const PrepopulatedEngine altavista = {
const PrepopulatedEngine altavista_ar = {
L"AltaVista",
- NULL,
+ L"ar.altavista.com",
L"http://ar.altavista.com/favicon.ico",
L"http://ar.altavista.com/web/results?q={searchTerms}",
"UTF-8",
@@ -148,7 +148,7 @@ const PrepopulatedEngine altavista_ar = {
const PrepopulatedEngine altavista_es = {
L"AltaVista",
- NULL,
+ L"es.altavista.com",
L"http://es.altavista.com/favicon.ico",
L"http://es.altavista.com/web/results?q={searchTerms}",
"UTF-8",
@@ -158,7 +158,7 @@ const PrepopulatedEngine altavista_es = {
const PrepopulatedEngine altavista_mx = {
L"AltaVista",
- NULL,
+ L"mx.altavista.com",
L"http://mx.altavista.com/favicon.ico",
L"http://mx.altavista.com/web/results?q={searchTerms}",
"UTF-8",
@@ -168,7 +168,7 @@ const PrepopulatedEngine altavista_mx = {
const PrepopulatedEngine altavista_se = {
L"AltaVista",
- NULL,
+ L"se.altavista.com",
L"http://se.altavista.com/favicon.ico",
L"http://se.altavista.com/web/results?q={searchTerms}",
"UTF-8",
@@ -208,7 +208,7 @@ const PrepopulatedEngine aonde = {
const PrepopulatedEngine araby = {
L"\x0639\x0631\x0628\x064a",
- NULL,
+ L"araby.com",
L"http://araby.com/favicon.ico",
L"http://araby.com/?q={searchTerms}",
"UTF-8",
@@ -218,7 +218,7 @@ const PrepopulatedEngine araby = {
const PrepopulatedEngine ask = {
L"Ask",
- NULL,
+ L"ask.com",
L"http://www.ask.com/favicon.ico",
L"http://www.ask.com/web?q={searchTerms}",
"UTF-8",
@@ -228,7 +228,7 @@ const PrepopulatedEngine ask = {
const PrepopulatedEngine ask_de = {
L"Ask.com Deutschland",
- NULL,
+ L"de.ask.com",
L"http://de.ask.com/favicon.ico",
L"http://de.ask.com/web?q={searchTerms}",
"UTF-8",
@@ -238,7 +238,7 @@ const PrepopulatedEngine ask_de = {
const PrepopulatedEngine ask_es = {
L"Ask.com Espa" L"\x00f1" L"a",
- NULL,
+ L"es.ask.com",
L"http://es.ask.com/favicon.ico",
L"http://es.ask.com/web?q={searchTerms}",
"UTF-8",
@@ -248,7 +248,7 @@ const PrepopulatedEngine ask_es = {
const PrepopulatedEngine ask_it = {
L"Ask.com Italia",
- NULL,
+ L"it.ask.com",
L"http://it.ask.com/favicon.ico",
L"http://it.ask.com/web?q={searchTerms}",
"UTF-8",
@@ -258,7 +258,7 @@ const PrepopulatedEngine ask_it = {
const PrepopulatedEngine ask_uk = {
L"Ask.com UK",
- NULL,
+ L"uk.ask.com",
L"http://uk.ask.com/favicon.ico",
L"http://uk.ask.com/web?q={searchTerms}",
"UTF-8",
@@ -288,7 +288,7 @@ const PrepopulatedEngine atlas_sk = {
const PrepopulatedEngine baidu = {
L"\x767e\x5ea6",
- NULL,
+ L"baidu.com",
L"http://www.baidu.com/favicon.ico",
L"http://www.baidu.com/s?wd={searchTerms}",
"GB2312",
@@ -318,7 +318,7 @@ const PrepopulatedEngine bigmir = {
const PrepopulatedEngine bluewin = {
L"Bluewin",
- NULL,
+ L"search.bluewin.ch",
L"http://search.bluewin.ch/favicon.ico",
L"http://search.bluewin.ch/bw/search/web/de/result.jsp?query={searchTerms}",
"ISO-8859-1",
@@ -398,7 +398,7 @@ const PrepopulatedEngine delfi_lv = {
const PrepopulatedEngine dogpile = {
L"Dogpile",
- NULL,
+ L"dogpile.com",
L"http://ttl60m.wsoo.infospace.com.edgesuite.net/dogpile/ws/pics/favicon.ico",
L"http://www.dogpile.com/dogpile/ws/results/Web/{searchTerms}/1/417/"
L"TopNavigation/Relevance/_iceUrlFlag=7?_IceUrl=true",
@@ -409,7 +409,7 @@ const PrepopulatedEngine dogpile = {
const PrepopulatedEngine embla = {
L"Embla",
- NULL,
+ L"embla.is",
L"http://embla.is/favicon.ico",
L"http://embla.is/mm/embla/?s={searchTerms}",
"ISO-8859-1",
@@ -429,7 +429,7 @@ const PrepopulatedEngine empas = {
const PrepopulatedEngine eniro_dk = {
L"Eniro",
- NULL,
+ L"eniro.dk",
L"http://eniro.dk/favicon.ico",
L"http://eniro.dk/query?search_word={searchTerms}&what=web_local",
"ISO-8859-1",
@@ -439,7 +439,7 @@ const PrepopulatedEngine eniro_dk = {
const PrepopulatedEngine eniro_fi = {
L"Eniro",
- NULL,
+ L"eniro.fi",
L"http://eniro.fi/favicon.ico",
L"http://eniro.fi/query?search_word={searchTerms}&what=web_local",
"ISO-8859-1",
@@ -449,7 +449,7 @@ const PrepopulatedEngine eniro_fi = {
const PrepopulatedEngine eniro_se = {
L"Eniro",
- NULL,
+ L"eniro.se",
L"http://eniro.se/favicon.ico",
L"http://eniro.se/query?search_word={searchTerms}&what=web_local",
"ISO-8859-1",
@@ -459,7 +459,7 @@ const PrepopulatedEngine eniro_se = {
const PrepopulatedEngine finna = {
L"FINNA",
- NULL,
+ L"finna.is",
L"http://finna.is/favicon.ico",
L"http://finna.is/WWW_Search/?query={searchTerms}",
"UTF-8",
@@ -526,7 +526,7 @@ const PrepopulatedEngine google = {
const PrepopulatedEngine guruji = {
L"guruji",
- NULL,
+ L"guruji.com",
L"http://guruji.com/favicon.ico",
L"http://guruji.com/search?q={searchTerms}",
"UTF-8",
@@ -576,7 +576,7 @@ const PrepopulatedEngine infoseek = {
const PrepopulatedEngine jabse = {
L"Jabse",
- NULL,
+ L"jabse.com",
L"http://www.jabse.com/favicon.ico",
L"http://www.jabse.com/searchmachine.php?query={searchTerms}",
"UTF-8",
@@ -586,7 +586,7 @@ const PrepopulatedEngine jabse = {
const PrepopulatedEngine jamaicalive = {
L"JamaicaLive",
- NULL,
+ L"jalive.com.jm",
L"http://jalive.com.jm/favicon.ico",
L"http://jalive.com.jm/search/?mode=allwords&search={searchTerms}",
"ISO-8859-1",
@@ -616,7 +616,7 @@ const PrepopulatedEngine krstarica = {
const PrepopulatedEngine kvasir = {
L"Kvasir",
- NULL,
+ L"kvasir.no",
L"http://www.kvasir.no/img/favicon.ico",
L"http://www.kvasir.no/nettsok/searchResult.html?searchExpr={searchTerms}",
"ISO-8859-1",
@@ -626,7 +626,7 @@ const PrepopulatedEngine kvasir = {
const PrepopulatedEngine latne = {
L"LATNE",
- NULL,
+ L"latne.lv",
L"http://latne.lv/favicon.ico",
L"http://latne.lv/siets.php?q={searchTerms}",
"UTF-8",
@@ -636,7 +636,7 @@ const PrepopulatedEngine latne = {
const PrepopulatedEngine leit = {
L"leit.is",
- NULL,
+ L"leit.is",
L"http://leit.is/leit.ico",
L"http://leit.is/query.aspx?qt={searchTerms}",
"ISO-8859-1",
@@ -749,7 +749,7 @@ const PrepopulatedEngine live_en_XA = {
};
const PrepopulatedEngine live_es_US = {
- L"Live Search (Espa" L"\x00f1" L"ol)",
+ L"Live Search (Espa\x00f1ol)",
L"", // "live.com" is already taken by live_en_US (see comment on ID below).
L"http://search.live.com/s/wlflag.ico",
L"http://search.live.com/results.aspx?setlang=es-US&mkt=es-US&"
@@ -911,7 +911,7 @@ const PrepopulatedEngine mail_ru = {
const PrepopulatedEngine maktoob = {
L"\x0645\x0643\x062a\x0648\x0628",
- NULL,
+ L"maktoob.com",
L"http://www.maktoob.com/favicon.ico",
L"http://www.maktoob.com/searchResult.php?q={searchTerms}",
"UTF-8",
@@ -921,7 +921,7 @@ const PrepopulatedEngine maktoob = {
const PrepopulatedEngine masrawy = {
L"\x0645\x0635\x0631\x0627\x0648\x064a",
- NULL,
+ L"masrawy.com",
L"http://www.masrawy.com/new/images/masrawy.ico",
L"http://masrawy.com/new/search.aspx?sr={searchTerms}",
"windows-1256",
@@ -931,7 +931,7 @@ const PrepopulatedEngine masrawy = {
const PrepopulatedEngine matkurja = {
L"Mat'Kurja",
- NULL,
+ L"matkurja.com",
L"http://matkurja.com/favicon.ico",
L"http://matkurja.com/si/iskalnik/?q={searchTerms}&search_source=directory",
"ISO-8859-2",
@@ -941,7 +941,7 @@ const PrepopulatedEngine matkurja = {
const PrepopulatedEngine meta = {
L"<META>",
- NULL,
+ L"meta.ua",
L"http://meta.ua/favicon.ico",
L"http://meta.ua/search.asp?q={searchTerms}",
"windows-1251",
@@ -983,7 +983,7 @@ const PrepopulatedEngine msn_da_DK = {
};
const PrepopulatedEngine msn_de_AT = {
- L"MSN " L"\x00f1" L"sterreich",
+ L"MSN \x00d6sterreich",
L"at.msn.com",
L"http://search.msn.at/s/wlflag.ico",
L"http://search.msn.at/results.aspx?mkt=de-AT&q={searchTerms}",
@@ -1145,7 +1145,7 @@ const PrepopulatedEngine msn_es_MX = {
};
const PrepopulatedEngine msn_es_XL = {
- L"MSN Latinoam" L"\x00e9" L"rica",
+ L"MSN Latinoam\x00e9rica",
L"latam.msn.com",
L"http://search.msn.com/s/wlflag.ico",
L"http://search.msn.com/results.aspx?mkt=es-XL&q={searchTerms}",
@@ -1282,7 +1282,7 @@ const PrepopulatedEngine msn_sv_SE = {
};
const PrepopulatedEngine msn_tr_TR = {
- L"MSN T" L"\x00fc" L"kiye'ye",
+ L"MSN T\x00fckiye'ye",
L"tr.msn.com",
L"http://search.msn.com.tr/s/wlflag.ico",
L"http://search.msn.com.tr/results.aspx?mkt=tr-TR&q={searchTerms}",
@@ -1334,7 +1334,7 @@ const PrepopulatedEngine mywebsearch = {
const PrepopulatedEngine najdi = {
L"Najdi.si",
- NULL,
+ L"najdi.si",
L"http://www.najdi.si/master/favicon.ico",
L"http://www.najdi.si/search.jsp?q={searchTerms}",
"UTF-8",
@@ -1375,7 +1375,7 @@ const PrepopulatedEngine naver = {
const PrepopulatedEngine neti = {
L"NETI",
- NULL,
+ L"neti.ee",
L"http://www.neti.ee/favicon.ico",
L"http://www.neti.ee/cgi-bin/otsing?query={searchTerms}",
"ISO-8859-1",
@@ -1385,7 +1385,7 @@ const PrepopulatedEngine neti = {
const PrepopulatedEngine netindex = {
L"NetINDEX",
- NULL,
+ L"netindex.pt",
L"http://www.netindex.pt/favicon.ico",
L"http://www.netindex.pt/cgi-bin/index.cgi?question={searchTerms}",
"ISO-8859-1",
@@ -1404,7 +1404,7 @@ const PrepopulatedEngine nifty = {
};
const PrepopulatedEngine ohperu = {
- L"Oh Per" L"\x00fa",
+ L"Oh Per\x00fa",
L"ohperu.com",
NULL,
L"http://www.google.com.pe/custom?q={searchTerms}&"
@@ -1421,7 +1421,7 @@ const PrepopulatedEngine ohperu = {
const PrepopulatedEngine ok = {
L"OK.hu",
- NULL,
+ L"ok.hu",
L"http://ok.hu/gfx/favicon.ico",
L"http://ok.hu/katalogus?q={searchTerms}",
"ISO-8859-2",
@@ -1451,7 +1451,7 @@ const PrepopulatedEngine orange = {
};
const PrepopulatedEngine ozu = {
- L"OZ" L"\x00da",
+ L"OZ\x00da",
L"ozu.es",
L"http://www.ozu.es/favicon.ico",
L"http://buscar.ozu.es/index.php?q={searchTerms}",
@@ -1462,7 +1462,7 @@ const PrepopulatedEngine ozu = {
const PrepopulatedEngine pogodak_ba = {
L"Pogodak!",
- NULL,
+ L"pogodak.ba",
L"http://www.pogodak.ba/favicon.ico",
L"http://www.pogodak.ba/search.jsp?q={searchTerms}",
"UTF-8",
@@ -1472,7 +1472,7 @@ const PrepopulatedEngine pogodak_ba = {
const PrepopulatedEngine pogodak_hr = {
L"Pogodak!",
- NULL,
+ L"pogodak.hr",
L"http://www.pogodak.hr/favicon.ico",
L"http://www.pogodak.hr/search.jsp?q={searchTerms}",
"UTF-8",
@@ -1482,7 +1482,7 @@ const PrepopulatedEngine pogodak_hr = {
const PrepopulatedEngine pogodak_rs = {
L"Pogodak!",
- NULL,
+ L"pogodak.rs",
L"http://www.pogodak.rs/favicon.ico",
L"http://www.pogodak.rs/search.jsp?q={searchTerms}",
"UTF-8",
@@ -1492,7 +1492,7 @@ const PrepopulatedEngine pogodak_rs = {
const PrepopulatedEngine pogodok = {
L"\x041f\x043e\x0433\x043e\x0434\x043e\x043a!",
- NULL,
+ L"pogodok.com.mk",
L"http://www.pogodok.com.mk/favicon.ico",
L"http://www.pogodok.com.mk/search.jsp?q={searchTerms}",
"UTF-8",
@@ -1502,7 +1502,7 @@ const PrepopulatedEngine pogodok = {
const PrepopulatedEngine rambler = {
L"Rambler",
- NULL,
+ L"rambler.ru",
L"http://www.rambler.ru/favicon.ico",
L"http://www.rambler.ru/srch?words={searchTerms}",
"windows-1251",
@@ -1522,7 +1522,7 @@ const PrepopulatedEngine rediff = {
const PrepopulatedEngine rednano = {
L"Rednano",
- NULL,
+ L"rednano.sg",
L"http://rednano.sg/favicon.ico",
L"http://rednano.sg/sfe/lwi.action?querystring={searchTerms}",
"UTF-8",
@@ -1552,7 +1552,7 @@ const PrepopulatedEngine sapo = {
const PrepopulatedEngine search_ch = {
L"search.ch",
- NULL,
+ L"search.ch",
L"http://www.search.ch/favicon.ico",
L"http://www.search.ch/?q={searchTerms}",
"ISO-8859-1",
@@ -1562,7 +1562,7 @@ const PrepopulatedEngine search_ch = {
const PrepopulatedEngine sensis = {
L"sensis.com.au",
- NULL,
+ L"sensis.com.au",
L"http://www.sensis.com.au/favicon.ico",
L"http://www.sensis.com.au/search.do?find={searchTerms}",
"UTF-8",
@@ -1572,7 +1572,7 @@ const PrepopulatedEngine sensis = {
const PrepopulatedEngine sesam = {
L"Sesam",
- NULL,
+ L"sesam.no",
L"http://sesam.no/images/favicon.gif",
L"http://sesam.no/search/?q={searchTerms}",
"UTF-8",
@@ -1593,7 +1593,7 @@ const PrepopulatedEngine seznam = {
const PrepopulatedEngine sogou = {
L"\x641c\x72d7",
- NULL,
+ L"sogou.com",
L"http://www.sogou.com/favicon.ico",
L"http://www.sogou.com/web?query={searchTerms}",
"GB2312",
@@ -1603,7 +1603,7 @@ const PrepopulatedEngine sogou = {
const PrepopulatedEngine soso = {
L"\x641c\x641c",
- NULL,
+ L"soso.com",
L"http://www.soso.com/favicon.ico",
L"http://www.soso.com/q?w={searchTerms}",
"GB2312",
@@ -1623,7 +1623,7 @@ const PrepopulatedEngine spray = {
const PrepopulatedEngine szm = {
L"SZM.sk",
- NULL,
+ L"szm.sk",
L"http://szm.sk/favicon.ico",
L"http://szm.sk/search/?co=1&q={searchTerms}",
"windows-1250",
@@ -1633,7 +1633,7 @@ const PrepopulatedEngine szm = {
const PrepopulatedEngine t_online = {
L"T-Online",
- NULL,
+ L"suche.t-online.de",
L"http://suche.t-online.de/favicon.ico",
L"http://suche.t-online.de/fast-cgi/tsc?q={searchTerms}",
"UTF-8",
@@ -1643,7 +1643,7 @@ const PrepopulatedEngine t_online = {
const PrepopulatedEngine tango = {
L"Tango",
- NULL,
+ L"tango.hu",
L"http://tango.hu/favicon.ico",
L"http://tango.hu/search.php?q={searchTerms}",
"windows-1250",
@@ -1653,7 +1653,7 @@ const PrepopulatedEngine tango = {
const PrepopulatedEngine tapuz = {
L"\x05ea\x05e4\x05d5\x05d6 \x05d0\x05e0\x05e9\x05d9\x05dd",
- NULL,
+ L"tapuz.co.il",
L"http://www.tapuz.co.il/favicon.ico",
L"http://www.tapuz.co.il/search/search.asp?q={searchTerms}",
"windows-1255",
@@ -1716,7 +1716,7 @@ const PrepopulatedEngine terra_pe = {
const PrepopulatedEngine toile = {
L"La Toile du Qu" L"\x00e9" L"bec",
- NULL,
+ L"toile.com",
L"http://static.search.canoe.ca/s-toile/img/favicon_toile.ico",
L"http://www.toile.com/search?q={searchTerms}",
"UTF-8",
@@ -1736,7 +1736,7 @@ const PrepopulatedEngine tut = {
const PrepopulatedEngine uol = {
L"UOL Busca",
- NULL,
+ L"busca.uol.com.br",
L"http://busca.uol.com.br/favicon.ico",
L"http://busca.uol.com.br/www/index.html?q={searchTerms}",
"ISO-8859-1",
@@ -1746,7 +1746,7 @@ const PrepopulatedEngine uol = {
const PrepopulatedEngine vinden = {
L"Vinden.nl",
- NULL,
+ L"vinden.nl",
L"http://www.vinden.nl/favicon.ico",
L"http://www.vinden.nl/?q={searchTerms}",
"UTF-8",
@@ -2037,7 +2037,7 @@ const PrepopulatedEngine yahoo_malaysia = {
};
const PrepopulatedEngine yahoo_mx = {
- L"Yahoo! M" L"\x00e9" L"xico",
+ L"Yahoo! M\x00e9xico",
L"mx.yahoo.com",
L"http://mx.search.yahoo.com/favicon.ico",
L"http://mx.search.yahoo.com/search?ei={inputEncoding}&p={searchTerms}",
@@ -2077,7 +2077,7 @@ const PrepopulatedEngine yahoo_nz = {
};
const PrepopulatedEngine yahoo_pe = {
- L"Yahoo! Per" L"\x00fa",
+ L"Yahoo! Per\x00fa",
L"pe.yahoo.com",
L"http://pe.search.yahoo.com/favicon.ico",
L"http://pe.search.yahoo.com/search?ei={inputEncoding}&p={searchTerms}",
@@ -2188,7 +2188,7 @@ const PrepopulatedEngine yam = {
const PrepopulatedEngine yamli = {
L"Yamli",
- NULL,
+ L"yamli.com",
L"http://www.yamli.com/favicon.ico",
L"http://www.yamli.com/#q={searchTerms}",
"UTF-8",
@@ -2198,7 +2198,7 @@ const PrepopulatedEngine yamli = {
const PrepopulatedEngine yandex_ru = {
L"\x042f\x043d\x0434\x0435\x043a\x0441",
- NULL,
+ L"yandex.ru",
L"http://yandex.ru/favicon.ico",
L"http://yandex.ru/yandsearch?text={searchTerms}",
"windows-1251",
@@ -2208,7 +2208,7 @@ const PrepopulatedEngine yandex_ru = {
const PrepopulatedEngine yandex_ua = {
L"\x042f\x043d\x0434\x0435\x043a\x0441",
- NULL,
+ L"yandex.ua",
L"http://yandex.ua/favicon.ico",
L"http://yandex.ua/yandsearch?text={searchTerms}",
"windows-1251",
@@ -2218,7 +2218,7 @@ const PrepopulatedEngine yandex_ua = {
const PrepopulatedEngine zoznam = {
L"Zoznam",
- NULL,
+ L"zoznam.sk",
L"http://zoznam.sk/favicon.ico",
L"http://zoznam.sk/hladaj.fcgi?s={searchTerms}",
"windows-1250",
@@ -2971,6 +2971,10 @@ void GetPrepopulatedEngines(PrefService* prefs,
if (engines[i].suggest_url)
new_turl->SetSuggestionsURL(engines[i].suggest_url, 0, 0);
new_turl->set_short_name(engines[i].name);
+ if (engines[i].keyword == NULL)
+ new_turl->set_autogenerate_keyword(true);
+ else
+ new_turl->set_keyword(engines[i].keyword);
new_turl->set_show_in_default_list(true);
new_turl->set_safe_for_autoreplace(true);
new_turl->set_date_created(Time());
@@ -2978,14 +2982,6 @@ void GetPrepopulatedEngines(PrefService* prefs,
turl_encodings.push_back(engines[i].encoding);
new_turl->set_input_encodings(turl_encodings);
new_turl->set_prepopulate_id(engines[i].id);
-
- // Set the keyword. We do this last so that if we need to generate a
- // keyword, the rest of the data is complete for GenerateSearchHost().
- new_turl->set_keyword(engines[i].keyword ? engines[i].keyword :
- TemplateURLModel::GenerateKeyword(
- TemplateURLModel::GenerateSearchURL(new_turl).GetWithEmptyPath(),
- true)); // autodetected
-
t_urls->push_back(new_turl);
}
}
diff --git a/chrome/browser/template_url_unittest.cc b/chrome/browser/template_url_unittest.cc
index 375ef40..2c574fb 100644
--- a/chrome/browser/template_url_unittest.cc
+++ b/chrome/browser/template_url_unittest.cc
@@ -365,4 +365,18 @@ TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {
for (int i = 0; i < arraysize(data); ++i)
CheckSuggestBaseURL(data[i].base_url, data[i].base_suggest_url);
-} \ No newline at end of file
+}
+
+TEST_F(TemplateURLTest, Keyword) {
+ TemplateURL t_url;
+ t_url.SetURL(L"http://www.google.com/search", 0, 0);
+ EXPECT_FALSE(t_url.autogenerate_keyword());
+ t_url.set_keyword(L"foo");
+ EXPECT_EQ(L"foo", t_url.keyword());
+ t_url.set_autogenerate_keyword(true);
+ EXPECT_TRUE(t_url.autogenerate_keyword());
+ EXPECT_EQ(L"google.com", t_url.keyword());
+ t_url.set_keyword(L"foo");
+ EXPECT_FALSE(t_url.autogenerate_keyword());
+ EXPECT_EQ(L"foo", t_url.keyword());
+}
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index 60b6b82..014452c 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -66,6 +66,7 @@
// encodings, may be empty.
// suggest_url
// prepopulate_id See TemplateURL::prepoulate_id.
+// autogenerate_keyword
//
// logins
// origin_url
@@ -98,7 +99,7 @@
////////////////////////////////////////////////////////////////////////////////
// Current version number.
-static const int kCurrentVersionNumber = 20;
+static const int kCurrentVersionNumber = 21;
// Keys used in the meta table.
static const char* kDefaultSearchProviderKey = "Default Search Provider ID";
@@ -185,14 +186,9 @@ bool WebDatabase::Init(const std::wstring& db_name) {
LOG(WARNING) << "Unable to initialize the web database.";
return false;
}
- int cur_version = meta_table_.GetVersionNumber();
- // Put migration code here.
-
- // When the version is too old, we just try to continue anyway, there should
- // not be a released product that makes a database too old for us to handle.
- LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
- "Web database version " << cur_version << " is too old to handle.";
+ // If the file on disk is an older database version, bring it up to date.
+ MigrateOldVersionsAsNeeded();
return (transaction.Commit() == SQLITE_OK);
}
@@ -305,7 +301,8 @@ bool WebDatabase::InitKeywordsTable() {
"usage_count INTEGER DEFAULT 0,"
"input_encodings VARCHAR,"
"suggest_url VARCHAR,"
- "prepopulate_id INTEGER DEFAULT 0)",
+ "prepopulate_id INTEGER DEFAULT 0,"
+ "autogenerate_keyword INTEGER DEFAULT 0)",
NULL, NULL, NULL) != SQLITE_OK) {
NOTREACHED();
return false;
@@ -432,6 +429,7 @@ static void BindURLToStatement(const TemplateURL& url, SQLStatement* s) {
else
s->bind_wstring(10, std::wstring());
s->bind_int(11, url.prepopulate_id());
+ s->bind_int(12, url.autogenerate_keyword() ? 1 : 0);
}
bool WebDatabase::AddKeyword(const TemplateURL& url) {
@@ -441,14 +439,15 @@ bool WebDatabase::AddKeyword(const TemplateURL& url) {
"INSERT INTO keywords "
"(short_name, keyword, favicon_url, url, safe_for_autoreplace, "
"originating_url, date_created, usage_count, input_encodings, "
- "show_in_default_list, suggest_url, prepopulate_id, id) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
+ "show_in_default_list, suggest_url, prepopulate_id, "
+ "autogenerate_keyword, id) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
!= SQLITE_OK) {
NOTREACHED() << "Statement prepare failed";
return false;
}
BindURLToStatement(url, &s);
- s.bind_int64(12, url.id());
+ s.bind_int64(13, url.id());
if (s.step() != SQLITE_DONE) {
NOTREACHED();
return false;
@@ -474,7 +473,7 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) {
"SELECT id, short_name, keyword, favicon_url, url, "
"safe_for_autoreplace, originating_url, date_created, "
"usage_count, input_encodings, show_in_default_list, "
- "suggest_url, prepopulate_id "
+ "suggest_url, prepopulate_id, autogenerate_keyword "
"FROM keywords ORDER BY id ASC") != SQLITE_OK) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -520,6 +519,8 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) {
template_url->set_prepopulate_id(s.column_int(12));
+ template_url->set_autogenerate_keyword(s.column_int(13) == 1);
+
urls->push_back(template_url);
}
return result == SQLITE_DONE;
@@ -530,17 +531,17 @@ bool WebDatabase::UpdateKeyword(const TemplateURL& url) {
SQLStatement s;
if (s.prepare(db_,
"UPDATE keywords "
- "SET short_name=?, keyword=?, favicon_url=?, url=?,"
- "safe_for_autoreplace=?, originating_url=?, "
- "date_created=?, usage_count=?, input_encodings=?, "
- "show_in_default_list=?, suggest_url=?, prepopulate_id=? "
+ "SET short_name=?, keyword=?, favicon_url=?, url=?, "
+ "safe_for_autoreplace=?, originating_url=?, date_created=?, "
+ "usage_count=?, input_encodings=?, show_in_default_list=?, "
+ "suggest_url=?, prepopulate_id=?, autogenerate_keyword=? "
"WHERE id=?")
!= SQLITE_OK) {
NOTREACHED() << "Statement prepare failed";
return false;
}
BindURLToStatement(url, &s);
- s.bind_int64(12, url.id());
+ s.bind_int64(13, url.id());
return s.step() == SQLITE_DONE;
}
@@ -871,3 +872,39 @@ bool WebDatabase::GetAllLogins(std::vector<PasswordForm*>* forms,
}
return result == SQLITE_DONE;
}
+
+void WebDatabase::MigrateOldVersionsAsNeeded() {
+ // Migrate if necessary.
+ int current_version = meta_table_.GetVersionNumber();
+ switch(current_version) {
+ // Versions 1 - 19 are unhandled. Version numbers greater than
+ // kCurrentVersionNumber should have already been weeded out by the caller.
+ default:
+ // When the version is too old, we just try to continue anyway. There
+ // should not be a released product that makes a database too old for us
+ // to handle.
+ LOG(WARNING) << "Web database version " << current_version <<
+ " is too old to handle.";
+ return;
+
+ case 20:
+ // Add the autogenerate_keyword column.
+ if (sqlite3_exec(db_,
+ "ALTER TABLE keywords ADD COLUMN autogenerate_keyword "
+ "INTEGER DEFAULT 0", NULL, NULL, NULL) != SQLITE_OK) {
+ NOTREACHED();
+ return;
+ }
+ ++current_version;
+ meta_table_.SetVersionNumber(current_version);
+ meta_table_.SetCompatibleVersionNumber(current_version);
+
+ // Add successive versions here. Each should set the version number and
+ // compatible version number as appropriate, then fall through to the next
+ // case.
+
+ case kCurrentVersionNumber:
+ // No migration needed.
+ return;
+ }
+}
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index f34d570..a9027cc 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -157,6 +157,8 @@ class WebDatabase {
bool InitWebAppIconsTable();
bool InitWebAppsTable();
+ void MigrateOldVersionsAsNeeded();
+
sqlite3* db_;
int transaction_nesting_;
MetaTableHelper meta_table_;
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index fd68974..4e62e0f 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -115,10 +115,10 @@ TEST_F(WebDatabaseTest, Keywords) {
TemplateURL template_url;
template_url.set_short_name(L"short_name");
template_url.set_keyword(L"keyword");
- GURL favicon_url("http://favicon.url");
- GURL originating_url("http://google.com");
+ GURL favicon_url("http://favicon.url/");
+ GURL originating_url("http://google.com/");
template_url.SetFavIconURL(favicon_url);
- template_url.SetURL(L"url", 0, 0);
+ template_url.SetURL(L"http://url/", 0, 0);
template_url.set_safe_for_autoreplace(true);
template_url.set_show_in_default_list(true);
template_url.set_originating_url(originating_url);
@@ -139,6 +139,8 @@ TEST_F(WebDatabaseTest, Keywords) {
EXPECT_EQ(template_url.keyword(), restored_url->keyword());
+ EXPECT_FALSE(restored_url->autogenerate_keyword());
+
EXPECT_TRUE(favicon_url == restored_url->GetFavIconURL());
EXPECT_TRUE(restored_url->safe_for_autoreplace());
@@ -189,10 +191,10 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
TemplateURL template_url;
template_url.set_short_name(L"short_name");
template_url.set_keyword(L"keyword");
- GURL favicon_url("http://favicon.url");
- GURL originating_url("http://originating.url");
+ GURL favicon_url("http://favicon.url/");
+ GURL originating_url("http://originating.url/");
template_url.SetFavIconURL(favicon_url);
- template_url.SetURL(L"url", 0, 0);
+ template_url.SetURL(L"http://url/", 0, 0);
template_url.set_safe_for_autoreplace(true);
template_url.set_show_in_default_list(true);
template_url.SetSuggestionsURL(L"url2", 0, 0);
@@ -200,9 +202,10 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
EXPECT_TRUE(db.AddKeyword(template_url));
- GURL originating_url2("http://originating.url");
- template_url.set_keyword(L"X");
+ GURL originating_url2("http://originating.url/");
template_url.set_originating_url(originating_url2);
+ template_url.set_autogenerate_keyword(true);
+ EXPECT_EQ(L"url", template_url.keyword());
template_url.add_input_encoding("Shift_JIS");
set_prepopulate_id(&template_url, 5);
EXPECT_TRUE(db.UpdateKeyword(template_url));
@@ -217,6 +220,8 @@ TEST_F(WebDatabaseTest, UpdateKeyword) {
EXPECT_EQ(template_url.keyword(), restored_url->keyword());
+ EXPECT_TRUE(restored_url->autogenerate_keyword());
+
EXPECT_TRUE(favicon_url == restored_url->GetFavIconURL());
EXPECT_TRUE(restored_url->safe_for_autoreplace());
@@ -248,7 +253,7 @@ TEST_F(WebDatabaseTest, KeywordWithNoFavicon) {
TemplateURL template_url;
template_url.set_short_name(L"short_name");
template_url.set_keyword(L"keyword");
- template_url.SetURL(L"url", 0, 0);
+ template_url.SetURL(L"http://url/", 0, 0);
template_url.set_safe_for_autoreplace(true);
SetID(-100, &template_url);
@@ -287,7 +292,7 @@ TEST_F(WebDatabaseTest, Logins) {
form.password_element = L"Passwd";
form.password_value = L"test";
form.submit_element = L"signIn";
- form.signon_realm = "http://www.google.com";
+ form.signon_realm = "http://www.google.com/";
form.ssl_valid = false;
form.preferred = false;
form.scheme = PasswordForm::SCHEME_HTML;
@@ -328,7 +333,7 @@ TEST_F(WebDatabaseTest, Logins) {
// Imagine the site moves to a secure server for login.
PasswordForm form4(form3);
- form4.signon_realm = "https://www.google.com";
+ form4.signon_realm = "https://www.google.com/";
form4.ssl_valid = true;
// We have only an http record, so no match for this.
@@ -480,7 +485,7 @@ TEST_F(WebDatabaseTest, BlacklistedLogins) {
form.username_element = L"Email";
form.password_element = L"Passwd";
form.submit_element = L"signIn";
- form.signon_realm = "http://www.google.com";
+ form.signon_realm = "http://www.google.com/";
form.ssl_valid = false;
form.preferred = true;
form.blacklisted_by_user = true;
@@ -506,7 +511,7 @@ TEST_F(WebDatabaseTest, WebAppHasAllImages) {
WebDatabase db;
EXPECT_TRUE(db.Init(file_));
- GURL url("http://google.com");
+ GURL url("http://google.com/");
// Initial value for unknown web app should be false.
EXPECT_FALSE(db.GetWebAppHasAllImages(url));
@@ -524,7 +529,7 @@ TEST_F(WebDatabaseTest, WebAppImages) {
WebDatabase db;
ASSERT_TRUE(db.Init(file_));
- GURL url("http://google.com");
+ GURL url("http://google.com/");
// Web app should initially have no images.
std::vector<SkBitmap> images;