OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // 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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 SimpleDatabaseSystem::~SimpleDatabaseSystem() { | 39 SimpleDatabaseSystem::~SimpleDatabaseSystem() { |
40 instance_ = NULL; | 40 instance_ = NULL; |
41 } | 41 } |
42 | 42 |
43 base::PlatformFile SimpleDatabaseSystem::OpenFile( | 43 base::PlatformFile SimpleDatabaseSystem::OpenFile( |
44 const string16& vfs_file_name, int desired_flags, | 44 const string16& vfs_file_name, int desired_flags, |
45 base::PlatformFile* dir_handle) { | 45 base::PlatformFile* dir_handle) { |
46 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | 46 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
47 FilePath file_name = | 47 FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); |
48 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | |
49 if (file_name.empty()) { | 48 if (file_name.empty()) { |
50 VfsBackend::OpenTempFileInDirectory( | 49 VfsBackend::OpenTempFileInDirectory( |
51 db_tracker_->DatabaseDirectory(), desired_flags, | 50 db_tracker_->DatabaseDirectory(), desired_flags, |
52 base::GetCurrentProcessHandle(), &file_handle, dir_handle); | 51 base::GetCurrentProcessHandle(), &file_handle, dir_handle); |
53 } else { | 52 } else { |
54 VfsBackend::OpenFile(file_name, desired_flags, | 53 VfsBackend::OpenFile(file_name, desired_flags, |
55 base::GetCurrentProcessHandle(), &file_handle, | 54 base::GetCurrentProcessHandle(), &file_handle, |
56 dir_handle); | 55 dir_handle); |
57 } | 56 } |
58 | 57 |
59 return file_handle; | 58 return file_handle; |
60 } | 59 } |
61 | 60 |
62 int SimpleDatabaseSystem::DeleteFile( | 61 int SimpleDatabaseSystem::DeleteFile( |
63 const string16& vfs_file_name, bool sync_dir) { | 62 const string16& vfs_file_name, bool sync_dir) { |
64 // We try to delete the file multiple times, because that's what the default | 63 // We try to delete the file multiple times, because that's what the default |
65 // VFS does (apparently deleting a file can sometimes fail on Windows). | 64 // VFS does (apparently deleting a file can sometimes fail on Windows). |
66 // We sleep for 10ms between retries for the same reason. | 65 // We sleep for 10ms between retries for the same reason. |
67 const int kNumDeleteRetries = 3; | 66 const int kNumDeleteRetries = 3; |
68 int num_retries = 0; | 67 int num_retries = 0; |
69 int error_code = SQLITE_OK; | 68 int error_code = SQLITE_OK; |
70 FilePath file_name = | 69 FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); |
71 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | |
72 do { | 70 do { |
73 error_code = VfsBackend::DeleteFile(file_name, sync_dir); | 71 error_code = VfsBackend::DeleteFile(file_name, sync_dir); |
74 } while ((++num_retries < kNumDeleteRetries) && | 72 } while ((++num_retries < kNumDeleteRetries) && |
75 (error_code == SQLITE_IOERR_DELETE) && | 73 (error_code == SQLITE_IOERR_DELETE) && |
76 (PlatformThread::Sleep(10), 1)); | 74 (PlatformThread::Sleep(10), 1)); |
77 | 75 |
78 return error_code; | 76 return error_code; |
79 } | 77 } |
80 | 78 |
81 long SimpleDatabaseSystem::GetFileAttributes(const string16& vfs_file_name) { | 79 long SimpleDatabaseSystem::GetFileAttributes(const string16& vfs_file_name) { |
82 return VfsBackend::GetFileAttributes( | 80 return VfsBackend::GetFileAttributes( |
83 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name)); | 81 GetFullFilePathForVfsFile(vfs_file_name)); |
84 } | 82 } |
85 | 83 |
86 long long SimpleDatabaseSystem::GetFileSize(const string16& vfs_file_name) { | 84 long long SimpleDatabaseSystem::GetFileSize(const string16& vfs_file_name) { |
87 return VfsBackend::GetFileSize( | 85 return VfsBackend::GetFileSize(GetFullFilePathForVfsFile(vfs_file_name)); |
88 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name)); | |
89 } | 86 } |
90 | 87 |
91 void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier, | 88 void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier, |
92 const string16& database_name, | 89 const string16& database_name, |
93 const string16& description, | 90 const string16& description, |
94 int64 estimated_size) { | 91 int64 estimated_size) { |
95 int64 database_size = 0; | 92 int64 database_size = 0; |
96 int64 space_available = 0; | 93 int64 space_available = 0; |
97 db_tracker_->DatabaseOpened(origin_identifier, database_name, description, | 94 db_tracker_->DatabaseOpened(origin_identifier, database_name, description, |
98 estimated_size, &database_size, &space_available); | 95 estimated_size, &database_size, &space_available); |
| 96 SetFullFilePathsForVfsFile(origin_identifier, database_name); |
| 97 |
99 OnDatabaseSizeChanged(origin_identifier, database_name, | 98 OnDatabaseSizeChanged(origin_identifier, database_name, |
100 database_size, space_available); | 99 database_size, space_available); |
101 } | 100 } |
102 | 101 |
103 void SimpleDatabaseSystem::DatabaseModified(const string16& origin_identifier, | 102 void SimpleDatabaseSystem::DatabaseModified(const string16& origin_identifier, |
104 const string16& database_name) { | 103 const string16& database_name) { |
105 db_tracker_->DatabaseModified(origin_identifier, database_name); | 104 db_tracker_->DatabaseModified(origin_identifier, database_name); |
106 } | 105 } |
107 | 106 |
108 void SimpleDatabaseSystem::DatabaseClosed(const string16& origin_identifier, | 107 void SimpleDatabaseSystem::DatabaseClosed(const string16& origin_identifier, |
(...skipping 23 matching lines...) Expand all Loading... |
132 } | 131 } |
133 | 132 |
134 void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { | 133 void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { |
135 DatabaseClosed(database.securityOrigin().databaseIdentifier(), | 134 DatabaseClosed(database.securityOrigin().databaseIdentifier(), |
136 database.name()); | 135 database.name()); |
137 } | 136 } |
138 | 137 |
139 void SimpleDatabaseSystem::ClearAllDatabases() { | 138 void SimpleDatabaseSystem::ClearAllDatabases() { |
140 db_tracker_->CloseTrackerDatabaseAndClearCaches(); | 139 db_tracker_->CloseTrackerDatabaseAndClearCaches(); |
141 file_util::Delete(db_tracker_->DatabaseDirectory(), true); | 140 file_util::Delete(db_tracker_->DatabaseDirectory(), true); |
| 141 file_names_.clear(); |
142 } | 142 } |
| 143 |
| 144 void SimpleDatabaseSystem::SetFullFilePathsForVfsFile( |
| 145 const string16& origin_identifier, |
| 146 const string16& database_name) { |
| 147 string16 vfs_file_name = origin_identifier + ASCIIToUTF16("/") + |
| 148 database_name + ASCIIToUTF16("#"); |
| 149 FilePath file_name = |
| 150 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); |
| 151 |
| 152 AutoLock file_names_auto_lock(file_names_lock_); |
| 153 file_names_[vfs_file_name] = file_name; |
| 154 file_names_[vfs_file_name + ASCIIToUTF16("-journal")] = |
| 155 FilePath::FromWStringHack(file_name.ToWStringHack() + |
| 156 ASCIIToWide("-journal")); |
| 157 } |
| 158 |
| 159 FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile( |
| 160 const string16& vfs_file_name) { |
| 161 AutoLock file_names_auto_lock(file_names_lock_); |
| 162 DCHECK(file_names_.find(vfs_file_name) != file_names_.end()); |
| 163 return file_names_[vfs_file_name]; |
| 164 } |
OLD | NEW |