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

Unified Diff: components/offline_pages/offline_page_metadata_store_sql.cc

Issue 2336813002: [Offline pages] OPMStoreSQL: Upgrade to M55, Upgrade refactoring, conversion refactoring (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « components/offline_pages/offline_page_metadata_store_impl_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b15d72214e7396ebae626e6d65388c69c6c308f3..043f9432a7256b9cef7185dbae444e02acdb8cf2 100644
--- a/components/offline_pages/offline_page_metadata_store_sql.cc
+++ b/components/offline_pages/offline_page_metadata_store_sql.cc
@@ -36,26 +36,17 @@ bool CreateOfflinePagesTable(sql::Connection* db) {
" version INTEGER NOT NULL,"
Dmitry Titov 2016/09/12 23:25:41 could you add this to the kill list as well? Since
fgorski 2016/09/13 17:42:26 Done.
" last_access_time INTEGER NOT NULL,"
" access_count INTEGER NOT NULL,"
- // TODO(fgorski): Remove. Never used.
- " status INTEGER NOT NULL DEFAULT 0,"
- // A note on this field: It will be NULL for now and is
- // reserved for 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 DEFAULT 0,"
" client_namespace VARCHAR NOT NULL,"
" client_id VARCHAR NOT NULL,"
" online_url VARCHAR NOT NULL,"
- // TODO(fgorski): Remove. Never used.
- " offline_url VARCHAR NOT NULL DEFAULT '',"
" file_path VARCHAR NOT NULL,"
" title VARCHAR NOT NULL DEFAULT ''"
")";
return db->Execute(kSql);
}
-bool RefreshColumnsFrom52To54(sql::Connection* db) {
+bool UpgradeFrom52(sql::Connection* db) {
if (!db->Execute("ALTER TABLE " OFFLINE_PAGES_TABLE_NAME
" RENAME TO temp_" OFFLINE_PAGES_TABLE_NAME)) {
return false;
@@ -65,12 +56,12 @@ bool RefreshColumnsFrom52To54(sql::Connection* db) {
if (!db->Execute(
"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 "
+ "access_count, client_namespace, client_id, "
+ "online_url, file_path) "
+ "SELECT "
+ "offline_id, creation_time, file_size, version, last_access_time, "
+ "access_count, client_namespace, client_id, "
+ "online_url, file_path "
"FROM temp_" OFFLINE_PAGES_TABLE_NAME)) {
return false;
}
@@ -80,7 +71,7 @@ bool RefreshColumnsFrom52To54(sql::Connection* db) {
return true;
}
-bool RefreshColumnsFrom53To54(sql::Connection* db) {
+bool UpgradeFrom53(sql::Connection* db) {
if (!db->Execute("ALTER TABLE " OFFLINE_PAGES_TABLE_NAME
" RENAME TO temp_" OFFLINE_PAGES_TABLE_NAME)) {
return false;
@@ -90,12 +81,37 @@ bool RefreshColumnsFrom53To54(sql::Connection* db) {
if (!db->Execute(
"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, expiration_time) "
- "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, expiration_time "
+ "access_count, expiration_time, client_namespace, client_id, "
+ "online_url, file_path) "
+ "SELECT "
+ "offline_id, creation_time, file_size, version, last_access_time, "
+ "access_count, expiration_time, client_namespace, client_id, "
+ "online_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 UpgradeFrom54(sql::Connection* db) {
+ if (!db->Execute("ALTER TABLE " OFFLINE_PAGES_TABLE_NAME
+ " RENAME TO temp_" OFFLINE_PAGES_TABLE_NAME)) {
+ return false;
+ }
+ if (!CreateOfflinePagesTable(db))
+ return false;
+ if (!db->Execute(
+ "INSERT INTO " OFFLINE_PAGES_TABLE_NAME
+ " (offline_id, creation_time, file_size, version, last_access_time, "
+ "access_count, expiration_time, client_namespace, client_id, "
+ "online_url, file_path, title) "
+ "SELECT "
+ "offline_id, creation_time, file_size, version, last_access_time, "
+ "access_count, expiration_time, client_namespace, client_id, "
+ "online_url, file_path, title "
"FROM temp_" OFFLINE_PAGES_TABLE_NAME)) {
return false;
}
@@ -117,11 +133,17 @@ bool CreateSchema(sql::Connection* db) {
return false;
}
+ // Last Schema update was M55. When making a new Schema update, please update
+ // all methods below to appropriately upgrade from their respective milestones
+ // and add appropriate method to cover changes from M55.
if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "expiration_time")) {
- if (!RefreshColumnsFrom52To54(db))
+ if (!UpgradeFrom52(db))
return false;
} else if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "title")) {
- if (!RefreshColumnsFrom53To54(db))
+ if (!UpgradeFrom53(db))
+ return false;
+ } else if (db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "offline_url")) {
+ if (!UpgradeFrom54(db))
return false;
}
@@ -137,6 +159,26 @@ bool DeleteByOfflineId(sql::Connection* db, int64_t offline_id) {
return statement.Run();
}
+base::FilePath GetPathFromString(const std::string& path_string) {
+#if defined(OS_POSIX)
+ return base::FilePath(path_string);
+#elif defined(OS_WIN)
+ return base::FilePath(base::UTF8ToWide(path_string));
+#else
+#error Unknown OS
+#endif
+}
+
+std::string GetStringFromPath(const base::FilePath& path) {
+#if defined(OS_POSIX)
+ return path.value();
+#elif defined(OS_WIN)
+ return base::WideToUTF8(path.value());
+#else
+#error Unknown OS
+#endif
+}
+
// Create an offline page item from a SQL result. Expects complete rows with
// all columns present.
OfflinePageItem MakeOfflinePageItem(sql::Statement* statement) {
@@ -144,25 +186,23 @@ OfflinePageItem MakeOfflinePageItem(sql::Statement* statement) {
base::Time creation_time =
base::Time::FromInternalValue(statement->ColumnInt64(1));
int64_t file_size = statement->ColumnInt64(2);
- ClientId client_id(statement->ColumnString(9),
- statement->ColumnString(10));
- GURL url(statement->ColumnString(11));
-#if defined(OS_POSIX)
- base::FilePath path(statement->ColumnString(13));
-#elif defined(OS_WIN)
- base::FilePath path(base::UTF8ToWide(statement->ColumnString(13)));
-#else
-#error Unknown OS
-#endif
+ int version = statement->ColumnInt(3);
+ base::Time last_access_time =
+ base::Time::FromInternalValue(statement->ColumnInt64(4));
+ int access_count = statement->ColumnInt(5);
+ base::Time expiration_time =
+ base::Time::FromInternalValue(statement->ColumnInt64(6));
+ ClientId client_id(statement->ColumnString(7), statement->ColumnString(8));
+ GURL url(statement->ColumnString(9));
+ base::FilePath path(GetPathFromString(statement->ColumnString(10)));
+ base::string16 title = statement->ColumnString16(11);
OfflinePageItem item(url, id, client_id, path, file_size, creation_time);
- item.version = statement->ColumnInt(3);
- item.last_access_time = base::Time::FromInternalValue(
- statement->ColumnInt64(4));
- item.access_count = statement->ColumnInt(5);
- item.expiration_time =
- base::Time::FromInternalValue(statement->ColumnInt64(8));
- item.title = statement->ColumnString16(14);
+ item.version = version;
+ item.last_access_time = last_access_time;
+ item.access_count = access_count;
+ item.expiration_time = expiration_time;
+ item.title = title;
return item;
}
@@ -180,14 +220,7 @@ bool InsertOrReplace(sql::Connection* db, const OfflinePageItem& item) {
statement.BindString(1, item.url.spec());
statement.BindString(2, item.client_id.name_space);
statement.BindString(3, item.client_id.id);
-#if defined(OS_POSIX)
- std::string path_string = item.file_path.value();
-#elif defined(OS_WIN)
- std::string path_string = base::WideToUTF8(item.file_path.value());
-#else
-#error Unknown OS
-#endif
- statement.BindString(4, path_string);
+ statement.BindString(4, GetStringFromPath(item.file_path));
statement.BindInt64(5, item.file_size);
statement.BindInt64(6, item.creation_time.ToInternalValue());
statement.BindInt64(7, item.last_access_time.ToInternalValue());
« no previous file with comments | « components/offline_pages/offline_page_metadata_store_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698