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/fileapi/obfuscated_file_system_file_util.h" | 5 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 DropDatabases(); | 62 DropDatabases(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen( | 65 PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen( |
| 66 FileSystemOperationContext* context, | 66 FileSystemOperationContext* context, |
| 67 const FilePath& virtual_path, int file_flags, | 67 const FilePath& virtual_path, int file_flags, |
| 68 PlatformFile* file_handle, bool* created) { | 68 PlatformFile* file_handle, bool* created) { |
| 69 DCHECK(!(file_flags & (base::PLATFORM_FILE_DELETE_ON_CLOSE | | 69 DCHECK(!(file_flags & (base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 70 base::PLATFORM_FILE_HIDDEN | base::PLATFORM_FILE_EXCLUSIVE_READ | | 70 base::PLATFORM_FILE_HIDDEN | base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 71 base::PLATFORM_FILE_EXCLUSIVE_WRITE))); | 71 base::PLATFORM_FILE_EXCLUSIVE_WRITE))); |
| 72 FileSystemDirectoryDatabase* db = | 72 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 73 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 73 context->src_origin_url(), context->src_type(), true); |
| 74 if (!db) | 74 if (!db) |
| 75 return base::PLATFORM_FILE_ERROR_FAILED; | 75 return base::PLATFORM_FILE_ERROR_FAILED; |
| 76 FileId file_id; | 76 FileId file_id; |
| 77 if (!db->GetFileWithPath(virtual_path, &file_id)) { | 77 if (!db->GetFileWithPath(virtual_path, &file_id)) { |
| 78 // The file doesn't exist. | 78 // The file doesn't exist. |
| 79 if (!(file_flags & (base::PLATFORM_FILE_CREATE | | 79 if (!(file_flags & (base::PLATFORM_FILE_CREATE | |
| 80 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_ALWAYS))) | 80 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_ALWAYS))) |
| 81 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 81 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 82 FileId parent_id; | 82 FileId parent_id; |
| 83 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) | 83 if (!db->GetFileWithPath(virtual_path.DirName(), &parent_id)) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 104 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 104 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 105 context->src_type(), file_info.data_path); | 105 context->src_type(), file_info.data_path); |
| 106 return QuotaFileUtil::GetInstance()->CreateOrOpen( | 106 return QuotaFileUtil::GetInstance()->CreateOrOpen( |
| 107 context, data_path, file_flags, file_handle, created); | 107 context, data_path, file_flags, file_handle, created); |
| 108 } | 108 } |
| 109 | 109 |
| 110 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( | 110 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( |
| 111 FileSystemOperationContext* context, | 111 FileSystemOperationContext* context, |
| 112 const FilePath& virtual_path, | 112 const FilePath& virtual_path, |
| 113 bool* created) { | 113 bool* created) { |
| 114 FileSystemDirectoryDatabase* db = | 114 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 115 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 115 context->src_origin_url(), context->src_type(), true); |
| 116 if (!db) | 116 if (!db) |
| 117 return base::PLATFORM_FILE_ERROR_FAILED; | 117 return base::PLATFORM_FILE_ERROR_FAILED; |
| 118 FileId file_id; | 118 FileId file_id; |
| 119 if (db->GetFileWithPath(virtual_path, &file_id)) { | 119 if (db->GetFileWithPath(virtual_path, &file_id)) { |
| 120 FileInfo file_info; | 120 FileInfo file_info; |
| 121 if (!db->GetFileInfo(file_id, &file_info)) { | 121 if (!db->GetFileInfo(file_id, &file_info)) { |
| 122 NOTREACHED(); | 122 NOTREACHED(); |
| 123 return base::PLATFORM_FILE_ERROR_FAILED; | 123 return base::PLATFORM_FILE_ERROR_FAILED; |
| 124 } | 124 } |
| 125 if (file_info.is_directory()) | 125 if (file_info.is_directory()) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 153 | 153 |
| 154 *local_path = path; | 154 *local_path = path; |
| 155 return base::PLATFORM_FILE_OK; | 155 return base::PLATFORM_FILE_OK; |
| 156 } | 156 } |
| 157 | 157 |
| 158 PlatformFileError ObfuscatedFileSystemFileUtil::GetFileInfo( | 158 PlatformFileError ObfuscatedFileSystemFileUtil::GetFileInfo( |
| 159 FileSystemOperationContext* context, | 159 FileSystemOperationContext* context, |
| 160 const FilePath& virtual_path, | 160 const FilePath& virtual_path, |
| 161 base::PlatformFileInfo* file_info, | 161 base::PlatformFileInfo* file_info, |
| 162 FilePath* platform_file_path) { | 162 FilePath* platform_file_path) { |
| 163 FileSystemDirectoryDatabase* db = | 163 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 164 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 164 context->src_origin_url(), context->src_type(), false); |
| 165 if (!db) | 165 if (!db) |
| 166 return base::PLATFORM_FILE_ERROR_FAILED; | 166 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 167 FileId file_id; | 167 FileId file_id; |
| 168 if (!db->GetFileWithPath(virtual_path, &file_id)) | 168 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 169 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 169 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 170 FileInfo local_info; | 170 FileInfo local_info; |
| 171 if (!db->GetFileInfo(file_id, &local_info)) { | 171 if (!db->GetFileInfo(file_id, &local_info)) { |
| 172 NOTREACHED(); | 172 NOTREACHED(); |
| 173 return base::PLATFORM_FILE_ERROR_FAILED; | 173 return base::PLATFORM_FILE_ERROR_FAILED; |
| 174 } | 174 } |
| 175 if (local_info.is_directory()) { | 175 if (local_info.is_directory()) { |
| 176 file_info->is_directory = true; | 176 file_info->is_directory = true; |
| 177 file_info->is_symbolic_link = false; | 177 file_info->is_symbolic_link = false; |
| 178 file_info->last_modified = local_info.modification_time; | 178 file_info->last_modified = local_info.modification_time; |
| 179 *platform_file_path = FilePath(); | 179 *platform_file_path = FilePath(); |
| 180 // We don't fill in ctime or atime. | 180 // We don't fill in ctime or atime. |
| 181 return base::PLATFORM_FILE_OK; | 181 return base::PLATFORM_FILE_OK; |
| 182 } | 182 } |
| 183 if (local_info.data_path.empty()) | 183 if (local_info.data_path.empty()) |
| 184 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 184 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 185 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 185 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 186 context->src_type(), local_info.data_path); | 186 context->src_type(), local_info.data_path); |
| 187 return QuotaFileUtil::GetInstance()->GetFileInfo( | 187 return QuotaFileUtil::GetInstance()->GetFileInfo( |
| 188 context, data_path, file_info, platform_file_path); | 188 context, data_path, file_info, platform_file_path); |
| 189 } | 189 } |
| 190 | 190 |
| 191 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( | 191 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( |
| 192 FileSystemOperationContext* context, | 192 FileSystemOperationContext* context, |
| 193 const FilePath& virtual_path, | 193 const FilePath& virtual_path, |
| 194 std::vector<base::FileUtilProxy::Entry>* entries) { | 194 std::vector<base::FileUtilProxy::Entry>* entries) { |
| 195 // TODO(kkanetkar): Implement directory read in multiple chunks. | 195 // TODO(kkanetkar): Implement directory read in multiple chunks. |
| 196 FileSystemDirectoryDatabase* db = | 196 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 197 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 197 context->src_origin_url(), context->src_type(), false); |
| 198 if (!db) | 198 if (!db) { |
| 199 return base::PLATFORM_FILE_ERROR_FAILED; | 199 if (virtual_path.empty() || |
| 200 virtual_path.value() == FILE_PATH_LITERAL("/")) { | |
| 201 // It's the root directory and the database hasn't been initialized yet. | |
| 202 entries->clear(); | |
| 203 return base::PLATFORM_FILE_OK; | |
| 204 } | |
| 205 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 206 } | |
| 200 FileId file_id; | 207 FileId file_id; |
| 201 if (!db->GetFileWithPath(virtual_path, &file_id)) | 208 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 202 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 209 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 203 FileInfo file_info; | 210 FileInfo file_info; |
| 204 if (!db->GetFileInfo(file_id, &file_info)) { | 211 if (!db->GetFileInfo(file_id, &file_info)) { |
| 205 DCHECK(!file_id); | 212 DCHECK(!file_id); |
| 206 // It's the root directory and the database hasn't been initialized yet. | 213 // It's the root directory and the database hasn't been initialized yet. |
| 207 entries->clear(); | 214 entries->clear(); |
| 208 return base::PLATFORM_FILE_OK; | 215 return base::PLATFORM_FILE_OK; |
| 209 } | 216 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 226 entries->push_back(entry); | 233 entries->push_back(entry); |
| 227 } | 234 } |
| 228 return base::PLATFORM_FILE_OK; | 235 return base::PLATFORM_FILE_OK; |
| 229 } | 236 } |
| 230 | 237 |
| 231 PlatformFileError ObfuscatedFileSystemFileUtil::CreateDirectory( | 238 PlatformFileError ObfuscatedFileSystemFileUtil::CreateDirectory( |
| 232 FileSystemOperationContext* context, | 239 FileSystemOperationContext* context, |
| 233 const FilePath& virtual_path, | 240 const FilePath& virtual_path, |
| 234 bool exclusive, | 241 bool exclusive, |
| 235 bool recursive) { | 242 bool recursive) { |
| 236 FileSystemDirectoryDatabase* db = | 243 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 237 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 244 context->src_origin_url(), context->src_type(), true); |
| 238 if (!db) | 245 if (!db) |
| 239 return base::PLATFORM_FILE_ERROR_FAILED; | 246 return base::PLATFORM_FILE_ERROR_FAILED; |
| 240 FileId file_id; | 247 FileId file_id; |
| 241 if (db->GetFileWithPath(virtual_path, &file_id)) { | 248 if (db->GetFileWithPath(virtual_path, &file_id)) { |
| 242 FileInfo file_info; | 249 FileInfo file_info; |
| 243 if (exclusive) | 250 if (exclusive) |
| 244 return base::PLATFORM_FILE_ERROR_EXISTS; | 251 return base::PLATFORM_FILE_ERROR_EXISTS; |
| 245 if (!db->GetFileInfo(file_id, &file_info)) { | 252 if (!db->GetFileInfo(file_id, &file_info)) { |
| 246 NOTREACHED(); | 253 NOTREACHED(); |
| 247 return base::PLATFORM_FILE_ERROR_FAILED; | 254 return base::PLATFORM_FILE_ERROR_FAILED; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 277 } | 284 } |
| 278 } | 285 } |
| 279 return base::PLATFORM_FILE_OK; | 286 return base::PLATFORM_FILE_OK; |
| 280 } | 287 } |
| 281 | 288 |
| 282 PlatformFileError ObfuscatedFileSystemFileUtil::CopyOrMoveFile( | 289 PlatformFileError ObfuscatedFileSystemFileUtil::CopyOrMoveFile( |
| 283 FileSystemOperationContext* context, | 290 FileSystemOperationContext* context, |
| 284 const FilePath& src_file_path, | 291 const FilePath& src_file_path, |
| 285 const FilePath& dest_file_path, | 292 const FilePath& dest_file_path, |
| 286 bool copy) { | 293 bool copy) { |
| 287 FileSystemDirectoryDatabase* db = | 294 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 288 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 295 context->src_origin_url(), context->src_type(), true); |
| 289 if (!db) | 296 if (!db) |
| 290 return base::PLATFORM_FILE_ERROR_FAILED; | 297 return base::PLATFORM_FILE_ERROR_FAILED; |
| 291 FileId src_file_id; | 298 FileId src_file_id; |
| 292 if (!db->GetFileWithPath(src_file_path, &src_file_id)) | 299 if (!db->GetFileWithPath(src_file_path, &src_file_id)) |
| 293 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 300 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 294 FileId dest_file_id; | 301 FileId dest_file_id; |
| 295 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); | 302 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); |
| 296 FileInfo src_file_info; | 303 FileInfo src_file_info; |
| 297 FileInfo dest_file_info; | 304 FileInfo dest_file_info; |
| 298 if (!db->GetFileInfo(src_file_id, &src_file_info) || | 305 if (!db->GetFileInfo(src_file_id, &src_file_info) || |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 } | 372 } |
| 366 } | 373 } |
| 367 NOTREACHED(); | 374 NOTREACHED(); |
| 368 return base::PLATFORM_FILE_ERROR_FAILED; | 375 return base::PLATFORM_FILE_ERROR_FAILED; |
| 369 } | 376 } |
| 370 | 377 |
| 371 PlatformFileError ObfuscatedFileSystemFileUtil::CopyInForeignFile( | 378 PlatformFileError ObfuscatedFileSystemFileUtil::CopyInForeignFile( |
| 372 FileSystemOperationContext* context, | 379 FileSystemOperationContext* context, |
| 373 const FilePath& src_file_path, | 380 const FilePath& src_file_path, |
| 374 const FilePath& dest_file_path) { | 381 const FilePath& dest_file_path) { |
| 375 FileSystemDirectoryDatabase* db = | 382 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 376 GetDirectoryDatabase(context->dest_origin_url(), context->dest_type()); | 383 context->dest_origin_url(), context->dest_type(), true); |
| 377 if (!db) | 384 if (!db) |
| 378 return base::PLATFORM_FILE_ERROR_FAILED; | 385 return base::PLATFORM_FILE_ERROR_FAILED; |
| 379 FileId dest_file_id; | 386 FileId dest_file_id; |
| 380 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); | 387 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); |
| 381 FileInfo dest_file_info; | 388 FileInfo dest_file_info; |
| 382 if (overwrite) { | 389 if (overwrite) { |
| 383 if (!db->GetFileInfo(dest_file_id, &dest_file_info) || | 390 if (!db->GetFileInfo(dest_file_id, &dest_file_info) || |
| 384 dest_file_info.is_directory()) { | 391 dest_file_info.is_directory()) { |
| 385 NOTREACHED(); | 392 NOTREACHED(); |
| 386 return base::PLATFORM_FILE_ERROR_FAILED; | 393 return base::PLATFORM_FILE_ERROR_FAILED; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 399 dest_file_path.BaseName().value()); | 406 dest_file_path.BaseName().value()); |
| 400 return CreateFile(context, context->dest_origin_url(), | 407 return CreateFile(context, context->dest_origin_url(), |
| 401 context->dest_type(), src_file_path, &dest_file_info, 0, NULL); | 408 context->dest_type(), src_file_path, &dest_file_info, 0, NULL); |
| 402 } | 409 } |
| 403 return base::PLATFORM_FILE_ERROR_FAILED; | 410 return base::PLATFORM_FILE_ERROR_FAILED; |
| 404 } | 411 } |
| 405 | 412 |
| 406 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteFile( | 413 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteFile( |
| 407 FileSystemOperationContext* context, | 414 FileSystemOperationContext* context, |
| 408 const FilePath& virtual_path) { | 415 const FilePath& virtual_path) { |
| 409 FileSystemDirectoryDatabase* db = | 416 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 410 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 417 context->src_origin_url(), context->src_type(), true); |
| 411 if (!db) | 418 if (!db) |
| 412 return base::PLATFORM_FILE_ERROR_FAILED; | 419 return base::PLATFORM_FILE_ERROR_FAILED; |
| 413 FileId file_id; | 420 FileId file_id; |
| 414 if (!db->GetFileWithPath(virtual_path, &file_id)) | 421 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 415 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 422 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 416 FileInfo file_info; | 423 FileInfo file_info; |
| 417 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { | 424 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { |
| 418 NOTREACHED(); | 425 NOTREACHED(); |
| 419 return base::PLATFORM_FILE_ERROR_FAILED; | 426 return base::PLATFORM_FILE_ERROR_FAILED; |
| 420 } | 427 } |
| 421 if (!db->RemoveFileInfo(file_id)) { | 428 if (!db->RemoveFileInfo(file_id)) { |
| 422 NOTREACHED(); | 429 NOTREACHED(); |
| 423 return base::PLATFORM_FILE_ERROR_FAILED; | 430 return base::PLATFORM_FILE_ERROR_FAILED; |
| 424 } | 431 } |
| 425 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 432 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 426 context->src_type(), file_info.data_path); | 433 context->src_type(), file_info.data_path); |
| 427 if (base::PLATFORM_FILE_OK != | 434 if (base::PLATFORM_FILE_OK != |
| 428 QuotaFileUtil::GetInstance()->DeleteFile(context, data_path)) | 435 QuotaFileUtil::GetInstance()->DeleteFile(context, data_path)) |
| 429 LOG(WARNING) << "Leaked a backing file."; | 436 LOG(WARNING) << "Leaked a backing file."; |
| 430 return base::PLATFORM_FILE_OK; | 437 return base::PLATFORM_FILE_OK; |
| 431 } | 438 } |
| 432 | 439 |
| 433 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( | 440 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( |
| 434 FileSystemOperationContext* context, | 441 FileSystemOperationContext* context, |
| 435 const FilePath& virtual_path) { | 442 const FilePath& virtual_path) { |
| 436 FileSystemDirectoryDatabase* db = | 443 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 437 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 444 context->src_origin_url(), context->src_type(), true); |
| 438 if (!db) | 445 if (!db) |
| 439 return base::PLATFORM_FILE_ERROR_FAILED; | 446 return base::PLATFORM_FILE_ERROR_FAILED; |
| 440 FileId file_id; | 447 FileId file_id; |
| 441 if (!db->GetFileWithPath(virtual_path, &file_id)) | 448 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 442 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 449 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 443 FileInfo file_info; | 450 FileInfo file_info; |
| 444 if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) { | 451 if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) { |
| 445 NOTREACHED(); | 452 NOTREACHED(); |
| 446 return base::PLATFORM_FILE_ERROR_FAILED; | 453 return base::PLATFORM_FILE_ERROR_FAILED; |
| 447 } | 454 } |
| 448 if (!db->RemoveFileInfo(file_id)) | 455 if (!db->RemoveFileInfo(file_id)) |
| 449 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 456 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
| 450 return base::PLATFORM_FILE_OK; | 457 return base::PLATFORM_FILE_OK; |
| 451 } | 458 } |
| 452 | 459 |
| 453 PlatformFileError ObfuscatedFileSystemFileUtil::Touch( | 460 PlatformFileError ObfuscatedFileSystemFileUtil::Touch( |
| 454 FileSystemOperationContext* context, | 461 FileSystemOperationContext* context, |
| 455 const FilePath& virtual_path, | 462 const FilePath& virtual_path, |
| 456 const base::Time& last_access_time, | 463 const base::Time& last_access_time, |
| 457 const base::Time& last_modified_time) { | 464 const base::Time& last_modified_time) { |
| 458 FileSystemDirectoryDatabase* db = | 465 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 459 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 466 context->src_origin_url(), context->src_type(), true); |
| 460 if (!db) | 467 if (!db) |
| 461 return base::PLATFORM_FILE_ERROR_FAILED; | 468 return base::PLATFORM_FILE_ERROR_FAILED; |
| 462 FileId file_id; | 469 FileId file_id; |
| 463 if (db->GetFileWithPath(virtual_path, &file_id)) { | 470 if (db->GetFileWithPath(virtual_path, &file_id)) { |
| 464 FileInfo file_info; | 471 FileInfo file_info; |
| 465 if (!db->GetFileInfo(file_id, &file_info)) { | 472 if (!db->GetFileInfo(file_id, &file_info)) { |
| 466 NOTREACHED(); | 473 NOTREACHED(); |
| 467 return base::PLATFORM_FILE_ERROR_FAILED; | 474 return base::PLATFORM_FILE_ERROR_FAILED; |
| 468 } | 475 } |
| 469 if (file_info.is_directory()) { | 476 if (file_info.is_directory()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 virtual_path); | 512 virtual_path); |
| 506 if (local_path.empty()) | 513 if (local_path.empty()) |
| 507 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 514 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 508 return QuotaFileUtil::GetInstance()->Truncate( | 515 return QuotaFileUtil::GetInstance()->Truncate( |
| 509 context, local_path, length); | 516 context, local_path, length); |
| 510 } | 517 } |
| 511 | 518 |
| 512 bool ObfuscatedFileSystemFileUtil::PathExists( | 519 bool ObfuscatedFileSystemFileUtil::PathExists( |
| 513 FileSystemOperationContext* context, | 520 FileSystemOperationContext* context, |
| 514 const FilePath& virtual_path) { | 521 const FilePath& virtual_path) { |
| 515 FileSystemDirectoryDatabase* db = | 522 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 516 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 523 context->src_origin_url(), context->src_type(), false); |
| 517 if (!db) | 524 if (!db) |
| 518 return false; | 525 return false; |
| 519 FileId file_id; | 526 FileId file_id; |
| 520 return db->GetFileWithPath(virtual_path, &file_id); | 527 return db->GetFileWithPath(virtual_path, &file_id); |
| 521 } | 528 } |
| 522 | 529 |
| 523 bool ObfuscatedFileSystemFileUtil::DirectoryExists( | 530 bool ObfuscatedFileSystemFileUtil::DirectoryExists( |
| 524 FileSystemOperationContext* context, | 531 FileSystemOperationContext* context, |
| 525 const FilePath& virtual_path) { | 532 const FilePath& virtual_path) { |
| 526 FileSystemDirectoryDatabase* db = | 533 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
|
michaeln
2011/07/05 19:10:12
What if the query is about the root directory, sho
kinuko
2011/07/06 07:44:14
Good question, and I don't have a good answer eith
| |
| 527 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 534 context->src_origin_url(), context->src_type(), false); |
| 528 if (!db) | 535 if (!db) |
| 529 return false; | 536 return false; |
| 530 FileId file_id; | 537 FileId file_id; |
| 531 if (!db->GetFileWithPath(virtual_path, &file_id)) | 538 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 532 return false; | 539 return false; |
| 533 FileInfo file_info; | 540 FileInfo file_info; |
| 534 if (!db->GetFileInfo(file_id, &file_info)) { | 541 if (!db->GetFileInfo(file_id, &file_info)) { |
| 535 NOTREACHED(); | 542 NOTREACHED(); |
| 536 return false; | 543 return false; |
| 537 } | 544 } |
| 538 return file_info.is_directory(); | 545 return file_info.is_directory(); |
| 539 } | 546 } |
| 540 | 547 |
| 541 bool ObfuscatedFileSystemFileUtil::IsDirectoryEmpty( | 548 bool ObfuscatedFileSystemFileUtil::IsDirectoryEmpty( |
| 542 FileSystemOperationContext* context, | 549 FileSystemOperationContext* context, |
| 543 const FilePath& virtual_path) { | 550 const FilePath& virtual_path) { |
| 544 FileSystemDirectoryDatabase* db = | 551 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 545 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 552 context->src_origin_url(), context->src_type(), false); |
| 546 if (!db) | 553 if (!db) |
| 547 return false; | 554 return true; // Not a great answer, but it's what others do. |
| 548 FileId file_id; | 555 FileId file_id; |
| 549 if (!db->GetFileWithPath(virtual_path, &file_id)) | 556 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 550 return true; // Not a great answer, but it's what others do. | 557 return true; // Ditto. |
| 551 FileInfo file_info; | 558 FileInfo file_info; |
| 552 if (!db->GetFileInfo(file_id, &file_info)) { | 559 if (!db->GetFileInfo(file_id, &file_info)) { |
| 553 DCHECK(!file_id); | 560 DCHECK(!file_id); |
| 554 // It's the root directory and the database hasn't been initialized yet. | 561 // It's the root directory and the database hasn't been initialized yet. |
| 555 return true; | 562 return true; |
| 556 } | 563 } |
| 557 if (!file_info.is_directory()) | 564 if (!file_info.is_directory()) |
| 558 return true; | 565 return true; |
| 559 std::vector<FileId> children; | 566 std::vector<FileId> children; |
| 560 // TODO(ericu): This could easily be made faster with help from the database. | 567 // TODO(ericu): This could easily be made faster with help from the database. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 | 692 |
| 686 InitOriginDatabase(false); | 693 InitOriginDatabase(false); |
| 687 return new ObfuscatedFileSystemOriginEnumerator( | 694 return new ObfuscatedFileSystemOriginEnumerator( |
| 688 origin_database_.get(), file_system_directory_); | 695 origin_database_.get(), file_system_directory_); |
| 689 } | 696 } |
| 690 | 697 |
| 691 FileSystemFileUtil::AbstractFileEnumerator* | 698 FileSystemFileUtil::AbstractFileEnumerator* |
| 692 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( | 699 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( |
| 693 FileSystemOperationContext* context, | 700 FileSystemOperationContext* context, |
| 694 const FilePath& root_path) { | 701 const FilePath& root_path) { |
| 695 FileSystemDirectoryDatabase* db = | 702 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 696 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 703 context->src_origin_url(), context->src_type(), false); |
| 697 if (!db) | 704 if (!db) |
| 698 return new FileSystemFileUtil::EmptyFileEnumerator(); | 705 return new FileSystemFileUtil::EmptyFileEnumerator(); |
| 699 return new ObfuscatedFileSystemFileEnumerator(db, root_path); | 706 return new ObfuscatedFileSystemFileEnumerator(db, root_path); |
| 700 } | 707 } |
| 701 | 708 |
| 702 PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile( | 709 PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile( |
| 703 FileSystemOperationContext* context, | 710 FileSystemOperationContext* context, |
| 704 const GURL& origin_url, FileSystemType type, const FilePath& source_path, | 711 const GURL& origin_url, FileSystemType type, const FilePath& source_path, |
| 705 FileInfo* file_info, int file_flags, PlatformFile* handle) { | 712 FileInfo* file_info, int file_flags, PlatformFile* handle) { |
| 706 if (handle) | 713 if (handle) |
| 707 *handle = base::kInvalidPlatformFileValue; | 714 *handle = base::kInvalidPlatformFileValue; |
| 708 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type); | 715 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 716 origin_url, type, true); | |
| 709 int64 number; | 717 int64 number; |
| 710 if (!db || !db->GetNextInteger(&number)) | 718 if (!db || !db->GetNextInteger(&number)) |
| 711 return base::PLATFORM_FILE_ERROR_FAILED; | 719 return base::PLATFORM_FILE_ERROR_FAILED; |
| 712 // We use the third- and fourth-to-last digits as the directory. | 720 // We use the third- and fourth-to-last digits as the directory. |
| 713 int64 directory_number = number % 10000 / 100; | 721 int64 directory_number = number % 10000 / 100; |
| 714 FilePath path = | 722 FilePath path = |
| 715 GetDirectoryForOriginAndType(origin_url, type, false); | 723 GetDirectoryForOriginAndType(origin_url, type, false); |
| 716 if (path.empty()) | 724 if (path.empty()) |
| 717 return base::PLATFORM_FILE_ERROR_FAILED; | 725 return base::PLATFORM_FILE_ERROR_FAILED; |
| 718 | 726 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 return base::PLATFORM_FILE_ERROR_FAILED; | 775 return base::PLATFORM_FILE_ERROR_FAILED; |
| 768 } | 776 } |
| 769 | 777 |
| 770 return base::PLATFORM_FILE_OK; | 778 return base::PLATFORM_FILE_OK; |
| 771 } | 779 } |
| 772 | 780 |
| 773 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( | 781 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( |
| 774 const GURL& origin_url, | 782 const GURL& origin_url, |
| 775 FileSystemType type, | 783 FileSystemType type, |
| 776 const FilePath& virtual_path) { | 784 const FilePath& virtual_path) { |
| 777 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type); | 785 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 786 origin_url, type, false); | |
| 778 if (!db) | 787 if (!db) |
| 779 return FilePath(); | 788 return FilePath(); |
| 780 FileId file_id; | 789 FileId file_id; |
| 781 if (!db->GetFileWithPath(virtual_path, &file_id)) | 790 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 782 return FilePath(); | 791 return FilePath(); |
| 783 FileInfo file_info; | 792 FileInfo file_info; |
| 784 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { | 793 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { |
| 785 NOTREACHED(); | 794 NOTREACHED(); |
| 786 return FilePath(); // Directories have no local path. | 795 return FilePath(); // Directories have no local path. |
| 787 } | 796 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 return path; | 831 return path; |
| 823 } | 832 } |
| 824 | 833 |
| 825 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( | 834 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( |
| 826 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { | 835 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { |
| 827 if (!DestroyDirectoryDatabase(origin_url, type)) | 836 if (!DestroyDirectoryDatabase(origin_url, type)) |
| 828 return false; | 837 return false; |
| 829 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); | 838 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); |
| 830 if (dest_root.empty()) | 839 if (dest_root.empty()) |
| 831 return false; | 840 return false; |
| 832 FileSystemDirectoryDatabase* db = GetDirectoryDatabase(origin_url, type); | 841 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 842 origin_url, type, false); | |
| 833 if (!db) | 843 if (!db) |
| 834 return false; | 844 return false; |
| 835 | 845 |
| 836 file_util::FileEnumerator file_enum(src_root, true, | 846 file_util::FileEnumerator file_enum(src_root, true, |
| 837 static_cast<file_util::FileEnumerator::FILE_TYPE>( | 847 static_cast<file_util::FileEnumerator::FILE_TYPE>( |
| 838 file_util::FileEnumerator::FILES | | 848 file_util::FileEnumerator::FILES | |
| 839 file_util::FileEnumerator::DIRECTORIES)); | 849 file_util::FileEnumerator::DIRECTORIES)); |
| 840 FilePath src_full_path; | 850 FilePath src_full_path; |
| 841 size_t root_path_length = src_root.value().length() + 1; // +1 for the slash | 851 size_t root_path_length = src_root.value().length() + 1; // +1 for the slash |
| 842 while (!(src_full_path = file_enum.Next()).empty()) { | 852 while (!(src_full_path = file_enum.Next()).empty()) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 return root; | 931 return root; |
| 922 // This removes the root, including the trailing slash, leaving a relative | 932 // This removes the root, including the trailing slash, leaving a relative |
| 923 // path. | 933 // path. |
| 924 return FilePath(local_path.value().substr(root.value().length() + 1)); | 934 return FilePath(local_path.value().substr(root.value().length() + 1)); |
| 925 } | 935 } |
| 926 | 936 |
| 927 // TODO: How to do the whole validation-without-creation thing? We may not have | 937 // TODO: How to do the whole validation-without-creation thing? We may not have |
| 928 // quota even to create the database. Ah, in that case don't even get here? | 938 // quota even to create the database. Ah, in that case don't even get here? |
| 929 // Still doesn't answer the quota issue, though. | 939 // Still doesn't answer the quota issue, though. |
| 930 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase( | 940 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase( |
| 931 const GURL& origin, FileSystemType type) { | 941 const GURL& origin, FileSystemType type, bool create) { |
| 932 | |
| 933 MarkUsed(); | |
| 934 std::string type_string = | 942 std::string type_string = |
| 935 FileSystemPathManager::GetFileSystemTypeString(type); | 943 FileSystemPathManager::GetFileSystemTypeString(type); |
| 936 if (type_string.empty()) { | 944 if (type_string.empty()) { |
| 937 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 945 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 938 return NULL; | 946 return NULL; |
| 939 } | 947 } |
| 940 std::string key = GetOriginIdentifierFromURL(origin) + type_string; | 948 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
| 941 DirectoryMap::iterator iter = directories_.find(key); | 949 DirectoryMap::iterator iter = directories_.find(key); |
| 942 if (iter != directories_.end()) | 950 if (iter != directories_.end()) { |
| 951 MarkUsed(); | |
| 943 return iter->second; | 952 return iter->second; |
| 953 } | |
| 944 | 954 |
| 945 FilePath path = GetDirectoryForOriginAndType(origin, type, true); | 955 FilePath path = GetDirectoryForOriginAndType(origin, type, create); |
| 946 if (path.empty()) | 956 if (path.empty()) |
| 947 return NULL; | 957 return NULL; |
| 948 if (!file_util::DirectoryExists(path)) { | 958 if (!file_util::DirectoryExists(path)) { |
| 949 if (!file_util::CreateDirectory(path)) { | 959 if (!file_util::CreateDirectory(path)) { |
| 950 LOG(WARNING) << "Failed to origin+type directory: " << path.value(); | 960 LOG(WARNING) << "Failed to origin+type directory: " << path.value(); |
| 951 return NULL; | 961 return NULL; |
| 952 } | 962 } |
| 953 } | 963 } |
| 964 MarkUsed(); | |
| 954 path = path.AppendASCII(kDirectoryDatabaseName); | 965 path = path.AppendASCII(kDirectoryDatabaseName); |
| 955 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); | 966 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); |
| 956 directories_[key] = database; | 967 directories_[key] = database; |
| 957 return database; | 968 return database; |
| 958 } | 969 } |
| 959 | 970 |
| 960 void ObfuscatedFileSystemFileUtil::MarkUsed() { | 971 void ObfuscatedFileSystemFileUtil::MarkUsed() { |
| 961 if (timer_.IsRunning()) | 972 if (timer_.IsRunning()) |
| 962 timer_.Reset(); | 973 timer_.Reset(); |
| 963 else | 974 else |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 return false; | 1015 return false; |
| 1005 } | 1016 } |
| 1006 origin_database_.reset( | 1017 origin_database_.reset( |
| 1007 new FileSystemOriginDatabase( | 1018 new FileSystemOriginDatabase( |
| 1008 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1019 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
| 1009 } | 1020 } |
| 1010 return true; | 1021 return true; |
| 1011 } | 1022 } |
| 1012 | 1023 |
| 1013 } // namespace fileapi | 1024 } // namespace fileapi |
| OLD | NEW |