Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/database/database_tracker.h" | 5 #include "webkit/database/database_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "app/sql/connection.h" | 10 #include "app/sql/connection.h" |
| 11 #include "app/sql/diagnostic_error_delegate.h" | 11 #include "app/sql/diagnostic_error_delegate.h" |
| 12 #include "app/sql/meta_table.h" | 12 #include "app/sql/meta_table.h" |
| 13 #include "app/sql/statement.h" | 13 #include "app/sql/statement.h" |
| 14 #include "app/sql/transaction.h" | 14 #include "app/sql/transaction.h" |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
| 18 #include "base/platform_file.h" | |
| 18 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
| 19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 21 #include "webkit/database/database_quota_client.h" | 22 #include "webkit/database/database_quota_client.h" |
| 22 #include "webkit/database/database_util.h" | 23 #include "webkit/database/database_util.h" |
| 23 #include "webkit/database/databases_table.h" | 24 #include "webkit/database/databases_table.h" |
| 24 #include "webkit/quota/quota_manager.h" | 25 #include "webkit/quota/quota_manager.h" |
| 25 #include "webkit/quota/special_storage_policy.h" | 26 #include "webkit/quota/special_storage_policy.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 40 namespace webkit_database { | 41 namespace webkit_database { |
| 41 | 42 |
| 42 const FilePath::CharType kDatabaseDirectoryName[] = | 43 const FilePath::CharType kDatabaseDirectoryName[] = |
| 43 FILE_PATH_LITERAL("databases"); | 44 FILE_PATH_LITERAL("databases"); |
| 44 const FilePath::CharType kIncognitoDatabaseDirectoryName[] = | 45 const FilePath::CharType kIncognitoDatabaseDirectoryName[] = |
| 45 FILE_PATH_LITERAL("databases-incognito"); | 46 FILE_PATH_LITERAL("databases-incognito"); |
| 46 const FilePath::CharType kTrackerDatabaseFileName[] = | 47 const FilePath::CharType kTrackerDatabaseFileName[] = |
| 47 FILE_PATH_LITERAL("Databases.db"); | 48 FILE_PATH_LITERAL("Databases.db"); |
| 48 static const int kCurrentVersion = 2; | 49 static const int kCurrentVersion = 2; |
| 49 static const int kCompatibleVersion = 1; | 50 static const int kCompatibleVersion = 1; |
| 50 static const char* kExtensionOriginIdentifierPrefix = "chrome-extension_"; | |
| 51 | 51 |
| 52 OriginInfo::OriginInfo() | 52 OriginInfo::OriginInfo() |
| 53 : total_size_(0) {} | 53 : total_size_(0) {} |
| 54 | 54 |
| 55 OriginInfo::OriginInfo(const OriginInfo& origin_info) | 55 OriginInfo::OriginInfo(const OriginInfo& origin_info) |
| 56 : origin_(origin_info.origin_), | 56 : origin_(origin_info.origin_), |
| 57 total_size_(origin_info.total_size_), | 57 total_size_(origin_info.total_size_), |
| 58 database_info_(origin_info.database_info_) {} | 58 database_info_(origin_info.database_info_) {} |
| 59 | 59 |
| 60 OriginInfo::~OriginInfo() {} | 60 OriginInfo::~OriginInfo() {} |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 80 return it->second.second; | 80 return it->second.second; |
| 81 return string16(); | 81 return string16(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 OriginInfo::OriginInfo(const string16& origin, int64 total_size) | 84 OriginInfo::OriginInfo(const string16& origin, int64 total_size) |
| 85 : origin_(origin), total_size_(total_size) {} | 85 : origin_(origin), total_size_(total_size) {} |
| 86 | 86 |
| 87 DatabaseTracker::DatabaseTracker( | 87 DatabaseTracker::DatabaseTracker( |
| 88 const FilePath& profile_path, | 88 const FilePath& profile_path, |
| 89 bool is_incognito, | 89 bool is_incognito, |
| 90 bool clear_local_state_on_exit, | |
| 90 quota::SpecialStoragePolicy* special_storage_policy, | 91 quota::SpecialStoragePolicy* special_storage_policy, |
| 91 quota::QuotaManagerProxy* quota_manager_proxy, | 92 quota::QuotaManagerProxy* quota_manager_proxy, |
| 92 base::MessageLoopProxy* db_tracker_thread) | 93 base::MessageLoopProxy* db_tracker_thread) |
| 93 : is_initialized_(false), | 94 : is_initialized_(false), |
| 94 is_incognito_(is_incognito), | 95 is_incognito_(is_incognito), |
| 96 clear_local_state_on_exit_(clear_local_state_on_exit), | |
| 95 shutting_down_(false), | 97 shutting_down_(false), |
| 96 profile_path_(profile_path), | 98 profile_path_(profile_path), |
| 97 db_dir_(is_incognito_ ? | 99 db_dir_(is_incognito_ ? |
| 98 profile_path_.Append(kIncognitoDatabaseDirectoryName) : | 100 profile_path_.Append(kIncognitoDatabaseDirectoryName) : |
| 99 profile_path_.Append(kDatabaseDirectoryName)), | 101 profile_path_.Append(kDatabaseDirectoryName)), |
| 100 db_(new sql::Connection()), | 102 db_(new sql::Connection()), |
| 101 databases_table_(NULL), | 103 databases_table_(NULL), |
| 102 meta_table_(NULL), | 104 meta_table_(NULL), |
| 103 special_storage_policy_(special_storage_policy), | 105 special_storage_policy_(special_storage_policy), |
| 104 quota_manager_proxy_(quota_manager_proxy), | 106 quota_manager_proxy_(quota_manager_proxy), |
| 105 incognito_origin_directories_generator_(0) { | 107 incognito_origin_directories_generator_(0) { |
| 106 if (quota_manager_proxy) { | 108 if (quota_manager_proxy) { |
| 107 quota_manager_proxy->RegisterClient( | 109 quota_manager_proxy->RegisterClient( |
| 108 new DatabaseQuotaClient(db_tracker_thread, this)); | 110 new DatabaseQuotaClient(db_tracker_thread, this)); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 DatabaseTracker::~DatabaseTracker() { | 114 DatabaseTracker::~DatabaseTracker() { |
| 113 DCHECK(dbs_to_be_deleted_.empty()); | 115 DCHECK(dbs_to_be_deleted_.empty()); |
| 114 DCHECK(deletion_callbacks_.empty()); | 116 DCHECK(deletion_callbacks_.empty()); |
| 117 | |
| 118 if (clear_local_state_on_exit_ && LazyInit()) { | |
|
michaeln
2011/06/22 20:15:33
Thought of another issue that has to be considered
jochen (gone - plz use gerrit)
2011/06/22 21:44:12
The profiles (which own the db tracker) are delete
michaeln
2011/06/22 22:35:14
DatabaseMessageFilters also hold references to thi
jochen (gone - plz use gerrit)
2011/06/28 10:01:24
Done.
| |
| 119 std::vector<string16> origin_identifiers; | |
| 120 databases_table_->GetAllOrigins(&origin_identifiers); | |
| 121 | |
| 122 for (std::vector<string16>::iterator origin = origin_identifiers.begin(); | |
| 123 origin != origin_identifiers.end(); ++origin) { | |
| 124 if (special_storage_policy_.get() && | |
| 125 special_storage_policy_->IsStorageProtected( | |
| 126 DatabaseUtil::GetOriginFromIdentifier(*origin))) { | |
| 127 continue; | |
| 128 } | |
| 129 std::vector<DatabaseDetails> details; | |
| 130 databases_table_->GetAllDatabaseDetailsForOrigin(*origin, &details); | |
| 131 for (std::vector<DatabaseDetails>::iterator database = details.begin(); | |
| 132 database != details.end(); ++database) { | |
| 133 base::PlatformFile file_handle = base::CreatePlatformFile( | |
| 134 GetFullDBFilePath(*origin, database->database_name), | |
| 135 base::PLATFORM_FILE_OPEN_ALWAYS | | |
| 136 base::PLATFORM_FILE_DELETE_ON_CLOSE | | |
| 137 base::PLATFORM_FILE_READ, | |
| 138 NULL, NULL); | |
| 139 base::ClosePlatformFile(file_handle); | |
|
michaeln
2011/06/22 19:43:28
I'm not sure this will actually result in the file
michaeln
2011/06/22 20:15:33
Hmmm... if we were guaranteed that the IPC channel
jochen (gone - plz use gerrit)
2011/06/22 21:44:12
With the change in vfs_backend.cc, you can mark op
michaeln
2011/06/22 22:35:14
But what if the last file handle to go is not one
jochen (gone - plz use gerrit)
2011/06/28 10:01:24
if the file was originally opened with SHARE_DELET
| |
| 140 } | |
| 141 databases_table_->DeleteOrigin(*origin); | |
|
michaeln
2011/06/22 19:43:28
As a matter of privacy, i think we need to delete
jochen (gone - plz use gerrit)
2011/06/22 21:44:12
that is, however, more difficult because the files
michaeln
2011/06/22 22:35:14
we'd have to move them in order to delete the dire
jochen (gone - plz use gerrit)
2011/06/28 10:01:24
Done.
| |
| 142 } | |
| 143 } | |
| 115 } | 144 } |
| 116 | 145 |
| 117 void DatabaseTracker::DatabaseOpened(const string16& origin_identifier, | 146 void DatabaseTracker::DatabaseOpened(const string16& origin_identifier, |
| 118 const string16& database_name, | 147 const string16& database_name, |
| 119 const string16& database_description, | 148 const string16& database_description, |
| 120 int64 estimated_size, | 149 int64 estimated_size, |
| 121 int64* database_size) { | 150 int64* database_size) { |
| 122 if (!LazyInit()) { | 151 if (!LazyInit()) { |
| 123 *database_size = 0; | 152 *database_size = 0; |
| 124 return; | 153 return; |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 for (FileHandlesMap::iterator it = incognito_file_handles_.begin(); | 769 for (FileHandlesMap::iterator it = incognito_file_handles_.begin(); |
| 741 it != incognito_file_handles_.end(); it++) | 770 it != incognito_file_handles_.end(); it++) |
| 742 base::ClosePlatformFile(it->second); | 771 base::ClosePlatformFile(it->second); |
| 743 | 772 |
| 744 FilePath incognito_db_dir = | 773 FilePath incognito_db_dir = |
| 745 profile_path_.Append(kIncognitoDatabaseDirectoryName); | 774 profile_path_.Append(kIncognitoDatabaseDirectoryName); |
| 746 if (file_util::DirectoryExists(incognito_db_dir)) | 775 if (file_util::DirectoryExists(incognito_db_dir)) |
| 747 file_util::Delete(incognito_db_dir, true); | 776 file_util::Delete(incognito_db_dir, true); |
| 748 } | 777 } |
| 749 | 778 |
| 750 // static | 779 void DatabaseTracker::SetClearLocalStateOnExit(bool clear_local_state_on_exit) { |
| 751 void DatabaseTracker::ClearLocalState(const FilePath& profile_path) { | 780 clear_local_state_on_exit_ = clear_local_state_on_exit; |
| 752 // TODO(michaeln): use SpecialStoragePolicy instead of kExtensionOriginPrefix | |
| 753 FilePath db_dir = profile_path.Append(FilePath(kDatabaseDirectoryName)); | |
| 754 FilePath db_tracker = db_dir.Append(FilePath(kTrackerDatabaseFileName)); | |
| 755 if (file_util::DirectoryExists(db_dir) && | |
| 756 file_util::PathExists(db_tracker)) { | |
| 757 scoped_ptr<sql::Connection> db_(new sql::Connection); | |
| 758 if (!db_->Open(db_tracker) || | |
| 759 !db_->DoesTableExist("Databases")) { | |
| 760 db_->Close(); | |
| 761 file_util::Delete(db_dir, true); | |
| 762 return; | |
| 763 } else { | |
| 764 sql::Statement delete_statement(db_->GetCachedStatement( | |
| 765 SQL_FROM_HERE, "DELETE FROM Databases WHERE origin NOT LIKE ?")); | |
| 766 std::string filter(kExtensionOriginIdentifierPrefix); | |
| 767 filter += "%"; | |
| 768 delete_statement.BindString(0, filter); | |
| 769 if (!delete_statement.Run()) { | |
| 770 db_->Close(); | |
| 771 file_util::Delete(db_dir, true); | |
| 772 return; | |
| 773 } | |
| 774 } | |
| 775 } | |
| 776 file_util::FileEnumerator file_enumerator(db_dir, false, | |
| 777 file_util::FileEnumerator::DIRECTORIES); | |
| 778 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); | |
| 779 file_path = file_enumerator.Next()) { | |
| 780 if (file_path.BaseName() != FilePath(kTrackerDatabaseFileName)) { | |
| 781 std::string basename = file_path.BaseName().MaybeAsASCII(); | |
| 782 if (!basename.empty() && | |
| 783 !StartsWithASCII(basename, kExtensionOriginIdentifierPrefix, true)) { | |
| 784 file_util::Delete(file_path, true); | |
| 785 } | |
| 786 } | |
| 787 } | |
| 788 } | 781 } |
| 789 | 782 |
| 790 } // namespace webkit_database | 783 } // namespace webkit_database |
| OLD | NEW |