| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (!UpgradeFrom52(db)) | 116 if (!UpgradeFrom52(db)) |
| 117 return false; | 117 return false; |
| 118 } else if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "title")) { | 118 } else if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "title")) { |
| 119 if (!UpgradeFrom53(db)) | 119 if (!UpgradeFrom53(db)) |
| 120 return false; | 120 return false; |
| 121 } else if (db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "offline_url")) { | 121 } else if (db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "offline_url")) { |
| 122 if (!UpgradeFrom54(db)) | 122 if (!UpgradeFrom54(db)) |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // TODO(bburns): Add indices here. | 126 // TODO(fgorski): Add indices here. |
| 127 return transaction.Commit(); | 127 return transaction.Commit(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool DeleteByOfflineId(sql::Connection* db, int64_t offline_id) { | 130 bool DeleteByOfflineId(sql::Connection* db, int64_t offline_id) { |
| 131 static const char kSql[] = | 131 static const char kSql[] = |
| 132 "DELETE FROM " OFFLINE_PAGES_TABLE_NAME " WHERE offline_id=?"; | 132 "DELETE FROM " OFFLINE_PAGES_TABLE_NAME " WHERE offline_id=?"; |
| 133 sql::Statement statement(db->GetCachedStatement(SQL_FROM_HERE, kSql)); | 133 sql::Statement statement(db->GetCachedStatement(SQL_FROM_HERE, kSql)); |
| 134 statement.BindInt64(0, offline_id); | 134 statement.BindInt64(0, offline_id); |
| 135 return statement.Run(); | 135 return statement.Run(); |
| 136 } | 136 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 db->Preload(); | 252 db->Preload(); |
| 253 | 253 |
| 254 return CreateSchema(db); | 254 return CreateSchema(db); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void NotifyLoadResult(scoped_refptr<base::SingleThreadTaskRunner> runner, | 257 void NotifyLoadResult(scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 258 const OfflinePageMetadataStore::LoadCallback& callback, | 258 const OfflinePageMetadataStore::LoadCallback& callback, |
| 259 OfflinePageMetadataStore::LoadStatus status, | 259 OfflinePageMetadataStore::LoadStatus status, |
| 260 const std::vector<OfflinePageItem>& result) { | 260 const std::vector<OfflinePageItem>& result) { |
| 261 // TODO(bburns): Switch to SQL specific UMA metrics. | 261 // TODO(fgorski): Switch to SQL specific UMA metrics. |
| 262 UMA_HISTOGRAM_ENUMERATION("OfflinePages.LoadStatus", status, | 262 UMA_HISTOGRAM_ENUMERATION("OfflinePages.LoadStatus", status, |
| 263 OfflinePageMetadataStore::LOAD_STATUS_COUNT); | 263 OfflinePageMetadataStore::LOAD_STATUS_COUNT); |
| 264 if (status == OfflinePageMetadataStore::LOAD_SUCCEEDED) { | 264 if (status == OfflinePageMetadataStore::LOAD_SUCCEEDED) { |
| 265 UMA_HISTOGRAM_COUNTS("OfflinePages.SavedPageCount", | 265 UMA_HISTOGRAM_COUNTS("OfflinePages.SavedPageCount", |
| 266 static_cast<int32_t>(result.size())); | 266 static_cast<int32_t>(result.size())); |
| 267 } else { | 267 } else { |
| 268 DVLOG(1) << "Offline pages database loading failed: " << status; | 268 DVLOG(1) << "Offline pages database loading failed: " << status; |
| 269 } | 269 } |
| 270 runner->PostTask(FROM_HERE, base::Bind(callback, status, result)); | 270 runner->PostTask(FROM_HERE, base::Bind(callback, status, result)); |
| 271 } | 271 } |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 579 bool OfflinePageMetadataStoreSQL::CheckDb(const base::Closure& callback) { | 579 bool OfflinePageMetadataStoreSQL::CheckDb(const base::Closure& callback) { |
| 580 if (!db_.get() || state_ != StoreState::LOADED) { | 580 if (!db_.get() || state_ != StoreState::LOADED) { |
| 581 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 581 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 582 return false; | 582 return false; |
| 583 } | 583 } |
| 584 return true; | 584 return true; |
| 585 } | 585 } |
| 586 | 586 |
| 587 } // namespace offline_pages | 587 } // namespace offline_pages |
| OLD | NEW |