| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tools/test_shell/simple_database_system.h" | 5 #include "webkit/tools/test_shell/simple_database_system.h" |
| 6 | 6 |
| 7 #if defined(USE_SYSTEM_SQLITE) | 7 #if defined(USE_SYSTEM_SQLITE) |
| 8 #include <sqlite3.h> | 8 #include <sqlite3.h> |
| 9 #else | 9 #else |
| 10 #include "third_party/sqlite/preprocessed/sqlite3.h" | 10 #include "third_party/sqlite/preprocessed/sqlite3.h" |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/platform_thread.h" | |
| 17 #include "base/process_util.h" | |
| 18 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 20 #include "webkit/database/database_util.h" | 18 #include "webkit/database/database_util.h" |
| 21 #include "webkit/database/vfs_backend.h" | 19 #include "webkit/database/vfs_backend.h" |
| 22 | 20 |
| 23 using webkit_database::DatabaseTracker; | 21 using webkit_database::DatabaseTracker; |
| 24 using webkit_database::DatabaseUtil; | 22 using webkit_database::DatabaseUtil; |
| 25 using webkit_database::VfsBackend; | 23 using webkit_database::VfsBackend; |
| 26 | 24 |
| 27 SimpleDatabaseSystem* SimpleDatabaseSystem::instance_ = NULL; | 25 SimpleDatabaseSystem* SimpleDatabaseSystem::instance_ = NULL; |
| 28 | 26 |
| 29 SimpleDatabaseSystem* SimpleDatabaseSystem::GetInstance() { | 27 SimpleDatabaseSystem* SimpleDatabaseSystem::GetInstance() { |
| 30 DCHECK(instance_); | 28 DCHECK(instance_); |
| 31 return instance_; | 29 return instance_; |
| 32 } | 30 } |
| 33 | 31 |
| 34 SimpleDatabaseSystem::SimpleDatabaseSystem() | 32 SimpleDatabaseSystem::SimpleDatabaseSystem() |
| 35 : waiting_for_dbs_to_close_(false) { | 33 : waiting_for_dbs_to_close_(false) { |
| 36 temp_dir_.CreateUniqueTempDir(); | 34 temp_dir_.CreateUniqueTempDir(); |
| 37 db_tracker_ = new DatabaseTracker(temp_dir_.path()); | 35 db_tracker_ = new DatabaseTracker(temp_dir_.path(), false); |
| 38 db_tracker_->AddObserver(this); | 36 db_tracker_->AddObserver(this); |
| 39 DCHECK(!instance_); | 37 DCHECK(!instance_); |
| 40 instance_ = this; | 38 instance_ = this; |
| 41 } | 39 } |
| 42 | 40 |
| 43 SimpleDatabaseSystem::~SimpleDatabaseSystem() { | 41 SimpleDatabaseSystem::~SimpleDatabaseSystem() { |
| 44 db_tracker_->RemoveObserver(this); | 42 db_tracker_->RemoveObserver(this); |
| 45 instance_ = NULL; | 43 instance_ = NULL; |
| 46 } | 44 } |
| 47 | 45 |
| 48 base::PlatformFile SimpleDatabaseSystem::OpenFile( | 46 base::PlatformFile SimpleDatabaseSystem::OpenFile( |
| 49 const string16& vfs_file_name, int desired_flags) { | 47 const string16& vfs_file_name, int desired_flags) { |
| 50 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | 48 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
| 51 FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); | 49 FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); |
| 52 if (file_name.empty()) { | 50 if (file_name.empty()) { |
| 53 VfsBackend::OpenTempFileInDirectory( | 51 VfsBackend::OpenTempFileInDirectory( |
| 54 db_tracker_->DatabaseDirectory(), desired_flags, | 52 db_tracker_->DatabaseDirectory(), desired_flags, &file_handle); |
| 55 base::GetCurrentProcessHandle(), &file_handle); | |
| 56 } else { | 53 } else { |
| 57 VfsBackend::OpenFile(file_name, desired_flags, | 54 VfsBackend::OpenFile(file_name, desired_flags, &file_handle); |
| 58 base::GetCurrentProcessHandle(), &file_handle); | |
| 59 } | 55 } |
| 60 | 56 |
| 61 return file_handle; | 57 return file_handle; |
| 62 } | 58 } |
| 63 | 59 |
| 64 int SimpleDatabaseSystem::DeleteFile( | 60 int SimpleDatabaseSystem::DeleteFile( |
| 65 const string16& vfs_file_name, bool sync_dir) { | 61 const string16& vfs_file_name, bool sync_dir) { |
| 66 // We try to delete the file multiple times, because that's what the default | 62 // We try to delete the file multiple times, because that's what the default |
| 67 // VFS does (apparently deleting a file can sometimes fail on Windows). | 63 // VFS does (apparently deleting a file can sometimes fail on Windows). |
| 68 // We sleep for 10ms between retries for the same reason. | 64 // We sleep for 10ms between retries for the same reason. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 148 } |
| 153 | 149 |
| 154 void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { | 150 void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { |
| 155 DatabaseClosed(database.securityOrigin().databaseIdentifier(), | 151 DatabaseClosed(database.securityOrigin().databaseIdentifier(), |
| 156 database.name()); | 152 database.name()); |
| 157 } | 153 } |
| 158 | 154 |
| 159 void SimpleDatabaseSystem::ClearAllDatabases() { | 155 void SimpleDatabaseSystem::ClearAllDatabases() { |
| 160 // Wait for all databases to be closed. | 156 // Wait for all databases to be closed. |
| 161 if (!database_connections_.IsEmpty()) { | 157 if (!database_connections_.IsEmpty()) { |
| 162 AutoReset<bool> waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true)
; | 158 AutoReset<bool> waiting_for_dbs_auto_reset( |
| 159 &waiting_for_dbs_to_close_, true); |
| 163 MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current()); | 160 MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current()); |
| 164 MessageLoop::current()->Run(); | 161 MessageLoop::current()->Run(); |
| 165 } | 162 } |
| 166 | 163 |
| 167 db_tracker_->CloseTrackerDatabaseAndClearCaches(); | 164 db_tracker_->CloseTrackerDatabaseAndClearCaches(); |
| 168 file_util::Delete(db_tracker_->DatabaseDirectory(), true); | 165 file_util::Delete(db_tracker_->DatabaseDirectory(), true); |
| 169 file_names_.clear(); | 166 file_names_.clear(); |
| 170 } | 167 } |
| 171 | 168 |
| 172 void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) { | 169 void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 190 | 187 |
| 191 FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile( | 188 FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile( |
| 192 const string16& vfs_file_name) { | 189 const string16& vfs_file_name) { |
| 193 if (vfs_file_name.empty()) // temp file, used for vacuuming | 190 if (vfs_file_name.empty()) // temp file, used for vacuuming |
| 194 return FilePath(); | 191 return FilePath(); |
| 195 | 192 |
| 196 AutoLock file_names_auto_lock(file_names_lock_); | 193 AutoLock file_names_auto_lock(file_names_lock_); |
| 197 DCHECK(file_names_.find(vfs_file_name) != file_names_.end()); | 194 DCHECK(file_names_.find(vfs_file_name) != file_names_.end()); |
| 198 return file_names_[vfs_file_name]; | 195 return file_names_[vfs_file_name]; |
| 199 } | 196 } |
| OLD | NEW |