Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: components/offline_pages/offline_page_metadata_store_sql.cc

Issue 2019333008: [Offline Pages] Fix crash due to table inconsistency. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win build Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/offline_page_metadata_store_sql.cc
diff --git a/components/offline_pages/offline_page_metadata_store_sql.cc b/components/offline_pages/offline_page_metadata_store_sql.cc
index 93afcb30ad5c8c13231e1147ff692f840bbfbba1..2be42570a5220f6156c5d1a9e7df899ac252e846 100644
--- a/components/offline_pages/offline_page_metadata_store_sql.cc
+++ b/components/offline_pages/offline_page_metadata_store_sql.cc
@@ -38,7 +38,7 @@ const char kOfflinePagesColumns[] =
// later use. We will treat NULL as "Unknown" in any subsequent queries
// for user_initiated values.
" user_initiated INTEGER," // this is actually a boolean
- " expiration_time INTEGER NOT NULL,"
+ " expiration_time INTEGER NOT NULL DEFAULT 0,"
" client_namespace VARCHAR NOT NULL,"
" client_id VARCHAR NOT NULL,"
" online_url VARCHAR NOT NULL,"
@@ -81,14 +81,45 @@ bool CreateTable(sql::Connection* db, const TableInfo& table_info) {
return db->Execute(sql.c_str());
}
+bool RefreshColumns(sql::Connection* db) {
+ if (!db->Execute("ALTER TABLE " OFFLINE_PAGES_TABLE_NAME
+ " RENAME TO temp_" OFFLINE_PAGES_TABLE_NAME)) {
+ return false;
+ }
+ if (!CreateTable(db, kOfflinePagesTable))
+ return false;
+ if (!db->Execute(
fgorski 2016/06/03 18:17:16 because you are actually doing the upgrade, could
romax 2016/06/03 19:36:22 Done.
+ "INSERT INTO " OFFLINE_PAGES_TABLE_NAME
+ " (offline_id, creation_time, file_size, version, last_access_time, "
+ "access_count, status, user_initiated, client_namespace, client_id, "
+ "online_url, offline_url, file_path) "
+ "SELECT offline_id, creation_time, file_size, version, "
+ "last_access_time, "
+ "access_count, status, user_initiated, client_namespace, client_id, "
+ "online_url, offline_url, file_path "
+ "FROM temp_" OFFLINE_PAGES_TABLE_NAME)) {
+ return false;
+ }
+ if (!db->Execute("DROP TABLE IF EXISTS temp_" OFFLINE_PAGES_TABLE_NAME))
+ return false;
+
+ return true;
+}
+
bool CreateSchema(sql::Connection* db) {
// If you create a transaction but don't Commit() it is automatically
// rolled back by its destructor when it falls out of scope.
sql::Transaction transaction(db);
if (!transaction.Begin())
return false;
- if (db->DoesTableExist(kOfflinePagesTable.table_name))
+ if (db->DoesTableExist(kOfflinePagesTable.table_name)) {
+ if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "expiration_time")) {
+ if (!RefreshColumns(db))
+ return false;
+ return transaction.Commit();
+ }
return true;
+ }
if (!CreateTable(db, kOfflinePagesTable))
return false;

Powered by Google App Engine
This is Rietveld 408576698