diff options
author | pkasting@google.com <pkasting@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-01 17:38:56 +0000 |
---|---|---|
committer | pkasting@google.com <pkasting@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-01 17:38:56 +0000 |
commit | fab288ae66e4e45b792d929aa44210fd8104f5e7 (patch) | |
tree | b737518357c503bce66334bcc59309cdcc4e509c /chrome/browser/webdata | |
parent | 1fcb8b01fe855dde2485b82d620cdaecb580a3bd (diff) | |
download | chromium_src-fab288ae66e4e45b792d929aa44210fd8104f5e7.zip chromium_src-fab288ae66e4e45b792d929aa44210fd8104f5e7.tar.gz chromium_src-fab288ae66e4e45b792d929aa44210fd8104f5e7.tar.bz2 |
Add the ability to dynamically generate keywords. Mark the Google engine as needing this. This ensures that users in countries where the Google base URL is not "google.com" will see the appropriate keyword for their local country (and can trigger it for tab-to-search, etc.).
BUG=1301290
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r-- | chrome/browser/webdata/web_database.cc | 73 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.h | 2 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 33 |
3 files changed, 76 insertions, 32 deletions
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; |