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 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 return base::PLATFORM_FILE_ERROR_FAILED; | 780 return base::PLATFORM_FILE_ERROR_FAILED; |
| 781 PlatformFileError error; | 781 PlatformFileError error; |
| 782 bool created = false; | 782 bool created = false; |
| 783 if (!source_path.empty()) { | 783 if (!source_path.empty()) { |
| 784 DCHECK(!file_flags); | 784 DCHECK(!file_flags); |
| 785 DCHECK(!handle); | 785 DCHECK(!handle); |
| 786 error = underlying_file_util_->CopyOrMoveFile( | 786 error = underlying_file_util_->CopyOrMoveFile( |
| 787 context, source_path, path, true /* copy */); | 787 context, source_path, path, true /* copy */); |
| 788 created = true; | 788 created = true; |
| 789 } else { | 789 } else { |
| 790 if (file_util::PathExists(path)) { | |
| 791 if (!file_util::Delete(path, false)) { | |
| 792 NOTREACHED(); | |
| 793 return base::PLATFORM_FILE_ERROR_FAILED; | |
| 794 } | |
| 795 context->file_system_context()->RecalculateUsage(origin_url, type); | |
|
ericu
2011/08/17 00:54:08
What's the purpose of this RecalculateUsage call?
kinuko
2011/08/18 01:26:36
Eric, this is one of the place we wondered if we'd
tzik
2011/08/18 08:02:26
Thanks for explaining kinuko-san, it is what I wan
| |
| 796 LOG(WARNING) << "A stray file detected"; | |
| 797 } | |
| 798 | |
| 790 if (handle) { | 799 if (handle) { |
| 791 error = underlying_file_util_->CreateOrOpen( | 800 error = underlying_file_util_->CreateOrOpen( |
| 792 context, path, file_flags, handle, &created); | 801 context, path, file_flags, handle, &created); |
| 793 // If this succeeds, we must close handle on any subsequent error. | 802 // If this succeeds, we must close handle on any subsequent error. |
| 794 } else { | 803 } else { |
| 795 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. | 804 DCHECK(!file_flags); // file_flags is only used by CreateOrOpen. |
| 796 error = underlying_file_util_->EnsureFileExists( | 805 error = underlying_file_util_->EnsureFileExists( |
| 797 context, path, &created); | 806 context, path, &created); |
| 798 } | 807 } |
| 799 } | 808 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 directories_[key] = database; | 1034 directories_[key] = database; |
| 1026 return database; | 1035 return database; |
| 1027 } | 1036 } |
| 1028 | 1037 |
| 1029 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( | 1038 FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin( |
| 1030 const GURL& origin, bool create) { | 1039 const GURL& origin, bool create) { |
| 1031 if (!InitOriginDatabase(create)) | 1040 if (!InitOriginDatabase(create)) |
| 1032 return FilePath(); | 1041 return FilePath(); |
| 1033 FilePath directory_name; | 1042 FilePath directory_name; |
| 1034 std::string id = GetOriginIdentifierFromURL(origin); | 1043 std::string id = GetOriginIdentifierFromURL(origin); |
| 1035 if (!create && !origin_database_->HasOriginPath(id)) | 1044 |
| 1045 bool exists_in_db = origin_database_->HasOriginPath(id); | |
| 1046 if (!exists_in_db && !create) | |
| 1036 return FilePath(); | 1047 return FilePath(); |
| 1037 if (!origin_database_->GetPathForOrigin(id, &directory_name)) | 1048 if (!origin_database_->GetPathForOrigin(id, &directory_name)) |
| 1038 return FilePath(); | 1049 return FilePath(); |
| 1050 | |
| 1039 FilePath path = file_system_directory_.Append(directory_name); | 1051 FilePath path = file_system_directory_.Append(directory_name); |
|
ericu
2011/08/17 00:54:08
This part looks like a good idea.
| |
| 1040 if (!file_util::DirectoryExists(path) && | 1052 bool exists_in_fs = file_util::DirectoryExists(path); |
| 1041 (!create || !file_util::CreateDirectory(path))) | 1053 if (!exists_in_db && exists_in_fs) { |
| 1042 return FilePath(); | 1054 if (!file_util::Delete(path, true)) |
| 1055 return FilePath(); | |
| 1056 exists_in_fs = false; | |
| 1057 } | |
| 1058 | |
| 1059 if (!exists_in_fs) { | |
| 1060 if (!create || !file_util::CreateDirectory(path)) | |
| 1061 return FilePath(); | |
| 1062 } | |
| 1063 | |
| 1043 return path; | 1064 return path; |
| 1044 } | 1065 } |
| 1045 | 1066 |
| 1046 void ObfuscatedFileSystemFileUtil::MarkUsed() { | 1067 void ObfuscatedFileSystemFileUtil::MarkUsed() { |
| 1047 if (timer_.IsRunning()) | 1068 if (timer_.IsRunning()) |
| 1048 timer_.Reset(); | 1069 timer_.Reset(); |
| 1049 else | 1070 else |
| 1050 timer_.Start(base::TimeDelta::FromSeconds(kFlushDelaySeconds), this, | 1071 timer_.Start(base::TimeDelta::FromSeconds(kFlushDelaySeconds), this, |
| 1051 &ObfuscatedFileSystemFileUtil::DropDatabases); | 1072 &ObfuscatedFileSystemFileUtil::DropDatabases); |
| 1052 } | 1073 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 return false; | 1114 return false; |
| 1094 } | 1115 } |
| 1095 origin_database_.reset( | 1116 origin_database_.reset( |
| 1096 new FileSystemOriginDatabase( | 1117 new FileSystemOriginDatabase( |
| 1097 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 1118 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
| 1098 } | 1119 } |
| 1099 return true; | 1120 return true; |
| 1100 } | 1121 } |
| 1101 | 1122 |
| 1102 } // namespace fileapi | 1123 } // namespace fileapi |
| OLD | NEW |