summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-12 22:24:08 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-12 22:24:08 +0000
commitad52b7715044472763c00e807f7c293ae97380ff (patch)
treeeea088fc1bbeec7b357450a3e499c57462a0a9de
parentf830f3d4ae0191c9095949096e9c3ca1f6dc8d12 (diff)
downloadchromium_src-ad52b7715044472763c00e807f7c293ae97380ff.zip
chromium_src-ad52b7715044472763c00e807f7c293ae97380ff.tar.gz
chromium_src-ad52b7715044472763c00e807f7c293ae97380ff.tar.bz2
Generalize migration code in WebDatabase.
This is part of removing knowledge of individual table types from WebDatabase, which is part of splitting WebData into several components (one component for generic bits like WebDatabase and whatever we end up calling the base class for all XyzWebData classes, e.g. AutofillWebData, plus one component per data type). BUG=181277 Review URL: https://chromiumcodereview.appspot.com/12518017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187663 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/webdata/autofill_table.cc46
-rw-r--r--chrome/browser/webdata/autofill_table.h3
-rw-r--r--chrome/browser/webdata/keyword_table.cc46
-rw-r--r--chrome/browser/webdata/keyword_table.h3
-rw-r--r--chrome/browser/webdata/logins_table.cc6
-rw-r--r--chrome/browser/webdata/logins_table.h3
-rw-r--r--chrome/browser/webdata/token_service_table.cc6
-rw-r--r--chrome/browser/webdata/token_service_table.h3
-rw-r--r--chrome/browser/webdata/web_apps_table.cc6
-rw-r--r--chrome/browser/webdata/web_apps_table.h3
-rw-r--r--chrome/browser/webdata/web_database.cc284
-rw-r--r--chrome/browser/webdata/web_database.h21
-rw-r--r--chrome/browser/webdata/web_database_table.h16
-rw-r--r--chrome/browser/webdata/web_intents_table.cc11
-rw-r--r--chrome/browser/webdata/web_intents_table.h3
15 files changed, 233 insertions, 227 deletions
diff --git a/chrome/browser/webdata/autofill_table.cc b/chrome/browser/webdata/autofill_table.cc
index 279ecfc..734c28a 100644
--- a/chrome/browser/webdata/autofill_table.cc
+++ b/chrome/browser/webdata/autofill_table.cc
@@ -342,6 +342,52 @@ bool AutofillTable::IsSyncable() {
return true;
}
+bool AutofillTable::MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) {
+ // Migrate if necessary.
+ switch (version) {
+ case 22:
+ return ClearAutofillEmptyValueElements();
+ case 23:
+ return MigrateToVersion23AddCardNumberEncryptedColumn();
+ case 24:
+ return MigrateToVersion24CleanupOversizedStringFields();
+ case 27:
+ *update_compatible_version = true;
+ return MigrateToVersion27UpdateLegacyCreditCards();
+ case 30:
+ *update_compatible_version = true;
+ return MigrateToVersion30AddDateModifed();
+ case 31:
+ *update_compatible_version = true;
+ return MigrateToVersion31AddGUIDToCreditCardsAndProfiles();
+ case 32:
+ *update_compatible_version = true;
+ return MigrateToVersion32UpdateProfilesAndCreditCards();
+ case 33:
+ *update_compatible_version = true;
+ return MigrateToVersion33ProfilesBasedOnFirstName();
+ case 34:
+ *update_compatible_version = true;
+ return MigrateToVersion34ProfilesBasedOnCountryCode(app_locale);
+ case 35:
+ *update_compatible_version = true;
+ return MigrateToVersion35GreatBritainCountryCodes();
+ // Combine migrations 36 and 37. This is due to enhancements to the merge
+ // step when migrating profiles. The original migration from 35 to 36 did
+ // not merge profiles with identical addresses, but the migration from 36 to
+ // 37 does. The step from 35 to 36 should only happen on the Chrome 12 dev
+ // channel. Chrome 12 beta and release users will jump from 35 to 37
+ // directly getting the full benefits of the multi-valued merge as well as
+ // the culling of bad data.
+ case 37:
+ *update_compatible_version = true;
+ return MigrateToVersion37MergeAndCullOlderProfiles();
+ }
+ return true;
+}
+
bool AutofillTable::AddFormFieldValues(
const std::vector<FormFieldData>& elements,
std::vector<AutofillChange>* changes) {
diff --git a/chrome/browser/webdata/autofill_table.h b/chrome/browser/webdata/autofill_table.h
index 3c8af5c..c0a076c 100644
--- a/chrome/browser/webdata/autofill_table.h
+++ b/chrome/browser/webdata/autofill_table.h
@@ -118,6 +118,9 @@ class AutofillTable : public WebDatabaseTable {
virtual ~AutofillTable();
virtual bool Init() OVERRIDE;
virtual bool IsSyncable() OVERRIDE;
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) OVERRIDE;
// Records the form elements in |elements| in the database in the
// autofill table. A list of all added and updated autofill entries
diff --git a/chrome/browser/webdata/keyword_table.cc b/chrome/browser/webdata/keyword_table.cc
index 53e15dd..15fba41 100644
--- a/chrome/browser/webdata/keyword_table.cc
+++ b/chrome/browser/webdata/keyword_table.cc
@@ -152,6 +152,52 @@ bool KeywordTable::IsSyncable() {
return true;
}
+bool KeywordTable::MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) {
+ // Migrate if necessary.
+ switch (version) {
+ case 21:
+ *update_compatible_version = true;
+ return MigrateToVersion21AutoGenerateKeywordColumn();
+ case 25:
+ *update_compatible_version = true;
+ return MigrateToVersion25AddLogoIDColumn();
+ case 26:
+ *update_compatible_version = true;
+ return MigrateToVersion26AddCreatedByPolicyColumn();
+ case 28:
+ *update_compatible_version = true;
+ return MigrateToVersion28SupportsInstantColumn();
+ case 29:
+ *update_compatible_version = true;
+ return MigrateToVersion29InstantURLToSupportsInstant();
+ case 38:
+ *update_compatible_version = true;
+ return MigrateToVersion38AddLastModifiedColumn();
+ case 39:
+ *update_compatible_version = true;
+ return MigrateToVersion39AddSyncGUIDColumn();
+ case 44:
+ *update_compatible_version = true;
+ return MigrateToVersion44AddDefaultSearchProviderBackup();
+ case 45:
+ *update_compatible_version = true;
+ return MigrateToVersion45RemoveLogoIDAndAutogenerateColumns();
+ case 47:
+ *update_compatible_version = true;
+ return MigrateToVersion47AddAlternateURLsColumn();
+ case 48:
+ *update_compatible_version = true;
+ return MigrateToVersion48RemoveKeywordsBackup();
+ case 49:
+ *update_compatible_version = true;
+ return MigrateToVersion49AddSearchTermsReplacementKeyColumn();
+ }
+
+ return true;
+}
+
bool KeywordTable::AddKeyword(const TemplateURLData& data) {
DCHECK(data.id);
std::string query("INSERT INTO keywords (" + GetKeywordColumns() +
diff --git a/chrome/browser/webdata/keyword_table.h b/chrome/browser/webdata/keyword_table.h
index 32a5c94..4e3eb9c 100644
--- a/chrome/browser/webdata/keyword_table.h
+++ b/chrome/browser/webdata/keyword_table.h
@@ -75,6 +75,9 @@ class KeywordTable : public WebDatabaseTable {
virtual ~KeywordTable();
virtual bool Init() OVERRIDE;
virtual bool IsSyncable() OVERRIDE;
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) OVERRIDE;
// Adds a new keyword, updating the id field on success.
// Returns true if successful.
diff --git a/chrome/browser/webdata/logins_table.cc b/chrome/browser/webdata/logins_table.cc
index fe7025e..35a1be2 100644
--- a/chrome/browser/webdata/logins_table.cc
+++ b/chrome/browser/webdata/logins_table.cc
@@ -41,3 +41,9 @@ bool LoginsTable::Init() {
bool LoginsTable::IsSyncable() {
return true;
}
+
+bool LoginsTable::MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) {
+ return true;
+}
diff --git a/chrome/browser/webdata/logins_table.h b/chrome/browser/webdata/logins_table.h
index 2ea63ed..eece326 100644
--- a/chrome/browser/webdata/logins_table.h
+++ b/chrome/browser/webdata/logins_table.h
@@ -25,6 +25,9 @@ class LoginsTable : public WebDatabaseTable {
virtual ~LoginsTable() {}
virtual bool Init() OVERRIDE;
virtual bool IsSyncable() OVERRIDE;
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) OVERRIDE;
#if defined(OS_WIN)
// Adds |info| to the list of imported passwords from ie7/ie8.
diff --git a/chrome/browser/webdata/token_service_table.cc b/chrome/browser/webdata/token_service_table.cc
index 14857c8..df8f1f1 100644
--- a/chrome/browser/webdata/token_service_table.cc
+++ b/chrome/browser/webdata/token_service_table.cc
@@ -27,6 +27,12 @@ bool TokenServiceTable::IsSyncable() {
return true;
}
+bool TokenServiceTable::MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) {
+ return true;
+}
+
bool TokenServiceTable::RemoveAllTokens() {
sql::Statement s(db_->GetUniqueStatement(
"DELETE FROM token_service"));
diff --git a/chrome/browser/webdata/token_service_table.h b/chrome/browser/webdata/token_service_table.h
index f2cd8e9..775ad9b 100644
--- a/chrome/browser/webdata/token_service_table.h
+++ b/chrome/browser/webdata/token_service_table.h
@@ -18,6 +18,9 @@ class TokenServiceTable : public WebDatabaseTable {
virtual ~TokenServiceTable() {}
virtual bool Init() OVERRIDE;
virtual bool IsSyncable() OVERRIDE;
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) OVERRIDE;
// Remove all tokens previously set with SetTokenForService.
bool RemoveAllTokens();
diff --git a/chrome/browser/webdata/web_apps_table.cc b/chrome/browser/webdata/web_apps_table.cc
index a503925..927b934 100644
--- a/chrome/browser/webdata/web_apps_table.cc
+++ b/chrome/browser/webdata/web_apps_table.cc
@@ -19,6 +19,12 @@ bool WebAppsTable::IsSyncable() {
return true;
}
+bool WebAppsTable::MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) {
+ return true;
+}
+
bool WebAppsTable::InitWebAppIconsTable() {
if (!db_->DoesTableExist("web_app_icons")) {
if (!db_->Execute("CREATE TABLE web_app_icons ("
diff --git a/chrome/browser/webdata/web_apps_table.h b/chrome/browser/webdata/web_apps_table.h
index 763ecd2..82ebda3 100644
--- a/chrome/browser/webdata/web_apps_table.h
+++ b/chrome/browser/webdata/web_apps_table.h
@@ -35,6 +35,9 @@ class WebAppsTable : public WebDatabaseTable {
virtual ~WebAppsTable() {}
virtual bool Init() OVERRIDE;
virtual bool IsSyncable() OVERRIDE;
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) OVERRIDE;
bool SetWebAppImage(const GURL& url, const SkBitmap& image);
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index c0111ed..9cb7f23 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -62,23 +62,23 @@ void WebDatabase::CommitTransaction() {
}
AutofillTable* WebDatabase::GetAutofillTable() {
- return autofill_table_.get();
+ return autofill_table_;
}
KeywordTable* WebDatabase::GetKeywordTable() {
- return keyword_table_.get();
+ return keyword_table_;
}
LoginsTable* WebDatabase::GetLoginsTable() {
- return logins_table_.get();
+ return logins_table_;
}
TokenServiceTable* WebDatabase::GetTokenServiceTable() {
- return token_service_table_.get();
+ return token_service_table_;
}
WebAppsTable* WebDatabase::GetWebAppsTable() {
- return web_apps_table_.get();
+ return web_apps_table_;
}
sql::Connection* WebDatabase::GetSQLConnection() {
@@ -123,23 +123,39 @@ sql::InitStatus WebDatabase::Init(const base::FilePath& db_name,
return sql::INIT_TOO_NEW;
}
+ // TODO(joi): Table creation should move out of this class; switch
+ // to a two-phase init to accomplish this.
+
// Create the tables.
- autofill_table_.reset(new AutofillTable(&db_, &meta_table_));
- keyword_table_.reset(new KeywordTable(&db_, &meta_table_));
+ autofill_table_ = new AutofillTable(&db_, &meta_table_);
+ tables_.push_back(autofill_table_);
+
+ keyword_table_ = new KeywordTable(&db_, &meta_table_);
+ tables_.push_back(keyword_table_);
+
// TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
// access, but for now, we still create it on all platforms since it deletes
// the old logins table. We can remove this after a while, e.g. in M22 or so.
- logins_table_.reset(new LoginsTable(&db_, &meta_table_));
- token_service_table_.reset(new TokenServiceTable(&db_, &meta_table_));
- web_apps_table_.reset(new WebAppsTable(&db_, &meta_table_));
- web_intents_table_.reset(new WebIntentsTable(&db_, &meta_table_));
+ logins_table_ = new LoginsTable(&db_, &meta_table_);
+ tables_.push_back(logins_table_);
+
+ token_service_table_ = new TokenServiceTable(&db_, &meta_table_);
+ tables_.push_back(token_service_table_);
+
+ web_apps_table_ = new WebAppsTable(&db_, &meta_table_);
+ tables_.push_back(web_apps_table_);
+
+ web_intents_table_ = new WebIntentsTable(&db_, &meta_table_);
+ tables_.push_back(web_intents_table_);
// Initialize the tables.
- if (!keyword_table_->Init() || !autofill_table_->Init() ||
- !logins_table_->Init() || !web_apps_table_->Init() ||
- !token_service_table_->Init() || !web_intents_table_->Init()) {
- LOG(WARNING) << "Unable to initialize the web database.";
- return sql::INIT_FAILURE;
+ for (ScopedVector<WebDatabaseTable>::iterator it = tables_.begin();
+ it != tables_.end();
+ ++it) {
+ if (!(*it)->Init()) {
+ LOG(WARNING) << "Unable to initialize the web database.";
+ return sql::INIT_FAILURE;
+ }
}
// If the file on disk is an older database version, bring it up to date.
@@ -162,212 +178,40 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(
if (current_version > meta_table_.GetVersionNumber())
ChangeVersion(&meta_table_, current_version, false);
- // Migrate if necessary.
- switch (current_version) {
+ if (current_version < 20) {
// 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 return failure error code. The schema
- // is too out of date to migrate.
- // There should not be a released product that makes a database too old to
- // migrate. If we do encounter such a legacy database, we will need a
- // better solution to handle it (i.e., pop up a dialog to tell the user,
- // erase all their prefs and start over, etc.).
- LOG(WARNING) << "Web database version " << current_version <<
- " is too old to handle.";
- NOTREACHED();
- return sql::INIT_FAILURE;
-
- case 20:
- if (!keyword_table_->MigrateToVersion21AutoGenerateKeywordColumn())
- return FailedMigrationTo(21);
-
- ChangeVersion(&meta_table_, 21, true);
- // FALL THROUGH
-
- case 21:
- if (!autofill_table_->ClearAutofillEmptyValueElements())
- return FailedMigrationTo(22);
-
- ChangeVersion(&meta_table_, 22, false);
- // FALL THROUGH
-
- case 22:
- if (!autofill_table_->MigrateToVersion23AddCardNumberEncryptedColumn())
- return FailedMigrationTo(23);
-
- ChangeVersion(&meta_table_, 23, false);
- // FALL THROUGH
-
- case 23:
- if (!autofill_table_->MigrateToVersion24CleanupOversizedStringFields())
- return FailedMigrationTo(24);
-
- ChangeVersion(&meta_table_, 24, false);
- // FALL THROUGH
-
- case 24:
- if (!keyword_table_->MigrateToVersion25AddLogoIDColumn())
- return FailedMigrationTo(25);
-
- ChangeVersion(&meta_table_, 25, true);
- // FALL THROUGH
-
- case 25:
- if (!keyword_table_->MigrateToVersion26AddCreatedByPolicyColumn())
- return FailedMigrationTo(26);
-
- ChangeVersion(&meta_table_, 26, true);
- // FALL THROUGH
-
- case 26:
- if (!autofill_table_->MigrateToVersion27UpdateLegacyCreditCards())
- return FailedMigrationTo(27);
-
- ChangeVersion(&meta_table_, 27, true);
- // FALL THROUGH
-
- case 27:
- if (!keyword_table_->MigrateToVersion28SupportsInstantColumn())
- return FailedMigrationTo(28);
-
- ChangeVersion(&meta_table_, 28, true);
- // FALL THROUGH
-
- case 28:
- if (!keyword_table_->MigrateToVersion29InstantURLToSupportsInstant())
- return FailedMigrationTo(29);
-
- ChangeVersion(&meta_table_, 29, true);
- // FALL THROUGH
-
- case 29:
- if (!autofill_table_->MigrateToVersion30AddDateModifed())
- return FailedMigrationTo(30);
-
- ChangeVersion(&meta_table_, 30, true);
- // FALL THROUGH
-
- case 30:
- if (!autofill_table_->MigrateToVersion31AddGUIDToCreditCardsAndProfiles())
- return FailedMigrationTo(31);
-
- ChangeVersion(&meta_table_, 31, true);
- // FALL THROUGH
-
- case 31:
- if (!autofill_table_->MigrateToVersion32UpdateProfilesAndCreditCards())
- return FailedMigrationTo(32);
-
- ChangeVersion(&meta_table_, 32, true);
- // FALL THROUGH
-
- case 32:
- if (!autofill_table_->MigrateToVersion33ProfilesBasedOnFirstName())
- return FailedMigrationTo(33);
-
- ChangeVersion(&meta_table_, 33, true);
- // FALL THROUGH
-
- case 33:
- if (!autofill_table_->MigrateToVersion34ProfilesBasedOnCountryCode(
- app_locale))
- return FailedMigrationTo(34);
-
- ChangeVersion(&meta_table_, 34, true);
- // FALL THROUGH
-
- case 34:
- if (!autofill_table_->MigrateToVersion35GreatBritainCountryCodes())
- return FailedMigrationTo(35);
-
- ChangeVersion(&meta_table_, 35, true);
- // FALL THROUGH
-
- // Combine migrations 35 and 36. This is due to enhancements to the merge
- // step when migrating profiles. The original migration from 35 to 36 did
- // not merge profiles with identical addresses, but the migration from 36 to
- // 37 does. The step from 35 to 36 should only happen on the Chrome 12 dev
- // channel. Chrome 12 beta and release users will jump from 35 to 37
- // directly getting the full benefits of the multi-valued merge as well as
- // the culling of bad data.
- case 35:
- case 36:
- if (!autofill_table_->MigrateToVersion37MergeAndCullOlderProfiles())
- return FailedMigrationTo(37);
-
- ChangeVersion(&meta_table_, 37, true);
- // FALL THROUGH
-
- case 37:
- if (!keyword_table_->MigrateToVersion38AddLastModifiedColumn())
- return FailedMigrationTo(38);
-
- ChangeVersion(&meta_table_, 38, true);
- // FALL THROUGH
-
- case 38:
- if (!keyword_table_->MigrateToVersion39AddSyncGUIDColumn())
- return FailedMigrationTo(39);
-
- ChangeVersion(&meta_table_, 39, true);
- // FALL THROUGH
-
- // Subsequent search engine backup migrations are merged into a single one.
- case 39:
- case 40:
- case 41:
- case 42:
- case 43:
- if (!keyword_table_->MigrateToVersion44AddDefaultSearchProviderBackup())
- return FailedMigrationTo(44);
-
- ChangeVersion(&meta_table_, 44, true);
- // FALL THROUGH
-
- case 44:
- if (!keyword_table_->
- MigrateToVersion45RemoveLogoIDAndAutogenerateColumns())
- return FailedMigrationTo(45);
-
- ChangeVersion(&meta_table_, 45, true);
- // FALL THROUGH
-
- case 45:
- if (!web_intents_table_->MigrateToVersion46AddSchemeColumn())
- return FailedMigrationTo(46);
-
- ChangeVersion(&meta_table_, 46, true);
- // FALL THROUGH
-
- case 46:
- if (!keyword_table_->MigrateToVersion47AddAlternateURLsColumn())
- return FailedMigrationTo(47);
-
- ChangeVersion(&meta_table_, 47, true);
- // FALL THROUGH
-
- case 47:
- if (!keyword_table_->MigrateToVersion48RemoveKeywordsBackup())
- return FailedMigrationTo(48);
-
- ChangeVersion(&meta_table_, 48, true);
- // FALL THROUGH
-
- case 48:
- if (!keyword_table_->
- MigrateToVersion49AddSearchTermsReplacementKeyColumn())
- return FailedMigrationTo(49);
+ //
+ // When the version is too old, we return failure error code. The schema
+ // is too out of date to migrate.
+ //
+ // There should not be a released product that makes a database too old to
+ // migrate. If we do encounter such a legacy database, we will need a
+ // better solution to handle it (i.e., pop up a dialog to tell the user,
+ // erase all their prefs and start over, etc.).
+ LOG(WARNING) << "Web database version " << current_version <<
+ " is too old to handle.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
- ChangeVersion(&meta_table_, 49, true);
- // FALL THROUGH
-
- // 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 sql::INIT_OK;
+ for (int next_version = current_version + 1;
+ next_version <= kCurrentVersionNumber;
+ ++next_version) {
+ // Give each table a chance to migrate to this version.
+ for (ScopedVector<WebDatabaseTable>::iterator it = tables_.begin();
+ it != tables_.end();
+ ++it) {
+ // Any of the tables may set this to true, but by default it is false.
+ bool update_compatible_version = false;
+ if (!(*it)->MigrateToVersion(next_version,
+ app_locale,
+ &update_compatible_version)) {
+ return FailedMigrationTo(next_version);
+ }
+
+ ChangeVersion(&meta_table_, next_version, update_compatible_version);
+ }
}
+ return sql::INIT_OK;
}
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index 5fdb607..3b47d2a 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
#include "sql/connection.h"
#include "sql/init_status.h"
#include "sql/meta_table.h"
@@ -15,6 +16,7 @@ class KeywordTable;
class LoginsTable;
class TokenServiceTable;
class WebAppsTable;
+class WebDatabaseTable;
class WebIntentsTable;
namespace base {
@@ -67,13 +69,20 @@ class WebDatabase {
sql::Connection db_;
sql::MetaTable meta_table_;
- scoped_ptr<AutofillTable> autofill_table_;
- scoped_ptr<KeywordTable> keyword_table_;
- scoped_ptr<LoginsTable> logins_table_;
- scoped_ptr<TokenServiceTable> token_service_table_;
- scoped_ptr<WebAppsTable> web_apps_table_;
+ // TODO(joi): All of the typed pointers are going in a future
+ // change, as we remove knowledge of the specific types from this
+ // class.
+ AutofillTable* autofill_table_;
+ KeywordTable* keyword_table_;
+ LoginsTable* logins_table_;
+ TokenServiceTable* token_service_table_;
+ WebAppsTable* web_apps_table_;
// TODO(thakis): Add a migration to delete this table, then remove this.
- scoped_ptr<WebIntentsTable> web_intents_table_;
+ WebIntentsTable* web_intents_table_;
+
+ // Owns all the different database tables that have been added to
+ // this object.
+ ScopedVector<WebDatabaseTable> tables_;
scoped_ptr<content::NotificationService> notification_service_;
diff --git a/chrome/browser/webdata/web_database_table.h b/chrome/browser/webdata/web_database_table.h
index a1b875d..7622695 100644
--- a/chrome/browser/webdata/web_database_table.h
+++ b/chrome/browser/webdata/web_database_table.h
@@ -15,7 +15,7 @@ class MetaTable;
// An abstract base class representing a table within a WebDatabase.
// Each table should subclass this, adding type-specific methods as needed.
class WebDatabaseTable {
- protected:
+ public:
WebDatabaseTable(sql::Connection* db, sql::MetaTable* meta_table);
virtual ~WebDatabaseTable();
@@ -29,6 +29,20 @@ class WebDatabaseTable {
// TODO(andybons): Implement something more robust.
virtual bool IsSyncable() = 0;
+ // Migrates this table to |version|. Returns false if there was
+ // migration work to do and it failed, true otherwise.
+ //
+ // |app_locale| is the locale of the app. Passed as a parameter as
+ // |it can only be safely queried on the UI thread.
+ //
+ // Implementations may set |*update_compatible_version| to true if
+ // the compatible version should be changed to |version|.
+ // Implementations should otherwise not modify this parameter.
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) = 0;
+
+ protected:
sql::Connection* db_;
sql::MetaTable* meta_table_;
diff --git a/chrome/browser/webdata/web_intents_table.cc b/chrome/browser/webdata/web_intents_table.cc
index b7f9ecd..3650c95 100644
--- a/chrome/browser/webdata/web_intents_table.cc
+++ b/chrome/browser/webdata/web_intents_table.cc
@@ -71,6 +71,17 @@ bool WebIntentsTable::IsSyncable() {
return false;
}
+bool WebIntentsTable::MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) {
+ if (version == 46) {
+ *update_compatible_version = true;
+ return MigrateToVersion46AddSchemeColumn();
+ }
+
+ return true;
+}
+
// Updates the table by way of renaming the old tables, rerunning
// the Init method, then selecting old values into the new tables.
bool WebIntentsTable::MigrateToVersion46AddSchemeColumn() {
diff --git a/chrome/browser/webdata/web_intents_table.h b/chrome/browser/webdata/web_intents_table.h
index 844de55..0064341 100644
--- a/chrome/browser/webdata/web_intents_table.h
+++ b/chrome/browser/webdata/web_intents_table.h
@@ -56,6 +56,9 @@ class WebIntentsTable : public WebDatabaseTable {
// WebDatabaseTable implementation.
virtual bool Init() OVERRIDE;
virtual bool IsSyncable() OVERRIDE;
+ virtual bool MigrateToVersion(int version,
+ const std::string& app_locale,
+ bool* update_compatible_version) OVERRIDE;
// Adds "scheme" column to the web_intents and web_intents_defaults tables.
bool MigrateToVersion46AddSchemeColumn();