Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/offline_pages/offline_page_metadata_store_sql.h" | 5 #include "components/offline_pages/offline_page_metadata_store_sql.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 " creation_time INTEGER NOT NULL," | 31 " creation_time INTEGER NOT NULL," |
| 32 " file_size INTEGER NOT NULL," | 32 " file_size INTEGER NOT NULL," |
| 33 " version INTEGER NOT NULL," | 33 " version INTEGER NOT NULL," |
| 34 " last_access_time INTEGER NOT NULL," | 34 " last_access_time INTEGER NOT NULL," |
| 35 " access_count INTEGER NOT NULL," | 35 " access_count INTEGER NOT NULL," |
| 36 " status INTEGER NOT NULL DEFAULT 0," | 36 " status INTEGER NOT NULL DEFAULT 0," |
| 37 // A note on this field: It will be NULL for now and is reserved for | 37 // A note on this field: It will be NULL for now and is reserved for |
| 38 // later use. We will treat NULL as "Unknown" in any subsequent queries | 38 // later use. We will treat NULL as "Unknown" in any subsequent queries |
| 39 // for user_initiated values. | 39 // for user_initiated values. |
| 40 " user_initiated INTEGER," // this is actually a boolean | 40 " user_initiated INTEGER," // this is actually a boolean |
| 41 " expiration_time INTEGER NOT NULL," | 41 " expiration_time INTEGER NOT NULL DEFAULT 0," |
| 42 " client_namespace VARCHAR NOT NULL," | 42 " client_namespace VARCHAR NOT NULL," |
| 43 " client_id VARCHAR NOT NULL," | 43 " client_id VARCHAR NOT NULL," |
| 44 " online_url VARCHAR NOT NULL," | 44 " online_url VARCHAR NOT NULL," |
| 45 " offline_url VARCHAR NOT NULL DEFAULT ''," | 45 " offline_url VARCHAR NOT NULL DEFAULT ''," |
| 46 " file_path VARCHAR NOT NULL" | 46 " file_path VARCHAR NOT NULL" |
| 47 ")"; | 47 ")"; |
| 48 | 48 |
| 49 // This is cloned from //content/browser/appcache/appcache_database.cc | 49 // This is cloned from //content/browser/appcache/appcache_database.cc |
| 50 struct TableInfo { | 50 struct TableInfo { |
| 51 const char* table_name; | 51 const char* table_name; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 80 sql += table_info.columns; | 80 sql += table_info.columns; |
| 81 return db->Execute(sql.c_str()); | 81 return db->Execute(sql.c_str()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool CreateSchema(sql::Connection* db) { | 84 bool CreateSchema(sql::Connection* db) { |
| 85 // If you create a transaction but don't Commit() it is automatically | 85 // If you create a transaction but don't Commit() it is automatically |
| 86 // rolled back by its destructor when it falls out of scope. | 86 // rolled back by its destructor when it falls out of scope. |
| 87 sql::Transaction transaction(db); | 87 sql::Transaction transaction(db); |
| 88 if (!transaction.Begin()) | 88 if (!transaction.Begin()) |
| 89 return false; | 89 return false; |
| 90 if (db->DoesTableExist(kOfflinePagesTable.table_name)) | 90 if (db->DoesTableExist(kOfflinePagesTable.table_name)) { |
| 91 if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "expiration_time")) { | |
| 92 return db->Execute( | |
| 93 "ALTER TABLE" OFFLINE_PAGES_TABLE_NAME | |
|
fgorski
2016/06/01 16:52:03
I think you need a space after TABLE
| |
| 94 "ADD COLUMN expiration_time INTEGER NOT NULL DEFAULT 0"); | |
|
fgorski
2016/06/01 16:52:04
and before ADD
| |
| 95 } | |
| 91 return true; | 96 return true; |
| 97 } | |
| 92 | 98 |
| 93 if (!CreateTable(db, kOfflinePagesTable)) | 99 if (!CreateTable(db, kOfflinePagesTable)) |
| 94 return false; | 100 return false; |
| 95 | 101 |
| 96 // TODO(bburns): Add indices here. | 102 // TODO(bburns): Add indices here. |
| 97 return transaction.Commit(); | 103 return transaction.Commit(); |
| 98 } | 104 } |
| 99 | 105 |
| 100 bool DeleteByOfflineId(sql::Connection* db, int64_t offline_id) { | 106 bool DeleteByOfflineId(sql::Connection* db, int64_t offline_id) { |
| 101 static const char kSql[] = | 107 static const char kSql[] = |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 } | 335 } |
| 330 | 336 |
| 331 void OfflinePageMetadataStoreSQL::Reset(const ResetCallback& callback) { | 337 void OfflinePageMetadataStoreSQL::Reset(const ResetCallback& callback) { |
| 332 background_task_runner_->PostTask( | 338 background_task_runner_->PostTask( |
| 333 FROM_HERE, | 339 FROM_HERE, |
| 334 base::Bind(&OfflinePageMetadataStoreSQL::ResetSync, base::Passed(&db_), | 340 base::Bind(&OfflinePageMetadataStoreSQL::ResetSync, base::Passed(&db_), |
| 335 base::ThreadTaskRunnerHandle::Get(), callback)); | 341 base::ThreadTaskRunnerHandle::Get(), callback)); |
| 336 } | 342 } |
| 337 | 343 |
| 338 } // namespace offline_pages | 344 } // namespace offline_pages |
| OLD | NEW |