Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/dom_storage/dom_storage_database.h" | 5 #include "webkit/dom_storage/dom_storage_database.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "sql/diagnostic_error_delegate.h" | 9 #include "sql/diagnostic_error_delegate.h" |
| 10 #include "sql/statement.h" | 10 #include "sql/statement.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 tried_to_recreate_(false) { | 33 tried_to_recreate_(false) { |
| 34 // Note: in normal use we should never get an empty backing path here. | 34 // Note: in normal use we should never get an empty backing path here. |
| 35 // However, the unit test for this class defines another constructor | 35 // However, the unit test for this class defines another constructor |
| 36 // that will bypass this check to allow an empty path that signifies | 36 // that will bypass this check to allow an empty path that signifies |
| 37 // we should operate on an in-memory database for performance/reliability | 37 // we should operate on an in-memory database for performance/reliability |
| 38 // reasons. | 38 // reasons. |
| 39 DCHECK(!file_path_.empty()); | 39 DCHECK(!file_path_.empty()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 DomStorageDatabase::~DomStorageDatabase() { | 42 DomStorageDatabase::~DomStorageDatabase() { |
| 43 if (IsOpen()) { | |
| 44 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, | |
| 45 "SELECT COUNT(key) from ItemTable")); | |
|
michaeln
2012/02/23 20:48:48
like we chatted about, can the 'its empty' conditi
benm (inactive)
2012/02/24 12:42:01
Done, but moved to it's own CL in http://coderevie
| |
| 46 if (statement.Step() && statement.ColumnInt(0) == 0) { | |
| 47 // Delete the db from disk, it's empty. | |
| 48 statement.Clear(); | |
| 49 Close(); | |
| 50 file_util::Delete(file_path_, false); | |
| 51 } | |
| 52 } | |
| 43 } | 53 } |
| 44 | 54 |
| 45 void DomStorageDatabase::ReadAllValues(ValuesMap* result) { | 55 void DomStorageDatabase::ReadAllValues(ValuesMap* result) { |
| 46 if (!LazyOpen(false)) | 56 if (!LazyOpen(false)) |
| 47 return; | 57 return; |
| 48 | 58 |
| 49 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, | 59 sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, |
| 50 "SELECT * from ItemTable")); | 60 "SELECT * from ItemTable")); |
| 51 DCHECK(statement.is_valid()); | 61 DCHECK(statement.is_valid()); |
| 52 | 62 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 CreateTableV2() && | 261 CreateTableV2() && |
| 252 CommitChanges(false, values) && | 262 CommitChanges(false, values) && |
| 253 migration.Commit(); | 263 migration.Commit(); |
| 254 } | 264 } |
| 255 | 265 |
| 256 void DomStorageDatabase::Close() { | 266 void DomStorageDatabase::Close() { |
| 257 db_.reset(NULL); | 267 db_.reset(NULL); |
| 258 } | 268 } |
| 259 | 269 |
| 260 } // namespace dom_storage | 270 } // namespace dom_storage |
| OLD | NEW |