| 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 "chrome/browser/renderer_host/database_dispatcher_host.h" | 5 #include "chrome/browser/renderer_host/database_dispatcher_host.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Scheduled by the IO thread on the file thread. | 152 // Scheduled by the IO thread on the file thread. |
| 153 // Opens the given database file, then schedules | 153 // Opens the given database file, then schedules |
| 154 // a task on the IO thread's message loop to send an IPC back to | 154 // a task on the IO thread's message loop to send an IPC back to |
| 155 // corresponding renderer process with the file handle. | 155 // corresponding renderer process with the file handle. |
| 156 void DatabaseDispatcherHost::DatabaseOpenFile(const string16& vfs_file_name, | 156 void DatabaseDispatcherHost::DatabaseOpenFile(const string16& vfs_file_name, |
| 157 int desired_flags, | 157 int desired_flags, |
| 158 IPC::Message* reply_msg) { | 158 IPC::Message* reply_msg) { |
| 159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 160 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
| 160 base::PlatformFile target_handle = base::kInvalidPlatformFileValue; | 161 base::PlatformFile target_handle = base::kInvalidPlatformFileValue; |
| 161 string16 origin_identifier; | 162 string16 origin_identifier; |
| 162 string16 database_name; | 163 string16 database_name; |
| 164 |
| 165 // When in incognito mode, we want to make sure that all DB files are |
| 166 // removed when the incognito profile goes away, so we add the |
| 167 // SQLITE_OPEN_DELETEONCLOSE flag when opening all files, and keep |
| 168 // open handles to them in the database tracker to make sure they're |
| 169 // around for as long as needed. |
| 163 if (vfs_file_name.empty()) { | 170 if (vfs_file_name.empty()) { |
| 164 VfsBackend::OpenTempFileInDirectory(db_tracker_->DatabaseDirectory(), | 171 VfsBackend::OpenTempFileInDirectory(db_tracker_->DatabaseDirectory(), |
| 165 desired_flags, process_handle_, | 172 desired_flags, &file_handle); |
| 166 &target_handle); | |
| 167 } else if (DatabaseUtil::CrackVfsFileName(vfs_file_name, &origin_identifier, | 173 } else if (DatabaseUtil::CrackVfsFileName(vfs_file_name, &origin_identifier, |
| 168 &database_name, NULL) && | 174 &database_name, NULL) && |
| 169 !db_tracker_->IsDatabaseScheduledForDeletion(origin_identifier, | 175 !db_tracker_->IsDatabaseScheduledForDeletion(origin_identifier, |
| 170 database_name)) { | 176 database_name)) { |
| 171 FilePath db_file = | 177 FilePath db_file = |
| 172 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | 178 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); |
| 173 if (!db_file.empty()) { | 179 if (!db_file.empty()) { |
| 174 VfsBackend::OpenFile(db_file, desired_flags, process_handle_, | 180 if (db_tracker_->IsIncognitoProfile()) { |
| 175 &target_handle); | 181 db_tracker_->GetIncognitoFileHandle(vfs_file_name, &file_handle); |
| 182 if (file_handle == base::kInvalidPlatformFileValue) { |
| 183 VfsBackend::OpenFile(db_file, |
| 184 desired_flags | SQLITE_OPEN_DELETEONCLOSE, |
| 185 &file_handle); |
| 186 if (VfsBackend::FileTypeIsMainDB(desired_flags) || |
| 187 VfsBackend::FileTypeIsJournal(desired_flags)) |
| 188 db_tracker_->SaveIncognitoFileHandle(vfs_file_name, file_handle); |
| 189 } |
| 190 } else { |
| 191 VfsBackend::OpenFile(db_file, desired_flags, &file_handle); |
| 192 } |
| 176 } | 193 } |
| 177 } | 194 } |
| 178 | 195 |
| 196 // Then we duplicate the file handle to make it useable in the renderer |
| 197 // process. The original handle is closed, unless we saved it in the |
| 198 // database tracker. |
| 199 bool auto_close = !db_tracker_->HasSavedIncognitoFileHandle(vfs_file_name); |
| 200 VfsBackend::GetFileHandleForProcess(process_handle_, file_handle, |
| 201 &target_handle, auto_close); |
| 202 |
| 179 ViewHostMsg_DatabaseOpenFile::WriteReplyParams( | 203 ViewHostMsg_DatabaseOpenFile::WriteReplyParams( |
| 180 reply_msg, | 204 reply_msg, |
| 181 #if defined(OS_WIN) | 205 #if defined(OS_WIN) |
| 182 target_handle | 206 target_handle |
| 183 #elif defined(OS_POSIX) | 207 #elif defined(OS_POSIX) |
| 184 base::FileDescriptor(target_handle, true) | 208 base::FileDescriptor(target_handle, auto_close) |
| 185 #endif | 209 #endif |
| 186 ); | 210 ); |
| 187 Send(reply_msg); | 211 Send(reply_msg); |
| 188 } | 212 } |
| 189 | 213 |
| 190 void DatabaseDispatcherHost::OnDatabaseDeleteFile(const string16& vfs_file_name, | 214 void DatabaseDispatcherHost::OnDatabaseDeleteFile(const string16& vfs_file_name, |
| 191 const bool& sync_dir, | 215 const bool& sync_dir, |
| 192 IPC::Message* reply_msg) { | 216 IPC::Message* reply_msg) { |
| 193 ChromeThread::PostTask( | 217 ChromeThread::PostTask( |
| 194 ChromeThread::FILE, FROM_HERE, | 218 ChromeThread::FILE, FROM_HERE, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 209 IPC::Message* reply_msg, | 233 IPC::Message* reply_msg, |
| 210 int reschedule_count) { | 234 int reschedule_count) { |
| 211 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 235 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 212 | 236 |
| 213 // Return an error if the file name is invalid or if the file could not | 237 // Return an error if the file name is invalid or if the file could not |
| 214 // be deleted after kNumDeleteRetries attempts. | 238 // be deleted after kNumDeleteRetries attempts. |
| 215 int error_code = SQLITE_IOERR_DELETE; | 239 int error_code = SQLITE_IOERR_DELETE; |
| 216 FilePath db_file = | 240 FilePath db_file = |
| 217 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | 241 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); |
| 218 if (!db_file.empty()) { | 242 if (!db_file.empty()) { |
| 219 error_code = VfsBackend::DeleteFile(db_file, sync_dir); | 243 // In order to delete a journal file in incognito mode, we only need to |
| 244 // close the open handle to it that's stored in the database tracker. |
| 245 if (db_tracker_->IsIncognitoProfile()) { |
| 246 if (db_tracker_->CloseIncognitoFileHandle(vfs_file_name)) |
| 247 error_code = SQLITE_OK; |
| 248 } else { |
| 249 error_code = VfsBackend::DeleteFile(db_file, sync_dir); |
| 250 } |
| 251 |
| 220 if ((error_code == SQLITE_IOERR_DELETE) && reschedule_count) { | 252 if ((error_code == SQLITE_IOERR_DELETE) && reschedule_count) { |
| 221 // If the file could not be deleted, try again. | 253 // If the file could not be deleted, try again. |
| 222 ChromeThread::PostDelayedTask( | 254 ChromeThread::PostDelayedTask( |
| 223 ChromeThread::FILE, FROM_HERE, | 255 ChromeThread::FILE, FROM_HERE, |
| 224 NewRunnableMethod(this, | 256 NewRunnableMethod(this, |
| 225 &DatabaseDispatcherHost::DatabaseDeleteFile, | 257 &DatabaseDispatcherHost::DatabaseDeleteFile, |
| 226 vfs_file_name, | 258 vfs_file_name, |
| 227 sync_dir, | 259 sync_dir, |
| 228 reply_msg, | 260 reply_msg, |
| 229 reschedule_count - 1), | 261 reschedule_count - 1), |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 database_size, space_available)); | 451 database_size, space_available)); |
| 420 } | 452 } |
| 421 } | 453 } |
| 422 | 454 |
| 423 void DatabaseDispatcherHost::OnDatabaseScheduledForDeletion( | 455 void DatabaseDispatcherHost::OnDatabaseScheduledForDeletion( |
| 424 const string16& origin_identifier, | 456 const string16& origin_identifier, |
| 425 const string16& database_name) { | 457 const string16& database_name) { |
| 426 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 458 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 427 Send(new ViewMsg_DatabaseCloseImmediately(origin_identifier, database_name)); | 459 Send(new ViewMsg_DatabaseCloseImmediately(origin_identifier, database_name)); |
| 428 } | 460 } |
| OLD | NEW |