Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/enhanced_bookmarks/persistent_image_store.h" | 5 #include "components/enhanced_bookmarks/persistent_image_store.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | |
| 7 #include "components/enhanced_bookmarks/image_store_util.h" | 8 #include "components/enhanced_bookmarks/image_store_util.h" |
| 8 #include "sql/statement.h" | 9 #include "sql/statement.h" |
| 9 #include "sql/transaction.h" | 10 #include "sql/transaction.h" |
| 10 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 bool InitTables(sql::Connection& db) { | 16 bool InitTables(sql::Connection& db) { |
| 16 const char kTableSql[] = | 17 const char kTableSql[] = |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 void PersistentImageStore::ClearAll() { | 191 void PersistentImageStore::ClearAll() { |
| 191 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 192 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 192 if (OpenDatabase() != sql::INIT_OK) | 193 if (OpenDatabase() != sql::INIT_OK) |
| 193 return; | 194 return; |
| 194 | 195 |
| 195 sql::Statement statement(db_.GetCachedStatement( | 196 sql::Statement statement(db_.GetCachedStatement( |
| 196 SQL_FROM_HERE, "DELETE FROM images_by_url")); | 197 SQL_FROM_HERE, "DELETE FROM images_by_url")); |
| 197 statement.Run(); | 198 statement.Run(); |
| 198 } | 199 } |
| 199 | 200 |
| 201 int64 PersistentImageStore::GetStoreSize() { | |
| 202 // Ensure that the db is actually valid. | |
| 203 if (OpenDatabase() != sql::INIT_OK) | |
|
sky
2014/05/29 21:51:05
Do you really need to open the db here?
Kibeom Kim (inactive)
2014/05/29 23:07:15
Done.
| |
| 204 return -1; | |
| 205 | |
| 206 return base::File(path_, base::File::FLAG_OPEN | base::File::FLAG_READ). | |
| 207 GetLength(); | |
| 208 } | |
| 209 | |
| 200 PersistentImageStore::~PersistentImageStore() { | 210 PersistentImageStore::~PersistentImageStore() { |
| 201 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 211 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 202 } | 212 } |
| 203 | 213 |
| 204 sql::InitStatus PersistentImageStore::OpenDatabase() { | 214 sql::InitStatus PersistentImageStore::OpenDatabase() { |
| 205 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 215 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 206 | 216 |
| 207 if (db_.is_open()) | 217 if (db_.is_open()) |
| 208 return sql::INIT_OK; | 218 return sql::INIT_OK; |
| 209 | 219 |
| 210 const size_t kAttempts = 2; | 220 const size_t kAttempts = 2; |
| 211 | 221 |
| 212 sql::InitStatus status = sql::INIT_FAILURE; | 222 sql::InitStatus status = sql::INIT_FAILURE; |
| 213 for (size_t i = 0; i < kAttempts; ++i) { | 223 for (size_t i = 0; i < kAttempts; ++i) { |
| 214 status = OpenDatabaseImpl(db_, path_); | 224 status = OpenDatabaseImpl(db_, path_); |
| 215 if (status == sql::INIT_OK) | 225 if (status == sql::INIT_OK) |
| 216 return status; | 226 return status; |
| 217 | 227 |
| 218 // Can't open, raze(). | 228 // Can't open, raze(). |
| 219 if (db_.is_open()) | 229 if (db_.is_open()) |
| 220 db_.Raze(); | 230 db_.Raze(); |
| 221 db_.Close(); | 231 db_.Close(); |
| 222 } | 232 } |
| 223 | 233 |
| 224 DCHECK(false) << "Can't open image DB"; | 234 DCHECK(false) << "Can't open image DB"; |
| 225 return sql::INIT_FAILURE; | 235 return sql::INIT_FAILURE; |
| 226 } | 236 } |
| OLD | NEW |