| 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_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" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"); | 48 const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"); |
| 49 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); | 49 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 namespace fileapi { | 53 namespace fileapi { |
| 54 | 54 |
| 55 using base::PlatformFile; | 55 using base::PlatformFile; |
| 56 using base::PlatformFileError; | 56 using base::PlatformFileError; |
| 57 | 57 |
| 58 ObfuscatedFileSystemFileUtil::ObfuscatedFileSystemFileUtil( | 58 ObfuscatedFileUtil::ObfuscatedFileUtil( |
| 59 const FilePath& file_system_directory, | 59 const FilePath& file_system_directory, |
| 60 FileSystemFileUtil* underlying_file_util) | 60 FileApiFileUtil* underlying_file_util) |
| 61 : file_system_directory_(file_system_directory), | 61 : OverlayFileUtil(underlying_file_util), |
| 62 underlying_file_util_(underlying_file_util) { | 62 file_system_directory_(file_system_directory) { |
| 63 } | 63 } |
| 64 | 64 |
| 65 ObfuscatedFileSystemFileUtil::~ObfuscatedFileSystemFileUtil() { | 65 ObfuscatedFileUtil::~ObfuscatedFileUtil() { |
| 66 DropDatabases(); | 66 DropDatabases(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen( | 69 PlatformFileError ObfuscatedFileUtil::CreateOrOpen( |
| 70 FileSystemOperationContext* context, | 70 FileSystemOperationContext* context, |
| 71 const FilePath& virtual_path, int file_flags, | 71 const FilePath& virtual_path, int file_flags, |
| 72 PlatformFile* file_handle, bool* created) { | 72 PlatformFile* file_handle, bool* created) { |
| 73 DCHECK(!(file_flags & (base::PLATFORM_FILE_DELETE_ON_CLOSE | | 73 DCHECK(!(file_flags & (base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 74 base::PLATFORM_FILE_HIDDEN | base::PLATFORM_FILE_EXCLUSIVE_READ | | 74 base::PLATFORM_FILE_HIDDEN | base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 75 base::PLATFORM_FILE_EXCLUSIVE_WRITE))); | 75 base::PLATFORM_FILE_EXCLUSIVE_WRITE))); |
| 76 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 76 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 77 context->src_origin_url(), context->src_type(), true); | 77 context->src_origin_url(), context->src_type(), true); |
| 78 if (!db) | 78 if (!db) |
| 79 return base::PLATFORM_FILE_ERROR_FAILED; | 79 return base::PLATFORM_FILE_ERROR_FAILED; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 return base::PLATFORM_FILE_ERROR_FAILED; | 104 return base::PLATFORM_FILE_ERROR_FAILED; |
| 105 } | 105 } |
| 106 if (file_info.is_directory()) | 106 if (file_info.is_directory()) |
| 107 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 107 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 108 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 108 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 109 context->src_type(), file_info.data_path); | 109 context->src_type(), file_info.data_path); |
| 110 return underlying_file_util_->CreateOrOpen( | 110 return underlying_file_util_->CreateOrOpen( |
| 111 context, data_path, file_flags, file_handle, created); | 111 context, data_path, file_flags, file_handle, created); |
| 112 } | 112 } |
| 113 | 113 |
| 114 PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists( | 114 PlatformFileError ObfuscatedFileUtil::EnsureFileExists( |
| 115 FileSystemOperationContext* context, | 115 FileSystemOperationContext* context, |
| 116 const FilePath& virtual_path, | 116 const FilePath& virtual_path, |
| 117 bool* created) { | 117 bool* created) { |
| 118 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 118 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 119 context->src_origin_url(), context->src_type(), true); | 119 context->src_origin_url(), context->src_type(), true); |
| 120 if (!db) | 120 if (!db) |
| 121 return base::PLATFORM_FILE_ERROR_FAILED; | 121 return base::PLATFORM_FILE_ERROR_FAILED; |
| 122 FileId file_id; | 122 FileId file_id; |
| 123 if (db->GetFileWithPath(virtual_path, &file_id)) { | 123 if (db->GetFileWithPath(virtual_path, &file_id)) { |
| 124 FileInfo file_info; | 124 FileInfo file_info; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 138 | 138 |
| 139 FileInfo file_info; | 139 FileInfo file_info; |
| 140 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); | 140 InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value()); |
| 141 PlatformFileError error = CreateFile(context, context->src_origin_url(), | 141 PlatformFileError error = CreateFile(context, context->src_origin_url(), |
| 142 context->src_type(), FilePath(), &file_info, 0, NULL); | 142 context->src_type(), FilePath(), &file_info, 0, NULL); |
| 143 if (created && base::PLATFORM_FILE_OK == error) | 143 if (created && base::PLATFORM_FILE_OK == error) |
| 144 *created = true; | 144 *created = true; |
| 145 return error; | 145 return error; |
| 146 } | 146 } |
| 147 | 147 |
| 148 PlatformFileError ObfuscatedFileSystemFileUtil::GetLocalFilePath( | 148 PlatformFileError ObfuscatedFileUtil::GetLocalFilePath( |
| 149 FileSystemOperationContext* context, | 149 FileSystemOperationContext* context, |
| 150 const FilePath& virtual_path, | 150 const FilePath& virtual_path, |
| 151 FilePath* local_path) { | 151 FilePath* local_path) { |
| 152 FilePath path = | 152 FilePath path = |
| 153 GetLocalPath(context->src_origin_url(), context->src_type(), | 153 GetLocalPath(context->src_origin_url(), context->src_type(), |
| 154 virtual_path); | 154 virtual_path); |
| 155 if (path.empty()) | 155 if (path.empty()) |
| 156 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 156 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 157 | 157 |
| 158 *local_path = path; | 158 *local_path = path; |
| 159 return base::PLATFORM_FILE_OK; | 159 return base::PLATFORM_FILE_OK; |
| 160 } | 160 } |
| 161 | 161 |
| 162 PlatformFileError ObfuscatedFileSystemFileUtil::GetFileInfo( | 162 PlatformFileError ObfuscatedFileUtil::GetFileInfo( |
| 163 FileSystemOperationContext* context, | 163 FileSystemOperationContext* context, |
| 164 const FilePath& virtual_path, | 164 const FilePath& virtual_path, |
| 165 base::PlatformFileInfo* file_info, | 165 base::PlatformFileInfo* file_info, |
| 166 FilePath* platform_file_path) { | 166 FilePath* platform_file_path) { |
| 167 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 167 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 168 context->src_origin_url(), context->src_type(), false); | 168 context->src_origin_url(), context->src_type(), false); |
| 169 if (!db) | 169 if (!db) |
| 170 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 170 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 171 FileId file_id; | 171 FileId file_id; |
| 172 if (!db->GetFileWithPath(virtual_path, &file_id)) | 172 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 173 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 173 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 174 FileInfo local_info; | 174 FileInfo local_info; |
| 175 return GetFileInfoInternal(db, context, file_id, | 175 return GetFileInfoInternal(db, context, file_id, |
| 176 &local_info, file_info, platform_file_path); | 176 &local_info, file_info, platform_file_path); |
| 177 } | 177 } |
| 178 | 178 |
| 179 PlatformFileError ObfuscatedFileSystemFileUtil::ReadDirectory( | 179 PlatformFileError ObfuscatedFileUtil::ReadDirectory( |
| 180 FileSystemOperationContext* context, | 180 FileSystemOperationContext* context, |
| 181 const FilePath& virtual_path, | 181 const FilePath& virtual_path, |
| 182 std::vector<base::FileUtilProxy::Entry>* entries) { | 182 std::vector<base::FileUtilProxy::Entry>* entries) { |
| 183 // TODO(kkanetkar): Implement directory read in multiple chunks. | 183 // TODO(kkanetkar): Implement directory read in multiple chunks. |
| 184 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 184 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 185 context->src_origin_url(), context->src_type(), false); | 185 context->src_origin_url(), context->src_type(), false); |
| 186 if (!db) { | 186 if (!db) { |
| 187 if (IsRootDirectory(virtual_path)) { | 187 if (IsRootDirectory(virtual_path)) { |
| 188 // It's the root directory and the database hasn't been initialized yet. | 188 // It's the root directory and the database hasn't been initialized yet. |
| 189 entries->clear(); | 189 entries->clear(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 base::FileUtilProxy::Entry entry; | 222 base::FileUtilProxy::Entry entry; |
| 223 entry.name = file_info.name; | 223 entry.name = file_info.name; |
| 224 entry.is_directory = file_info.is_directory(); | 224 entry.is_directory = file_info.is_directory(); |
| 225 entry.size = entry.is_directory ? 0 : platform_file_info.size; | 225 entry.size = entry.is_directory ? 0 : platform_file_info.size; |
| 226 entry.last_modified_time = platform_file_info.last_modified; | 226 entry.last_modified_time = platform_file_info.last_modified; |
| 227 entries->push_back(entry); | 227 entries->push_back(entry); |
| 228 } | 228 } |
| 229 return base::PLATFORM_FILE_OK; | 229 return base::PLATFORM_FILE_OK; |
| 230 } | 230 } |
| 231 | 231 |
| 232 PlatformFileError ObfuscatedFileSystemFileUtil::CreateDirectory( | 232 PlatformFileError ObfuscatedFileUtil::CreateDirectory( |
| 233 FileSystemOperationContext* context, | 233 FileSystemOperationContext* context, |
| 234 const FilePath& virtual_path, | 234 const FilePath& virtual_path, |
| 235 bool exclusive, | 235 bool exclusive, |
| 236 bool recursive) { | 236 bool recursive) { |
| 237 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 237 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 238 context->src_origin_url(), context->src_type(), true); | 238 context->src_origin_url(), context->src_type(), true); |
| 239 if (!db) | 239 if (!db) |
| 240 return base::PLATFORM_FILE_ERROR_FAILED; | 240 return base::PLATFORM_FILE_ERROR_FAILED; |
| 241 FileId file_id; | 241 FileId file_id; |
| 242 if (db->GetFileWithPath(virtual_path, &file_id)) { | 242 if (db->GetFileWithPath(virtual_path, &file_id)) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 file_info.modification_time = base::Time::Now(); | 279 file_info.modification_time = base::Time::Now(); |
| 280 file_info.parent_id = parent_id; | 280 file_info.parent_id = parent_id; |
| 281 if (!db->AddFileInfo(file_info, &parent_id)) { | 281 if (!db->AddFileInfo(file_info, &parent_id)) { |
| 282 NOTREACHED(); | 282 NOTREACHED(); |
| 283 return base::PLATFORM_FILE_ERROR_FAILED; | 283 return base::PLATFORM_FILE_ERROR_FAILED; |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 return base::PLATFORM_FILE_OK; | 286 return base::PLATFORM_FILE_OK; |
| 287 } | 287 } |
| 288 | 288 |
| 289 PlatformFileError ObfuscatedFileSystemFileUtil::CopyOrMoveFile( | 289 PlatformFileError ObfuscatedFileUtil::CopyOrMoveFile( |
| 290 FileSystemOperationContext* context, | 290 FileSystemOperationContext* context, |
| 291 const FilePath& src_file_path, | 291 const FilePath& src_file_path, |
| 292 const FilePath& dest_file_path, | 292 const FilePath& dest_file_path, |
| 293 bool copy) { | 293 bool copy) { |
| 294 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 294 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 295 context->src_origin_url(), context->src_type(), true); | 295 context->src_origin_url(), context->src_type(), true); |
| 296 if (!db) | 296 if (!db) |
| 297 return base::PLATFORM_FILE_ERROR_FAILED; | 297 return base::PLATFORM_FILE_ERROR_FAILED; |
| 298 FileId src_file_id; | 298 FileId src_file_id; |
| 299 if (!db->GetFileWithPath(src_file_path, &src_file_id)) | 299 if (!db->GetFileWithPath(src_file_path, &src_file_id)) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 src_file_info.name = dest_file_path.BaseName().value(); | 368 src_file_info.name = dest_file_path.BaseName().value(); |
| 369 if (!db->UpdateFileInfo(src_file_id, src_file_info)) | 369 if (!db->UpdateFileInfo(src_file_id, src_file_info)) |
| 370 return base::PLATFORM_FILE_ERROR_FAILED; | 370 return base::PLATFORM_FILE_ERROR_FAILED; |
| 371 return base::PLATFORM_FILE_OK; | 371 return base::PLATFORM_FILE_OK; |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 NOTREACHED(); | 374 NOTREACHED(); |
| 375 return base::PLATFORM_FILE_ERROR_FAILED; | 375 return base::PLATFORM_FILE_ERROR_FAILED; |
| 376 } | 376 } |
| 377 | 377 |
| 378 PlatformFileError ObfuscatedFileSystemFileUtil::CopyInForeignFile( | 378 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( |
| 379 FileSystemOperationContext* context, | 379 FileSystemOperationContext* context, |
| 380 const FilePath& src_file_path, | 380 const FilePath& src_file_path, |
| 381 const FilePath& dest_file_path) { | 381 const FilePath& dest_file_path) { |
| 382 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 382 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 383 context->dest_origin_url(), context->dest_type(), true); | 383 context->dest_origin_url(), context->dest_type(), true); |
| 384 if (!db) | 384 if (!db) |
| 385 return base::PLATFORM_FILE_ERROR_FAILED; | 385 return base::PLATFORM_FILE_ERROR_FAILED; |
| 386 FileId dest_file_id; | 386 FileId dest_file_id; |
| 387 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); | 387 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); |
| 388 FileInfo dest_file_info; | 388 FileInfo dest_file_info; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 403 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 403 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 404 } | 404 } |
| 405 InitFileInfo(&dest_file_info, dest_parent_id, | 405 InitFileInfo(&dest_file_info, dest_parent_id, |
| 406 dest_file_path.BaseName().value()); | 406 dest_file_path.BaseName().value()); |
| 407 return CreateFile(context, context->dest_origin_url(), | 407 return CreateFile(context, context->dest_origin_url(), |
| 408 context->dest_type(), src_file_path, &dest_file_info, 0, NULL); | 408 context->dest_type(), src_file_path, &dest_file_info, 0, NULL); |
| 409 } | 409 } |
| 410 return base::PLATFORM_FILE_ERROR_FAILED; | 410 return base::PLATFORM_FILE_ERROR_FAILED; |
| 411 } | 411 } |
| 412 | 412 |
| 413 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteFile( | 413 PlatformFileError ObfuscatedFileUtil::DeleteFile( |
| 414 FileSystemOperationContext* context, | 414 FileSystemOperationContext* context, |
| 415 const FilePath& virtual_path) { | 415 const FilePath& virtual_path) { |
| 416 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 416 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 417 context->src_origin_url(), context->src_type(), true); | 417 context->src_origin_url(), context->src_type(), true); |
| 418 if (!db) | 418 if (!db) |
| 419 return base::PLATFORM_FILE_ERROR_FAILED; | 419 return base::PLATFORM_FILE_ERROR_FAILED; |
| 420 FileId file_id; | 420 FileId file_id; |
| 421 if (!db->GetFileWithPath(virtual_path, &file_id)) | 421 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 422 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 422 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 423 FileInfo file_info; | 423 FileInfo file_info; |
| 424 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { | 424 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { |
| 425 NOTREACHED(); | 425 NOTREACHED(); |
| 426 return base::PLATFORM_FILE_ERROR_FAILED; | 426 return base::PLATFORM_FILE_ERROR_FAILED; |
| 427 } | 427 } |
| 428 if (!db->RemoveFileInfo(file_id)) { | 428 if (!db->RemoveFileInfo(file_id)) { |
| 429 NOTREACHED(); | 429 NOTREACHED(); |
| 430 return base::PLATFORM_FILE_ERROR_FAILED; | 430 return base::PLATFORM_FILE_ERROR_FAILED; |
| 431 } | 431 } |
| 432 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 432 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 433 context->src_type(), file_info.data_path); | 433 context->src_type(), file_info.data_path); |
| 434 if (base::PLATFORM_FILE_OK != | 434 if (base::PLATFORM_FILE_OK != |
| 435 underlying_file_util_->DeleteFile(context, data_path)) | 435 underlying_file_util_->DeleteFile(context, data_path)) |
| 436 LOG(WARNING) << "Leaked a backing file."; | 436 LOG(WARNING) << "Leaked a backing file."; |
| 437 return base::PLATFORM_FILE_OK; | 437 return base::PLATFORM_FILE_OK; |
| 438 } | 438 } |
| 439 | 439 |
| 440 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteSingleDirectory( | 440 PlatformFileError ObfuscatedFileUtil::DeleteSingleDirectory( |
| 441 FileSystemOperationContext* context, | 441 FileSystemOperationContext* context, |
| 442 const FilePath& virtual_path) { | 442 const FilePath& virtual_path) { |
| 443 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 443 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 444 context->src_origin_url(), context->src_type(), true); | 444 context->src_origin_url(), context->src_type(), true); |
| 445 if (!db) | 445 if (!db) |
| 446 return base::PLATFORM_FILE_ERROR_FAILED; | 446 return base::PLATFORM_FILE_ERROR_FAILED; |
| 447 FileId file_id; | 447 FileId file_id; |
| 448 if (!db->GetFileWithPath(virtual_path, &file_id)) | 448 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 449 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 449 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 450 FileInfo file_info; | 450 FileInfo file_info; |
| 451 if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) { | 451 if (!db->GetFileInfo(file_id, &file_info) || !file_info.is_directory()) { |
| 452 NOTREACHED(); | 452 NOTREACHED(); |
| 453 return base::PLATFORM_FILE_ERROR_FAILED; | 453 return base::PLATFORM_FILE_ERROR_FAILED; |
| 454 } | 454 } |
| 455 if (!db->RemoveFileInfo(file_id)) | 455 if (!db->RemoveFileInfo(file_id)) |
| 456 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 456 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
| 457 return base::PLATFORM_FILE_OK; | 457 return base::PLATFORM_FILE_OK; |
| 458 } | 458 } |
| 459 | 459 |
| 460 PlatformFileError ObfuscatedFileSystemFileUtil::Touch( | 460 PlatformFileError ObfuscatedFileUtil::Touch( |
| 461 FileSystemOperationContext* context, | 461 FileSystemOperationContext* context, |
| 462 const FilePath& virtual_path, | 462 const FilePath& virtual_path, |
| 463 const base::Time& last_access_time, | 463 const base::Time& last_access_time, |
| 464 const base::Time& last_modified_time) { | 464 const base::Time& last_modified_time) { |
| 465 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 465 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 466 context->src_origin_url(), context->src_type(), true); | 466 context->src_origin_url(), context->src_type(), true); |
| 467 if (!db) | 467 if (!db) |
| 468 return base::PLATFORM_FILE_ERROR_FAILED; | 468 return base::PLATFORM_FILE_ERROR_FAILED; |
| 469 FileId file_id; | 469 FileId file_id; |
| 470 if (db->GetFileWithPath(virtual_path, &file_id)) { | 470 if (db->GetFileWithPath(virtual_path, &file_id)) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 496 context->src_type(), FilePath(), &file_info, 0, NULL); | 496 context->src_type(), FilePath(), &file_info, 0, NULL); |
| 497 if (base::PLATFORM_FILE_OK != error) | 497 if (base::PLATFORM_FILE_OK != error) |
| 498 return error; | 498 return error; |
| 499 | 499 |
| 500 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 500 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 501 context->src_type(), file_info.data_path); | 501 context->src_type(), file_info.data_path); |
| 502 return underlying_file_util_->Touch(context, data_path, | 502 return underlying_file_util_->Touch(context, data_path, |
| 503 last_access_time, last_modified_time); | 503 last_access_time, last_modified_time); |
| 504 } | 504 } |
| 505 | 505 |
| 506 PlatformFileError ObfuscatedFileSystemFileUtil::Truncate( | 506 PlatformFileError ObfuscatedFileUtil::Truncate( |
| 507 FileSystemOperationContext* context, | 507 FileSystemOperationContext* context, |
| 508 const FilePath& virtual_path, | 508 const FilePath& virtual_path, |
| 509 int64 length) { | 509 int64 length) { |
| 510 FilePath local_path = | 510 FilePath local_path = |
| 511 GetLocalPath(context->src_origin_url(), context->src_type(), | 511 GetLocalPath(context->src_origin_url(), context->src_type(), |
| 512 virtual_path); | 512 virtual_path); |
| 513 if (local_path.empty()) | 513 if (local_path.empty()) |
| 514 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 514 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 515 return underlying_file_util_->Truncate( | 515 return underlying_file_util_->Truncate( |
| 516 context, local_path, length); | 516 context, local_path, length); |
| 517 } | 517 } |
| 518 | 518 |
| 519 bool ObfuscatedFileSystemFileUtil::PathExists( | 519 bool ObfuscatedFileUtil::PathExists( |
| 520 FileSystemOperationContext* context, | 520 FileSystemOperationContext* context, |
| 521 const FilePath& virtual_path) { | 521 const FilePath& virtual_path) { |
| 522 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 522 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 523 context->src_origin_url(), context->src_type(), false); | 523 context->src_origin_url(), context->src_type(), false); |
| 524 if (!db) | 524 if (!db) |
| 525 return false; | 525 return false; |
| 526 FileId file_id; | 526 FileId file_id; |
| 527 return db->GetFileWithPath(virtual_path, &file_id); | 527 return db->GetFileWithPath(virtual_path, &file_id); |
| 528 } | 528 } |
| 529 | 529 |
| 530 bool ObfuscatedFileSystemFileUtil::DirectoryExists( | 530 bool ObfuscatedFileUtil::DirectoryExists( |
| 531 FileSystemOperationContext* context, | 531 FileSystemOperationContext* context, |
| 532 const FilePath& virtual_path) { | 532 const FilePath& virtual_path) { |
| 533 if (IsRootDirectory(virtual_path)) { | 533 if (IsRootDirectory(virtual_path)) { |
| 534 // It's questionable whether we should return true or false for the | 534 // It's questionable whether we should return true or false for the |
| 535 // root directory of nonexistent origin, but here we return true | 535 // root directory of nonexistent origin, but here we return true |
| 536 // as the current implementation of ReadDirectory always returns an empty | 536 // as the current implementation of ReadDirectory always returns an empty |
| 537 // array (rather than erroring out with NOT_FOUND_ERR even) for | 537 // array (rather than erroring out with NOT_FOUND_ERR even) for |
| 538 // nonexistent origins. | 538 // nonexistent origins. |
| 539 // Note: if you're going to change this behavior please also consider | 539 // Note: if you're going to change this behavior please also consider |
| 540 // changiing the ReadDirectory's behavior! | 540 // changiing the ReadDirectory's behavior! |
| 541 return true; | 541 return true; |
| 542 } | 542 } |
| 543 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 543 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 544 context->src_origin_url(), context->src_type(), false); | 544 context->src_origin_url(), context->src_type(), false); |
| 545 if (!db) | 545 if (!db) |
| 546 return false; | 546 return false; |
| 547 FileId file_id; | 547 FileId file_id; |
| 548 if (!db->GetFileWithPath(virtual_path, &file_id)) | 548 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 549 return false; | 549 return false; |
| 550 FileInfo file_info; | 550 FileInfo file_info; |
| 551 if (!db->GetFileInfo(file_id, &file_info)) { | 551 if (!db->GetFileInfo(file_id, &file_info)) { |
| 552 NOTREACHED(); | 552 NOTREACHED(); |
| 553 return false; | 553 return false; |
| 554 } | 554 } |
| 555 return file_info.is_directory(); | 555 return file_info.is_directory(); |
| 556 } | 556 } |
| 557 | 557 |
| 558 bool ObfuscatedFileSystemFileUtil::IsDirectoryEmpty( | 558 bool ObfuscatedFileUtil::IsDirectoryEmpty( |
| 559 FileSystemOperationContext* context, | 559 FileSystemOperationContext* context, |
| 560 const FilePath& virtual_path) { | 560 const FilePath& virtual_path) { |
| 561 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 561 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 562 context->src_origin_url(), context->src_type(), false); | 562 context->src_origin_url(), context->src_type(), false); |
| 563 if (!db) | 563 if (!db) |
| 564 return true; // Not a great answer, but it's what others do. | 564 return true; // Not a great answer, but it's what others do. |
| 565 FileId file_id; | 565 FileId file_id; |
| 566 if (!db->GetFileWithPath(virtual_path, &file_id)) | 566 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 567 return true; // Ditto. | 567 return true; // Ditto. |
| 568 FileInfo file_info; | 568 FileInfo file_info; |
| 569 if (!db->GetFileInfo(file_id, &file_info)) { | 569 if (!db->GetFileInfo(file_id, &file_info)) { |
| 570 DCHECK(!file_id); | 570 DCHECK(!file_id); |
| 571 // It's the root directory and the database hasn't been initialized yet. | 571 // It's the root directory and the database hasn't been initialized yet. |
| 572 return true; | 572 return true; |
| 573 } | 573 } |
| 574 if (!file_info.is_directory()) | 574 if (!file_info.is_directory()) |
| 575 return true; | 575 return true; |
| 576 std::vector<FileId> children; | 576 std::vector<FileId> children; |
| 577 // TODO(ericu): This could easily be made faster with help from the database. | 577 // TODO(ericu): This could easily be made faster with help from the database. |
| 578 if (!db->ListChildren(file_id, &children)) | 578 if (!db->ListChildren(file_id, &children)) |
| 579 return true; | 579 return true; |
| 580 return children.empty(); | 580 return children.empty(); |
| 581 } | 581 } |
| 582 | 582 |
| 583 class ObfuscatedFileSystemFileEnumerator | 583 class ObfuscatedFileSystemFileEnumerator |
| 584 : public FileSystemFileUtil::AbstractFileEnumerator { | 584 : public FileApiFileUtil::AbstractFileEnumerator { |
| 585 public: | 585 public: |
| 586 ObfuscatedFileSystemFileEnumerator( | 586 ObfuscatedFileSystemFileEnumerator( |
| 587 FileSystemDirectoryDatabase* db, const FilePath& virtual_root_path) | 587 FileSystemDirectoryDatabase* db, const FilePath& virtual_root_path) |
| 588 : db_(db) { | 588 : db_(db) { |
| 589 FileId file_id; | 589 FileId file_id; |
| 590 FileInfo file_info; | 590 FileInfo file_info; |
| 591 if (!db_->GetFileWithPath(virtual_root_path, &file_id)) | 591 if (!db_->GetFileWithPath(virtual_root_path, &file_id)) |
| 592 return; | 592 return; |
| 593 if (!db_->GetFileInfo(file_id, &file_info)) | 593 if (!db_->GetFileInfo(file_id, &file_info)) |
| 594 return; | 594 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 } | 645 } |
| 646 } | 646 } |
| 647 | 647 |
| 648 std::queue<FileRecord> display_queue_; | 648 std::queue<FileRecord> display_queue_; |
| 649 std::queue<FileRecord> recurse_queue_; | 649 std::queue<FileRecord> recurse_queue_; |
| 650 FileRecord current_; | 650 FileRecord current_; |
| 651 FileSystemDirectoryDatabase* db_; | 651 FileSystemDirectoryDatabase* db_; |
| 652 }; | 652 }; |
| 653 | 653 |
| 654 class ObfuscatedFileSystemOriginEnumerator | 654 class ObfuscatedFileSystemOriginEnumerator |
| 655 : public ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator { | 655 : public ObfuscatedFileUtil::AbstractOriginEnumerator { |
| 656 public: | 656 public: |
| 657 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; | 657 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; |
| 658 ObfuscatedFileSystemOriginEnumerator( | 658 ObfuscatedFileSystemOriginEnumerator( |
| 659 FileSystemOriginDatabase* origin_database, | 659 FileSystemOriginDatabase* origin_database, |
| 660 const FilePath& base_path) | 660 const FilePath& base_path) |
| 661 : base_path_(base_path) { | 661 : base_path_(base_path) { |
| 662 if (origin_database) | 662 if (origin_database) |
| 663 origin_database->ListAllOrigins(&origins_); | 663 origin_database->ListAllOrigins(&origins_); |
| 664 } | 664 } |
| 665 | 665 |
| 666 ~ObfuscatedFileSystemOriginEnumerator() {} | 666 ~ObfuscatedFileSystemOriginEnumerator() {} |
| 667 | 667 |
| 668 // Returns the next origin. Returns empty if there are no more origins. | 668 // Returns the next origin. Returns empty if there are no more origins. |
| 669 virtual GURL Next() OVERRIDE { | 669 virtual GURL Next() OVERRIDE { |
| 670 OriginRecord record; | 670 OriginRecord record; |
| 671 if (!origins_.empty()) { | 671 if (!origins_.empty()) { |
| 672 record = origins_.back(); | 672 record = origins_.back(); |
| 673 origins_.pop_back(); | 673 origins_.pop_back(); |
| 674 } | 674 } |
| 675 current_ = record; | 675 current_ = record; |
| 676 return GetOriginURLFromIdentifier(record.origin); | 676 return GetOriginURLFromIdentifier(record.origin); |
| 677 } | 677 } |
| 678 | 678 |
| 679 // Returns the current origin's information. | 679 // Returns the current origin's information. |
| 680 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { | 680 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { |
| 681 if (current_.path.empty()) | 681 if (current_.path.empty()) |
| 682 return false; | 682 return false; |
| 683 FilePath::StringType type_string = | 683 FilePath::StringType type_string = |
| 684 ObfuscatedFileSystemFileUtil::GetDirectoryNameForType(type); | 684 ObfuscatedFileUtil::GetDirectoryNameForType(type); |
| 685 if (type_string.empty()) { | 685 if (type_string.empty()) { |
| 686 NOTREACHED(); | 686 NOTREACHED(); |
| 687 return false; | 687 return false; |
| 688 } | 688 } |
| 689 FilePath path = base_path_.Append(current_.path).Append(type_string); | 689 FilePath path = base_path_.Append(current_.path).Append(type_string); |
| 690 return file_util::DirectoryExists(path); | 690 return file_util::DirectoryExists(path); |
| 691 } | 691 } |
| 692 | 692 |
| 693 private: | 693 private: |
| 694 std::vector<OriginRecord> origins_; | 694 std::vector<OriginRecord> origins_; |
| 695 OriginRecord current_; | 695 OriginRecord current_; |
| 696 FilePath base_path_; | 696 FilePath base_path_; |
| 697 }; | 697 }; |
| 698 | 698 |
| 699 ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator* | 699 ObfuscatedFileUtil::AbstractOriginEnumerator* |
| 700 ObfuscatedFileSystemFileUtil::CreateOriginEnumerator() { | 700 ObfuscatedFileUtil::CreateOriginEnumerator() { |
| 701 std::vector<FileSystemOriginDatabase::OriginRecord> origins; | 701 std::vector<FileSystemOriginDatabase::OriginRecord> origins; |
| 702 | 702 |
| 703 InitOriginDatabase(false); | 703 InitOriginDatabase(false); |
| 704 return new ObfuscatedFileSystemOriginEnumerator( | 704 return new ObfuscatedFileSystemOriginEnumerator( |
| 705 origin_database_.get(), file_system_directory_); | 705 origin_database_.get(), file_system_directory_); |
| 706 } | 706 } |
| 707 | 707 |
| 708 FileSystemFileUtil::AbstractFileEnumerator* | 708 FileApiFileUtil::AbstractFileEnumerator* |
| 709 ObfuscatedFileSystemFileUtil::CreateFileEnumerator( | 709 ObfuscatedFileUtil::CreateFileEnumerator( |
| 710 FileSystemOperationContext* context, | 710 FileSystemOperationContext* context, |
| 711 const FilePath& root_path) { | 711 const FilePath& root_path) { |
| 712 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 712 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 713 context->src_origin_url(), context->src_type(), false); | 713 context->src_origin_url(), context->src_type(), false); |
| 714 if (!db) | 714 if (!db) |
| 715 return new FileSystemFileUtil::EmptyFileEnumerator(); | 715 return new FileApiFileUtil::EmptyFileEnumerator(); |
| 716 return new ObfuscatedFileSystemFileEnumerator(db, root_path); | 716 return new ObfuscatedFileSystemFileEnumerator(db, root_path); |
| 717 } | 717 } |
| 718 | 718 |
| 719 PlatformFileError ObfuscatedFileSystemFileUtil::GetFileInfoInternal( | 719 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( |
| 720 FileSystemDirectoryDatabase* db, | 720 FileSystemDirectoryDatabase* db, |
| 721 FileSystemOperationContext* context, | 721 FileSystemOperationContext* context, |
| 722 FileId file_id, | 722 FileId file_id, |
| 723 FileInfo* local_info, | 723 FileInfo* local_info, |
| 724 base::PlatformFileInfo* file_info, | 724 base::PlatformFileInfo* file_info, |
| 725 FilePath* platform_file_path) { | 725 FilePath* platform_file_path) { |
| 726 DCHECK(db); | 726 DCHECK(db); |
| 727 DCHECK(context); | 727 DCHECK(context); |
| 728 DCHECK(file_info); | 728 DCHECK(file_info); |
| 729 DCHECK(platform_file_path); | 729 DCHECK(platform_file_path); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 742 return base::PLATFORM_FILE_OK; | 742 return base::PLATFORM_FILE_OK; |
| 743 } | 743 } |
| 744 if (local_info->data_path.empty()) | 744 if (local_info->data_path.empty()) |
| 745 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 745 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 746 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), | 746 FilePath data_path = DataPathToLocalPath(context->src_origin_url(), |
| 747 context->src_type(), local_info->data_path); | 747 context->src_type(), local_info->data_path); |
| 748 return underlying_file_util_->GetFileInfo( | 748 return underlying_file_util_->GetFileInfo( |
| 749 context, data_path, file_info, platform_file_path); | 749 context, data_path, file_info, platform_file_path); |
| 750 } | 750 } |
| 751 | 751 |
| 752 PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile( | 752 PlatformFileError ObfuscatedFileUtil::CreateFile( |
| 753 FileSystemOperationContext* context, | 753 FileSystemOperationContext* context, |
| 754 const GURL& origin_url, FileSystemType type, const FilePath& source_path, | 754 const GURL& origin_url, FileSystemType type, const FilePath& source_path, |
| 755 FileInfo* file_info, int file_flags, PlatformFile* handle) { | 755 FileInfo* file_info, int file_flags, PlatformFile* handle) { |
| 756 if (handle) | 756 if (handle) |
| 757 *handle = base::kInvalidPlatformFileValue; | 757 *handle = base::kInvalidPlatformFileValue; |
| 758 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 758 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 759 origin_url, type, true); | 759 origin_url, type, true); |
| 760 int64 number; | 760 int64 number; |
| 761 if (!db || !db->GetNextInteger(&number)) | 761 if (!db || !db->GetNextInteger(&number)) |
| 762 return base::PLATFORM_FILE_ERROR_FAILED; | 762 return base::PLATFORM_FILE_ERROR_FAILED; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); | 816 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); |
| 817 base::ClosePlatformFile(*handle); | 817 base::ClosePlatformFile(*handle); |
| 818 } | 818 } |
| 819 underlying_file_util_->DeleteFile(context, path); | 819 underlying_file_util_->DeleteFile(context, path); |
| 820 return base::PLATFORM_FILE_ERROR_FAILED; | 820 return base::PLATFORM_FILE_ERROR_FAILED; |
| 821 } | 821 } |
| 822 | 822 |
| 823 return base::PLATFORM_FILE_OK; | 823 return base::PLATFORM_FILE_OK; |
| 824 } | 824 } |
| 825 | 825 |
| 826 FilePath ObfuscatedFileSystemFileUtil::GetLocalPath( | 826 FilePath ObfuscatedFileUtil::GetLocalPath( |
| 827 const GURL& origin_url, | 827 const GURL& origin_url, |
| 828 FileSystemType type, | 828 FileSystemType type, |
| 829 const FilePath& virtual_path) { | 829 const FilePath& virtual_path) { |
| 830 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 830 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 831 origin_url, type, false); | 831 origin_url, type, false); |
| 832 if (!db) | 832 if (!db) |
| 833 return FilePath(); | 833 return FilePath(); |
| 834 FileId file_id; | 834 FileId file_id; |
| 835 if (!db->GetFileWithPath(virtual_path, &file_id)) | 835 if (!db->GetFileWithPath(virtual_path, &file_id)) |
| 836 return FilePath(); | 836 return FilePath(); |
| 837 FileInfo file_info; | 837 FileInfo file_info; |
| 838 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { | 838 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { |
| 839 NOTREACHED(); | 839 NOTREACHED(); |
| 840 return FilePath(); // Directories have no local path. | 840 return FilePath(); // Directories have no local path. |
| 841 } | 841 } |
| 842 return DataPathToLocalPath(origin_url, type, file_info.data_path); | 842 return DataPathToLocalPath(origin_url, type, file_info.data_path); |
| 843 } | 843 } |
| 844 | 844 |
| 845 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOriginAndType( | 845 FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType( |
| 846 const GURL& origin, FileSystemType type, bool create) { | 846 const GURL& origin, FileSystemType type, bool create) { |
| 847 FilePath origin_dir = GetDirectoryForOrigin(origin, create); | 847 FilePath origin_dir = GetDirectoryForOrigin(origin, create); |
| 848 if (origin_dir.empty()) | 848 if (origin_dir.empty()) |
| 849 return FilePath(); | 849 return FilePath(); |
| 850 FilePath::StringType type_string = GetDirectoryNameForType(type); | 850 FilePath::StringType type_string = GetDirectoryNameForType(type); |
| 851 if (type_string.empty()) { | 851 if (type_string.empty()) { |
| 852 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 852 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 853 return FilePath(); | 853 return FilePath(); |
| 854 } | 854 } |
| 855 FilePath path = origin_dir.Append(type_string); | 855 FilePath path = origin_dir.Append(type_string); |
| 856 if (!file_util::DirectoryExists(path) && | 856 if (!file_util::DirectoryExists(path) && |
| 857 (!create || !file_util::CreateDirectory(path))) | 857 (!create || !file_util::CreateDirectory(path))) |
| 858 return FilePath(); | 858 return FilePath(); |
| 859 return path; | 859 return path; |
| 860 } | 860 } |
| 861 | 861 |
| 862 bool ObfuscatedFileSystemFileUtil::DeleteDirectoryForOriginAndType( | 862 bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType( |
| 863 const GURL& origin, FileSystemType type) { | 863 const GURL& origin, FileSystemType type) { |
| 864 FilePath origin_type_path = GetDirectoryForOriginAndType(origin, type, false); | 864 FilePath origin_type_path = GetDirectoryForOriginAndType(origin, type, false); |
| 865 if (!file_util::PathExists(origin_type_path)) | 865 if (!file_util::PathExists(origin_type_path)) |
| 866 return true; | 866 return true; |
| 867 | 867 |
| 868 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase. | 868 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase. |
| 869 // We ignore its error now since 1) it doesn't matter the final result, and | 869 // We ignore its error now since 1) it doesn't matter the final result, and |
| 870 // 2) it always returns false in Windows because of LevelDB's implementation. | 870 // 2) it always returns false in Windows because of LevelDB's implementation. |
| 871 // Information about failure would be useful for debugging. | 871 // Information about failure would be useful for debugging. |
| 872 DestroyDirectoryDatabase(origin, type); | 872 DestroyDirectoryDatabase(origin, type); |
| 873 if (!file_util::Delete(origin_type_path, true /* recursive */)) | 873 if (!file_util::Delete(origin_type_path, true /* recursive */)) |
| 874 return false; | 874 return false; |
| 875 | 875 |
| 876 FilePath origin_path = origin_type_path.DirName(); | 876 FilePath origin_path = origin_type_path.DirName(); |
| 877 DCHECK_EQ(origin_path.value(), GetDirectoryForOrigin(origin, false).value()); | 877 DCHECK_EQ(origin_path.value(), GetDirectoryForOrigin(origin, false).value()); |
| 878 | 878 |
| 879 // Delete the origin directory if the deleted one was the last remaining | 879 // Delete the origin directory if the deleted one was the last remaining |
| 880 // type for the origin. | 880 // type for the origin. |
| 881 if (file_util::Delete(origin_path, false /* recursive */)) { | 881 if (file_util::Delete(origin_path, false /* recursive */)) { |
| 882 InitOriginDatabase(false); | 882 InitOriginDatabase(false); |
| 883 if (origin_database_.get()) | 883 if (origin_database_.get()) |
| 884 origin_database_->RemovePathForOrigin(GetOriginIdentifierFromURL(origin)); | 884 origin_database_->RemovePathForOrigin(GetOriginIdentifierFromURL(origin)); |
| 885 } | 885 } |
| 886 | 886 |
| 887 // At this point we are sure we had successfully deleted the origin/type | 887 // At this point we are sure we had successfully deleted the origin/type |
| 888 // directory, so just returning true here. | 888 // directory, so just returning true here. |
| 889 return true; | 889 return true; |
| 890 } | 890 } |
| 891 | 891 |
| 892 bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( | 892 bool ObfuscatedFileUtil::MigrateFromOldSandbox( |
| 893 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { | 893 const GURL& origin_url, FileSystemType type, const FilePath& src_root) { |
| 894 if (!DestroyDirectoryDatabase(origin_url, type)) | 894 if (!DestroyDirectoryDatabase(origin_url, type)) |
| 895 return false; | 895 return false; |
| 896 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); | 896 FilePath dest_root = GetDirectoryForOriginAndType(origin_url, type, true); |
| 897 if (dest_root.empty()) | 897 if (dest_root.empty()) |
| 898 return false; | 898 return false; |
| 899 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 899 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 900 origin_url, type, false); | 900 origin_url, type, false); |
| 901 if (!db) | 901 if (!db) |
| 902 return false; | 902 return false; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 LOG(WARNING) << | 954 LOG(WARNING) << |
| 955 "The final step of a migration failed; I'll try to clean up."; | 955 "The final step of a migration failed; I'll try to clean up."; |
| 956 db = NULL; | 956 db = NULL; |
| 957 DestroyDirectoryDatabase(origin_url, type); | 957 DestroyDirectoryDatabase(origin_url, type); |
| 958 return false; | 958 return false; |
| 959 } | 959 } |
| 960 return true; | 960 return true; |
| 961 } | 961 } |
| 962 | 962 |
| 963 // static | 963 // static |
| 964 FilePath::StringType ObfuscatedFileSystemFileUtil::GetDirectoryNameForType( | 964 FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType( |
| 965 FileSystemType type) { | 965 FileSystemType type) { |
| 966 switch (type) { | 966 switch (type) { |
| 967 case kFileSystemTypeTemporary: | 967 case kFileSystemTypeTemporary: |
| 968 return kTemporaryDirectoryName; | 968 return kTemporaryDirectoryName; |
| 969 case kFileSystemTypePersistent: | 969 case kFileSystemTypePersistent: |
| 970 return kPersistentDirectoryName; | 970 return kPersistentDirectoryName; |
| 971 case kFileSystemTypeUnknown: | 971 case kFileSystemTypeUnknown: |
| 972 default: | 972 default: |
| 973 return FilePath::StringType(); | 973 return FilePath::StringType(); |
| 974 } | 974 } |
| 975 } | 975 } |
| 976 | 976 |
| 977 FilePath ObfuscatedFileSystemFileUtil::DataPathToLocalPath( | 977 FilePath ObfuscatedFileUtil::DataPathToLocalPath( |
| 978 const GURL& origin, FileSystemType type, const FilePath& data_path) { | 978 const GURL& origin, FileSystemType type, const FilePath& data_path) { |
| 979 FilePath root = GetDirectoryForOriginAndType(origin, type, false); | 979 FilePath root = GetDirectoryForOriginAndType(origin, type, false); |
| 980 if (root.empty()) | 980 if (root.empty()) |
| 981 return root; | 981 return root; |
| 982 return root.Append(data_path); | 982 return root.Append(data_path); |
| 983 } | 983 } |
| 984 | 984 |
| 985 FilePath ObfuscatedFileSystemFileUtil::LocalPathToDataPath( | 985 FilePath ObfuscatedFileUtil::LocalPathToDataPath( |
| 986 const GURL& origin, FileSystemType type, const FilePath& local_path) { | 986 const GURL& origin, FileSystemType type, const FilePath& local_path) { |
| 987 FilePath root = GetDirectoryForOriginAndType(origin, type, false); | 987 FilePath root = GetDirectoryForOriginAndType(origin, type, false); |
| 988 if (root.empty()) | 988 if (root.empty()) |
| 989 return root; | 989 return root; |
| 990 // This removes the root, including the trailing slash, leaving a relative | 990 // This removes the root, including the trailing slash, leaving a relative |
| 991 // path. | 991 // path. |
| 992 return FilePath(local_path.value().substr(root.value().length() + 1)); | 992 return FilePath(local_path.value().substr(root.value().length() + 1)); |
| 993 } | 993 } |
| 994 | 994 |
| 995 // TODO: How to do the whole validation-without-creation thing? We may not have | 995 // TODO: How to do the whole validation-without-creation thing? We may not have |
| 996 // quota even to create the database. Ah, in that case don't even get here? | 996 // quota even to create the database. Ah, in that case don't even get here? |
| 997 // Still doesn't answer the quota issue, though. | 997 // Still doesn't answer the quota issue, though. |
| 998 FileSystemDirectoryDatabase* ObfuscatedFileSystemFileUtil::GetDirectoryDatabase( | 998 FileSystemDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( |
| 999 const GURL& origin, FileSystemType type, bool create) { | 999 const GURL& origin, FileSystemType type, bool create) { |
| 1000 std::string type_string = | 1000 std::string type_string = |
| 1001 FileSystemPathManager::GetFileSystemTypeString(type); | 1001 FileSystemPathManager::GetFileSystemTypeString(type); |
| 1002 if (type_string.empty()) { | 1002 if (type_string.empty()) { |
| 1003 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 1003 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 1004 return NULL; | 1004 return NULL; |
| 1005 } | 1005 } |
| 1006 std::string key = GetOriginIdentifierFromURL(origin) + type_string; | 1006 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
| 1007 DirectoryMap::iterator iter = directories_.find(key); | 1007 DirectoryMap::iterator iter = directories_.find(key); |
| 1008 if (iter != directories_.end()) { | 1008 if (iter != directories_.end()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1019 return NULL; | 1019 return NULL; |
| 1020 } | 1020 } |
| 1021 } | 1021 } |
| 1022 MarkUsed(); | 1022 MarkUsed(); |
| 1023 path = path.AppendASCII(kDirectoryDatabaseName); | 1023 path = path.AppendASCII(kDirectoryDatabaseName); |
| 1024 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); | 1024 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); |
| 1025 directories_[key] = database; | 1025 directories_[key] = database; |
| 1026 return database; | 1026 return database; |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( | 1029 FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( |
| 1030 const GURL& origin, bool create) { | 1030 const GURL& origin, bool create) { |
| 1031 if (!InitOriginDatabase(create)) | 1031 if (!InitOriginDatabase(create)) |
| 1032 return FilePath(); | 1032 return FilePath(); |
| 1033 FilePath directory_name; | 1033 FilePath directory_name; |
| 1034 std::string id = GetOriginIdentifierFromURL(origin); | 1034 std::string id = GetOriginIdentifierFromURL(origin); |
| 1035 if (!create && !origin_database_->HasOriginPath(id)) | 1035 if (!create && !origin_database_->HasOriginPath(id)) |
| 1036 return FilePath(); | 1036 return FilePath(); |
| 1037 if (!origin_database_->GetPathForOrigin(id, &directory_name)) | 1037 if (!origin_database_->GetPathForOrigin(id, &directory_name)) |
| 1038 return FilePath(); | 1038 return FilePath(); |
| 1039 FilePath path = file_system_directory_.Append(directory_name); | 1039 FilePath path = file_system_directory_.Append(directory_name); |
| 1040 if (!file_util::DirectoryExists(path) && | 1040 if (!file_util::DirectoryExists(path) && |
| 1041 (!create || !file_util::CreateDirectory(path))) | 1041 (!create || !file_util::CreateDirectory(path))) |
| 1042 return FilePath(); | 1042 return FilePath(); |
| 1043 return path; | 1043 return path; |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 void ObfuscatedFileSystemFileUtil::MarkUsed() { | 1046 void ObfuscatedFileUtil::MarkUsed() { |
| 1047 if (timer_.IsRunning()) | 1047 if (timer_.IsRunning()) |
| 1048 timer_.Reset(); | 1048 timer_.Reset(); |
| 1049 else | 1049 else |
| 1050 timer_.Start(base::TimeDelta::FromSeconds(kFlushDelaySeconds), this, | 1050 timer_.Start(base::TimeDelta::FromSeconds(kFlushDelaySeconds), this, |
| 1051 &ObfuscatedFileSystemFileUtil::DropDatabases); | 1051 &ObfuscatedFileUtil::DropDatabases); |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 void ObfuscatedFileSystemFileUtil::DropDatabases() { | 1054 void ObfuscatedFileUtil::DropDatabases() { |
| 1055 origin_database_.reset(); | 1055 origin_database_.reset(); |
| 1056 STLDeleteContainerPairSecondPointers( | 1056 STLDeleteContainerPairSecondPointers( |
| 1057 directories_.begin(), directories_.end()); | 1057 directories_.begin(), directories_.end()); |
| 1058 directories_.clear(); | 1058 directories_.clear(); |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 bool ObfuscatedFileSystemFileUtil::DestroyDirectoryDatabase( | 1061 bool ObfuscatedFileUtil::DestroyDirectoryDatabase( |
| 1062 const GURL& origin, FileSystemType type) { | 1062 const GURL& origin, FileSystemType type) { |
| 1063 std::string type_string = | 1063 std::string type_string = |
| 1064 FileSystemPathManager::GetFileSystemTypeString(type); | 1064 FileSystemPathManager::GetFileSystemTypeString(type); |
| 1065 if (type_string.empty()) { | 1065 if (type_string.empty()) { |
| 1066 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 1066 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 1067 return true; | 1067 return true; |
| 1068 } | 1068 } |
| 1069 std::string key = GetOriginIdentifierFromURL(origin) + type_string; | 1069 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
| 1070 DirectoryMap::iterator iter = directories_.find(key); | 1070 DirectoryMap::iterator iter = directories_.find(key); |
| 1071 if (iter != directories_.end()) { | 1071 if (iter != directories_.end()) { |
| 1072 FileSystemDirectoryDatabase* database = iter->second; | 1072 FileSystemDirectoryDatabase* database = iter->second; |
| 1073 directories_.erase(iter); | 1073 directories_.erase(iter); |
| 1074 delete database; | 1074 delete database; |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 FilePath path = GetDirectoryForOriginAndType(origin, type, false); | 1077 FilePath path = GetDirectoryForOriginAndType(origin, type, false); |
| 1078 if (path.empty()) | 1078 if (path.empty()) |
| 1079 return true; | 1079 return true; |
| 1080 if (!file_util::DirectoryExists(path)) | 1080 if (!file_util::DirectoryExists(path)) |
| 1081 return true; | 1081 return true; |
| 1082 path = path.AppendASCII(kDirectoryDatabaseName); | 1082 path = path.AppendASCII(kDirectoryDatabaseName); |
| 1083 return FileSystemDirectoryDatabase::DestroyDatabase(path); | 1083 return FileSystemDirectoryDatabase::DestroyDatabase(path); |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 bool ObfuscatedFileSystemFileUtil::InitOriginDatabase(bool create) { | 1086 bool ObfuscatedFileUtil::InitOriginDatabase(bool create) { |
| 1087 if (!origin_database_.get()) { | 1087 if (!origin_database_.get()) { |
| 1088 if (!create && !file_util::DirectoryExists(file_system_directory_)) | 1088 if (!create && !file_util::DirectoryExists(file_system_directory_)) |
| 1089 return false; | 1089 return false; |
| 1090 if (!file_util::CreateDirectory(file_system_directory_)) { | 1090 if (!file_util::CreateDirectory(file_system_directory_)) { |
| 1091 LOG(WARNING) << "Failed to create FileSystem directory: " << | 1091 LOG(WARNING) << "Failed to create FileSystem directory: " << |
| 1092 file_system_directory_.value(); | 1092 file_system_directory_.value(); |
| 1093 return false; | 1093 return false; |
| 1094 } | 1094 } |
| 1095 origin_database_.reset( | 1095 origin_database_.reset( |
| 1096 new FileSystemOriginDatabase( | 1096 new FileSystemOriginDatabase( |
| 1097 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1097 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
| 1098 } | 1098 } |
| 1099 return true; | 1099 return true; |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 } // namespace fileapi | 1102 } // namespace fileapi |
| OLD | NEW |