| 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 80061980d55d58f742b9bfecc9923f93021f6c6b..dea0649e81cff8c461562d55b73db83c766960fb 100644
|
| --- a/components/offline_pages/offline_page_metadata_store_sql.cc
|
| +++ b/components/offline_pages/offline_page_metadata_store_sql.cc
|
| @@ -38,7 +38,8 @@ bool CreateOfflinePagesTable(sql::Connection* db) {
|
| " client_id VARCHAR NOT NULL,"
|
| " online_url VARCHAR NOT NULL,"
|
| " file_path VARCHAR NOT NULL,"
|
| - " title VARCHAR NOT NULL DEFAULT ''"
|
| + " title VARCHAR NOT NULL DEFAULT '',"
|
| + " original_url VARCHAR NOT NULL DEFAULT ''"
|
| ")";
|
| return db->Execute(kSql);
|
| }
|
| @@ -99,6 +100,20 @@ bool UpgradeFrom54(sql::Connection* db) {
|
| return UpgradeWithQuery(db, kSql);
|
| }
|
|
|
| +bool UpgradeFrom55(sql::Connection* db) {
|
| + const char kSql[] =
|
| + "INSERT INTO " OFFLINE_PAGES_TABLE_NAME
|
| + " (offline_id, creation_time, file_size, last_access_time, "
|
| + "access_count, expiration_time, client_namespace, client_id, "
|
| + "online_url, file_path, title) "
|
| + "SELECT "
|
| + "offline_id, creation_time, file_size, last_access_time, "
|
| + "access_count, expiration_time, client_namespace, client_id, "
|
| + "online_url, file_path, title "
|
| + "FROM temp_" OFFLINE_PAGES_TABLE_NAME;
|
| + return UpgradeWithQuery(db, kSql);
|
| +}
|
| +
|
| 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.
|
| @@ -121,6 +136,9 @@ bool CreateSchema(sql::Connection* db) {
|
| } else if (db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "offline_url")) {
|
| if (!UpgradeFrom54(db))
|
| return false;
|
| + } else if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "original_url")) {
|
| + if (!UpgradeFrom55(db))
|
| + return false;
|
| }
|
|
|
| // TODO(fgorski): Add indices here.
|
| @@ -171,12 +189,14 @@ OfflinePageItem MakeOfflinePageItem(sql::Statement* statement) {
|
| GURL url(statement->ColumnString(8));
|
| base::FilePath path(GetPathFromUTF8String(statement->ColumnString(9)));
|
| base::string16 title = statement->ColumnString16(10);
|
| + GURL original_url(statement->ColumnString(11));
|
|
|
| OfflinePageItem item(url, id, client_id, path, file_size, creation_time);
|
| item.last_access_time = last_access_time;
|
| item.access_count = access_count;
|
| item.expiration_time = expiration_time;
|
| item.title = title;
|
| + item.original_url = original_url;
|
| return item;
|
| }
|
|
|
| @@ -187,9 +207,9 @@ ItemActionStatus Insert(sql::Connection* db, const OfflinePageItem& item) {
|
| "INSERT OR IGNORE INTO " OFFLINE_PAGES_TABLE_NAME
|
| " (offline_id, online_url, client_namespace, client_id, file_path, "
|
| "file_size, creation_time, last_access_time, access_count, "
|
| - "expiration_time, title)"
|
| + "expiration_time, title, original_url)"
|
| " VALUES "
|
| - " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
| + " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
| sql::Statement statement(db->GetCachedStatement(SQL_FROM_HERE, kSql));
|
| statement.BindInt64(0, item.offline_id);
|
| @@ -203,6 +223,7 @@ ItemActionStatus Insert(sql::Connection* db, const OfflinePageItem& item) {
|
| statement.BindInt(8, item.access_count);
|
| statement.BindInt64(9, item.expiration_time.ToInternalValue());
|
| statement.BindString16(10, item.title);
|
| + statement.BindString(11, item.original_url.spec());
|
| if (!statement.Run())
|
| return ItemActionStatus::STORE_ERROR;
|
| if (db->GetLastChangeCount() == 0)
|
| @@ -215,7 +236,7 @@ bool Update(sql::Connection* db, const OfflinePageItem& item) {
|
| "UPDATE OR IGNORE " OFFLINE_PAGES_TABLE_NAME
|
| " SET online_url = ?, client_namespace = ?, client_id = ?, file_path = ?,"
|
| " file_size = ?, creation_time = ?, last_access_time = ?,"
|
| - " access_count = ?, expiration_time = ?, title = ?"
|
| + " access_count = ?, expiration_time = ?, title = ?, original_url = ?"
|
| " WHERE offline_id = ?";
|
|
|
| sql::Statement statement(db->GetCachedStatement(SQL_FROM_HERE, kSql));
|
| @@ -229,7 +250,8 @@ bool Update(sql::Connection* db, const OfflinePageItem& item) {
|
| statement.BindInt(7, item.access_count);
|
| statement.BindInt64(8, item.expiration_time.ToInternalValue());
|
| statement.BindString16(9, item.title);
|
| - statement.BindInt64(10, item.offline_id);
|
| + statement.BindString(10, item.original_url.spec());
|
| + statement.BindInt64(11, item.offline_id);
|
| return statement.Run() && db->GetLastChangeCount() > 0;
|
| }
|
|
|
|
|