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