| 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 "storage/browser/database/database_tracker.h" | 5 #include "storage/browser/database/database_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 db_dir_, | 453 db_dir_, |
| 454 false, | 454 false, |
| 455 base::FileEnumerator::DIRECTORIES, | 455 base::FileEnumerator::DIRECTORIES, |
| 456 kTemporaryDirectoryPattern); | 456 kTemporaryDirectoryPattern); |
| 457 for (base::FilePath directory = directories.Next(); !directory.empty(); | 457 for (base::FilePath directory = directories.Next(); !directory.empty(); |
| 458 directory = directories.Next()) { | 458 directory = directories.Next()) { |
| 459 base::DeleteFile(directory, true); | 459 base::DeleteFile(directory, true); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 db_->set_histogram_tag("DatabaseTracker"); |
| 464 |
| 463 // If the tracker database exists, but it's corrupt or doesn't | 465 // If the tracker database exists, but it's corrupt or doesn't |
| 464 // have a meta table, delete the database directory. | 466 // have a meta table, delete the database directory. |
| 465 const base::FilePath kTrackerDatabaseFullPath = | 467 const base::FilePath kTrackerDatabaseFullPath = |
| 466 db_dir_.Append(base::FilePath(kTrackerDatabaseFileName)); | 468 db_dir_.Append(base::FilePath(kTrackerDatabaseFileName)); |
| 467 if (base::DirectoryExists(db_dir_) && | 469 if (base::DirectoryExists(db_dir_) && |
| 468 base::PathExists(kTrackerDatabaseFullPath) && | 470 base::PathExists(kTrackerDatabaseFullPath) && |
| 469 (!db_->Open(kTrackerDatabaseFullPath) || | 471 (!db_->Open(kTrackerDatabaseFullPath) || |
| 470 !sql::MetaTable::DoesTableExist(db_.get()))) { | 472 !sql::MetaTable::DoesTableExist(db_.get()))) { |
| 471 db_->Close(); | 473 db_->Close(); |
| 472 if (!base::DeleteFile(db_dir_, true)) | 474 if (!base::DeleteFile(db_dir_, true)) |
| 473 return false; | 475 return false; |
| 474 } | 476 } |
| 475 | 477 |
| 476 db_->set_histogram_tag("DatabaseTracker"); | |
| 477 | |
| 478 databases_table_.reset(new DatabasesTable(db_.get())); | 478 databases_table_.reset(new DatabasesTable(db_.get())); |
| 479 meta_table_.reset(new sql::MetaTable()); | 479 meta_table_.reset(new sql::MetaTable()); |
| 480 | 480 |
| 481 is_initialized_ = | 481 is_initialized_ = |
| 482 base::CreateDirectory(db_dir_) && | 482 base::CreateDirectory(db_dir_) && |
| 483 (db_->is_open() || | 483 (db_->is_open() || |
| 484 (is_incognito_ ? db_->OpenInMemory() : | 484 (is_incognito_ ? db_->OpenInMemory() : |
| 485 db_->Open(kTrackerDatabaseFullPath))) && | 485 db_->Open(kTrackerDatabaseFullPath))) && |
| 486 UpgradeToCurrentVersion(); | 486 UpgradeToCurrentVersion(); |
| 487 if (!is_initialized_) { | 487 if (!is_initialized_) { |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 if (!db_tracker_thread_->BelongsToCurrentThread()) { | 859 if (!db_tracker_thread_->BelongsToCurrentThread()) { |
| 860 db_tracker_thread_->PostTask( | 860 db_tracker_thread_->PostTask( |
| 861 FROM_HERE, | 861 FROM_HERE, |
| 862 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this)); | 862 base::Bind(&DatabaseTracker::SetForceKeepSessionState, this)); |
| 863 return; | 863 return; |
| 864 } | 864 } |
| 865 force_keep_session_state_ = true; | 865 force_keep_session_state_ = true; |
| 866 } | 866 } |
| 867 | 867 |
| 868 } // namespace storage | 868 } // namespace storage |
| OLD | NEW |