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 "webkit/support/simple_database_system.h" | 5 #include "webkit/support/simple_database_system.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // to better emulate what happens in chrome where this method is | 214 // to better emulate what happens in chrome where this method is |
215 // invoked on the background ipc thread. | 215 // invoked on the background ipc thread. |
216 WebKit::WebDatabase::closeDatabaseImmediately( | 216 WebKit::WebDatabase::closeDatabaseImmediately( |
217 origin_identifier, database_name); | 217 origin_identifier, database_name); |
218 } | 218 } |
219 | 219 |
220 void SimpleDatabaseSystem::VfsOpenFile( | 220 void SimpleDatabaseSystem::VfsOpenFile( |
221 const string16& vfs_file_name, int desired_flags, | 221 const string16& vfs_file_name, int desired_flags, |
222 base::PlatformFile* file_handle, base::WaitableEvent* done_event ) { | 222 base::PlatformFile* file_handle, base::WaitableEvent* done_event ) { |
223 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); | 223 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); |
224 FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); | 224 base::FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); |
225 if (file_name.empty()) { | 225 if (file_name.empty()) { |
226 VfsBackend::OpenTempFileInDirectory( | 226 VfsBackend::OpenTempFileInDirectory( |
227 db_tracker_->DatabaseDirectory(), desired_flags, file_handle); | 227 db_tracker_->DatabaseDirectory(), desired_flags, file_handle); |
228 } else { | 228 } else { |
229 VfsBackend::OpenFile(file_name, desired_flags, file_handle); | 229 VfsBackend::OpenFile(file_name, desired_flags, file_handle); |
230 } | 230 } |
231 done_event->Signal(); | 231 done_event->Signal(); |
232 } | 232 } |
233 | 233 |
234 void SimpleDatabaseSystem::VfsDeleteFile( | 234 void SimpleDatabaseSystem::VfsDeleteFile( |
235 const string16& vfs_file_name, bool sync_dir, | 235 const string16& vfs_file_name, bool sync_dir, |
236 int* result, base::WaitableEvent* done_event) { | 236 int* result, base::WaitableEvent* done_event) { |
237 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); | 237 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); |
238 // We try to delete the file multiple times, because that's what the default | 238 // We try to delete the file multiple times, because that's what the default |
239 // VFS does (apparently deleting a file can sometimes fail on Windows). | 239 // VFS does (apparently deleting a file can sometimes fail on Windows). |
240 // We sleep for 10ms between retries for the same reason. | 240 // We sleep for 10ms between retries for the same reason. |
241 const int kNumDeleteRetries = 3; | 241 const int kNumDeleteRetries = 3; |
242 int num_retries = 0; | 242 int num_retries = 0; |
243 *result = SQLITE_OK; | 243 *result = SQLITE_OK; |
244 FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); | 244 base::FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); |
245 do { | 245 do { |
246 *result = VfsBackend::DeleteFile(file_name, sync_dir); | 246 *result = VfsBackend::DeleteFile(file_name, sync_dir); |
247 } while ((++num_retries < kNumDeleteRetries) && | 247 } while ((++num_retries < kNumDeleteRetries) && |
248 (*result == SQLITE_IOERR_DELETE) && | 248 (*result == SQLITE_IOERR_DELETE) && |
249 (base::PlatformThread::Sleep( | 249 (base::PlatformThread::Sleep( |
250 base::TimeDelta::FromMilliseconds(10)), | 250 base::TimeDelta::FromMilliseconds(10)), |
251 1)); | 251 1)); |
252 | 252 |
253 done_event->Signal(); | 253 done_event->Signal(); |
254 } | 254 } |
(...skipping 25 matching lines...) Expand all Loading... |
280 if (db_tracker_->GetOriginInfo(origin_identifier, &info)) { | 280 if (db_tracker_->GetOriginInfo(origin_identifier, &info)) { |
281 int64 space_available = quota_per_origin_ - info.TotalSize(); | 281 int64 space_available = quota_per_origin_ - info.TotalSize(); |
282 *result = space_available < 0 ? 0 : space_available; | 282 *result = space_available < 0 ? 0 : space_available; |
283 } else { | 283 } else { |
284 NOTREACHED(); | 284 NOTREACHED(); |
285 *result = 0; | 285 *result = 0; |
286 } | 286 } |
287 done_event->Signal(); | 287 done_event->Signal(); |
288 } | 288 } |
289 | 289 |
290 FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile( | 290 base::FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile( |
291 const string16& vfs_file_name) { | 291 const string16& vfs_file_name) { |
292 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); | 292 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); |
293 if (vfs_file_name.empty()) // temp file, used for vacuuming | 293 if (vfs_file_name.empty()) // temp file, used for vacuuming |
294 return FilePath(); | 294 return base::FilePath(); |
295 return DatabaseUtil::GetFullFilePathForVfsFile( | 295 return DatabaseUtil::GetFullFilePathForVfsFile( |
296 db_tracker_.get(), vfs_file_name); | 296 db_tracker_.get(), vfs_file_name); |
297 } | 297 } |
298 | 298 |
299 void SimpleDatabaseSystem::ResetTracker() { | 299 void SimpleDatabaseSystem::ResetTracker() { |
300 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); | 300 DCHECK(db_thread_proxy_->BelongsToCurrentThread()); |
301 db_tracker_->CloseTrackerDatabaseAndClearCaches(); | 301 db_tracker_->CloseTrackerDatabaseAndClearCaches(); |
302 file_util::Delete(db_tracker_->DatabaseDirectory(), true); | 302 file_util::Delete(db_tracker_->DatabaseDirectory(), true); |
303 } | 303 } |
304 | 304 |
305 void SimpleDatabaseSystem::ThreadCleanup(base::WaitableEvent* done_event) { | 305 void SimpleDatabaseSystem::ThreadCleanup(base::WaitableEvent* done_event) { |
306 ResetTracker(); | 306 ResetTracker(); |
307 db_tracker_->RemoveObserver(this); | 307 db_tracker_->RemoveObserver(this); |
308 db_tracker_ = NULL; | 308 db_tracker_ = NULL; |
309 done_event->Signal(); | 309 done_event->Signal(); |
310 } | 310 } |
311 | 311 |
OLD | NEW |