| 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 26 matching lines...) Expand all Loading... |
| 37 " access_count INTEGER NOT NULL," | 37 " access_count INTEGER NOT NULL," |
| 38 " status INTEGER NOT NULL DEFAULT 0," | 38 " status INTEGER NOT NULL DEFAULT 0," |
| 39 // A note on this field: It will be NULL for now and is reserved for | 39 // A note on this field: It will be NULL for now and is reserved for |
| 40 // later use. We will treat NULL as "Unknown" in any subsequent queries | 40 // later use. We will treat NULL as "Unknown" in any subsequent queries |
| 41 // for user_initiated values. | 41 // for user_initiated values. |
| 42 " user_initiated INTEGER," // this is actually a boolean | 42 " user_initiated INTEGER," // this is actually a boolean |
| 43 " expiration_time INTEGER NOT NULL DEFAULT 0," | 43 " expiration_time INTEGER NOT NULL DEFAULT 0," |
| 44 " client_namespace VARCHAR NOT NULL," | 44 " client_namespace VARCHAR NOT NULL," |
| 45 " client_id VARCHAR NOT NULL," | 45 " client_id VARCHAR NOT NULL," |
| 46 " online_url VARCHAR NOT NULL," | 46 " online_url VARCHAR NOT NULL," |
| 47 " offline_url VARCHAR NOT NULL DEFAULT ''," | 47 " offline_url VARCHAR NOT NULL DEFAULT ''," // Deprecated. |
| 48 " file_path VARCHAR NOT NULL," | 48 " file_path VARCHAR NOT NULL," |
| 49 " title VARCHAR NOT NULL DEFAULT ''" | 49 " title VARCHAR NOT NULL DEFAULT ''" |
| 50 ")"; | 50 ")"; |
| 51 | 51 |
| 52 // This is cloned from //content/browser/appcache/appcache_database.cc | 52 // This is cloned from //content/browser/appcache/appcache_database.cc |
| 53 struct TableInfo { | 53 struct TableInfo { |
| 54 const char* table_name; | 54 const char* table_name; |
| 55 const char* columns; | 55 const char* columns; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 const TableInfo kOfflinePagesTable{OFFLINE_PAGES_TABLE_NAME, | 58 const TableInfo kOfflinePagesTable{OFFLINE_PAGES_TABLE_NAME, |
| 59 kOfflinePagesColumns}; | 59 kOfflinePagesColumns}; |
| 60 | 60 |
| 61 // This enum is used to define the indices for the columns in each row | 61 // This enum is used to define the indices for the columns in each row |
| 62 // that hold the different pieces of offline page. | 62 // that hold the different pieces of offline page. |
| 63 enum : int { | 63 enum : int { |
| 64 OP_OFFLINE_ID = 0, | 64 OP_OFFLINE_ID = 0, |
| 65 OP_CREATION_TIME, | 65 OP_CREATION_TIME, |
| 66 OP_FILE_SIZE, | 66 OP_FILE_SIZE, |
| 67 OP_VERSION, | 67 OP_VERSION, |
| 68 OP_LAST_ACCESS_TIME, | 68 OP_LAST_ACCESS_TIME, |
| 69 OP_ACCESS_COUNT, | 69 OP_ACCESS_COUNT, |
| 70 OP_STATUS, | 70 OP_STATUS, |
| 71 OP_USER_INITIATED, | 71 OP_USER_INITIATED, |
| 72 OP_EXPIRATION_TIME, // Added in M53. | 72 OP_EXPIRATION_TIME, // Added in M53. |
| 73 OP_CLIENT_NAMESPACE, | 73 OP_CLIENT_NAMESPACE, |
| 74 OP_CLIENT_ID, | 74 OP_CLIENT_ID, |
| 75 OP_ONLINE_URL, | 75 OP_ONLINE_URL, |
| 76 OP_OFFLINE_URL, | 76 OP_OFFLINE_URL, // Deprecated. |
| 77 OP_FILE_PATH, | 77 OP_FILE_PATH, |
| 78 OP_TITLE, // Added in M54. | 78 OP_TITLE, // Added in M54. |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 bool CreateTable(sql::Connection* db, const TableInfo& table_info) { | 81 bool CreateTable(sql::Connection* db, const TableInfo& table_info) { |
| 82 std::string sql("CREATE TABLE "); | 82 std::string sql("CREATE TABLE "); |
| 83 sql += table_info.table_name; | 83 sql += table_info.table_name; |
| 84 sql += table_info.columns; | 84 sql += table_info.columns; |
| 85 return db->Execute(sql.c_str()); | 85 return db->Execute(sql.c_str()); |
| 86 } | 86 } |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 393 } |
| 394 | 394 |
| 395 void OfflinePageMetadataStoreSQL::Reset(const ResetCallback& callback) { | 395 void OfflinePageMetadataStoreSQL::Reset(const ResetCallback& callback) { |
| 396 background_task_runner_->PostTask( | 396 background_task_runner_->PostTask( |
| 397 FROM_HERE, | 397 FROM_HERE, |
| 398 base::Bind(&OfflinePageMetadataStoreSQL::ResetSync, base::Passed(&db_), | 398 base::Bind(&OfflinePageMetadataStoreSQL::ResetSync, base::Passed(&db_), |
| 399 base::ThreadTaskRunnerHandle::Get(), callback)); | 399 base::ThreadTaskRunnerHandle::Get(), callback)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 } // namespace offline_pages | 402 } // namespace offline_pages |
| OLD | NEW |