| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/obfuscated_file_util.h" | 5 #include "webkit/fileapi/obfuscated_file_util.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "webkit/fileapi/file_system_context.h" | 21 #include "webkit/fileapi/file_system_context.h" |
| 22 #include "webkit/fileapi/file_system_operation_context.h" | 22 #include "webkit/fileapi/file_system_operation_context.h" |
| 23 #include "webkit/fileapi/file_system_url.h" | 23 #include "webkit/fileapi/file_system_url.h" |
| 24 #include "webkit/fileapi/file_system_util.h" | 24 #include "webkit/fileapi/file_system_util.h" |
| 25 #include "webkit/fileapi/native_file_util.h" | 25 #include "webkit/fileapi/native_file_util.h" |
| 26 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 26 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 27 #include "webkit/quota/quota_manager.h" | 27 #include "webkit/quota/quota_manager.h" |
| 28 | 28 |
| 29 // Example of various paths: | 29 // Example of various paths: |
| 30 // void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) { | 30 // void ObfuscatedFileUtil::DoSomething(const FileSystemURL& url) { |
| 31 // FilePath virtual_path = url.path(); | 31 // base::FilePath virtual_path = url.path(); |
| 32 // FilePath local_path = GetLocalFilePath(url); | 32 // base::FilePath local_path = GetLocalFilePath(url); |
| 33 // | 33 // |
| 34 // NativeFileUtil::DoSomething(local_path); | 34 // NativeFileUtil::DoSomething(local_path); |
| 35 // file_util::DoAnother(local_path); | 35 // file_util::DoAnother(local_path); |
| 36 // } | 36 // } |
| 37 | 37 |
| 38 namespace fileapi { | 38 namespace fileapi { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 typedef FileSystemDirectoryDatabase::FileId FileId; | 42 typedef FileSystemDirectoryDatabase::FileId FileId; |
| 43 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; | 43 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; |
| 44 | 44 |
| 45 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes | 45 const int64 kFlushDelaySeconds = 10 * 60; // 10 minutes |
| 46 | 46 |
| 47 void InitFileInfo( | 47 void InitFileInfo( |
| 48 FileSystemDirectoryDatabase::FileInfo* file_info, | 48 FileSystemDirectoryDatabase::FileInfo* file_info, |
| 49 FileSystemDirectoryDatabase::FileId parent_id, | 49 FileSystemDirectoryDatabase::FileId parent_id, |
| 50 const FilePath::StringType& file_name) { | 50 const base::FilePath::StringType& file_name) { |
| 51 DCHECK(file_info); | 51 DCHECK(file_info); |
| 52 file_info->parent_id = parent_id; | 52 file_info->parent_id = parent_id; |
| 53 file_info->name = file_name; | 53 file_info->name = file_name; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Costs computed as per crbug.com/86114, based on the LevelDB implementation of | 56 // Costs computed as per crbug.com/86114, based on the LevelDB implementation of |
| 57 // path storage under Linux. It's not clear if that will differ on Windows, on | 57 // path storage under Linux. It's not clear if that will differ on Windows, on |
| 58 // which FilePath uses wide chars [since they're converted to UTF-8 for storage | 58 // which base::FilePath uses wide chars [since they're converted to UTF-8 for st
orage |
| 59 // anyway], but as long as the cost is high enough that one can't cheat on quota | 59 // anyway], but as long as the cost is high enough that one can't cheat on quota |
| 60 // by storing data in paths, it doesn't need to be all that accurate. | 60 // by storing data in paths, it doesn't need to be all that accurate. |
| 61 const int64 kPathCreationQuotaCost = 146; // Bytes per inode, basically. | 61 const int64 kPathCreationQuotaCost = 146; // Bytes per inode, basically. |
| 62 const int64 kPathByteQuotaCost = 2; // Bytes per byte of path length in UTF-8. | 62 const int64 kPathByteQuotaCost = 2; // Bytes per byte of path length in UTF-8. |
| 63 | 63 |
| 64 int64 UsageForPath(size_t length) { | 64 int64 UsageForPath(size_t length) { |
| 65 return kPathCreationQuotaCost + | 65 return kPathCreationQuotaCost + |
| 66 static_cast<int64>(length) * kPathByteQuotaCost; | 66 static_cast<int64>(length) * kPathByteQuotaCost; |
| 67 } | 67 } |
| 68 | 68 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 context->update_observers()->Notify( | 84 context->update_observers()->Notify( |
| 85 &FileUpdateObserver::OnUpdate, MakeTuple(url, growth)); | 85 &FileUpdateObserver::OnUpdate, MakeTuple(url, growth)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TouchDirectory(FileSystemDirectoryDatabase* db, FileId dir_id) { | 88 void TouchDirectory(FileSystemDirectoryDatabase* db, FileId dir_id) { |
| 89 DCHECK(db); | 89 DCHECK(db); |
| 90 if (!db->UpdateModificationTime(dir_id, base::Time::Now())) | 90 if (!db->UpdateModificationTime(dir_id, base::Time::Now())) |
| 91 NOTREACHED(); | 91 NOTREACHED(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 const FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"); | 94 const base::FilePath::CharType kTemporaryDirectoryName[] = FILE_PATH_LITERAL("t"
); |
| 95 const FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p"); | 95 const base::FilePath::CharType kPersistentDirectoryName[] = FILE_PATH_LITERAL("p
"); |
| 96 const FilePath::CharType kSyncableDirectoryName[] = FILE_PATH_LITERAL("s"); | 96 const base::FilePath::CharType kSyncableDirectoryName[] = FILE_PATH_LITERAL("s")
; |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 using base::PlatformFile; | 100 using base::PlatformFile; |
| 101 using base::PlatformFileError; | 101 using base::PlatformFileError; |
| 102 | 102 |
| 103 class ObfuscatedFileEnumerator | 103 class ObfuscatedFileEnumerator |
| 104 : public FileSystemFileUtil::AbstractFileEnumerator { | 104 : public FileSystemFileUtil::AbstractFileEnumerator { |
| 105 public: | 105 public: |
| 106 ObfuscatedFileEnumerator( | 106 ObfuscatedFileEnumerator( |
| 107 FileSystemDirectoryDatabase* db, | 107 FileSystemDirectoryDatabase* db, |
| 108 FileSystemOperationContext* context, | 108 FileSystemOperationContext* context, |
| 109 ObfuscatedFileUtil* obfuscated_file_util, | 109 ObfuscatedFileUtil* obfuscated_file_util, |
| 110 const FileSystemURL& root_url, | 110 const FileSystemURL& root_url, |
| 111 bool recursive) | 111 bool recursive) |
| 112 : db_(db), | 112 : db_(db), |
| 113 context_(context), | 113 context_(context), |
| 114 obfuscated_file_util_(obfuscated_file_util), | 114 obfuscated_file_util_(obfuscated_file_util), |
| 115 origin_(root_url.origin()), | 115 origin_(root_url.origin()), |
| 116 type_(root_url.type()), | 116 type_(root_url.type()), |
| 117 recursive_(recursive), | 117 recursive_(recursive), |
| 118 current_file_id_(0) { | 118 current_file_id_(0) { |
| 119 FilePath root_virtual_path = root_url.path(); | 119 base::FilePath root_virtual_path = root_url.path(); |
| 120 FileId file_id; | 120 FileId file_id; |
| 121 | 121 |
| 122 if (!db_->GetFileWithPath(root_virtual_path, &file_id)) | 122 if (!db_->GetFileWithPath(root_virtual_path, &file_id)) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 FileRecord record = { file_id, root_virtual_path }; | 125 FileRecord record = { file_id, root_virtual_path }; |
| 126 recurse_queue_.push(record); | 126 recurse_queue_.push(record); |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual ~ObfuscatedFileEnumerator() {} | 129 virtual ~ObfuscatedFileEnumerator() {} |
| 130 | 130 |
| 131 virtual FilePath Next() OVERRIDE { | 131 virtual base::FilePath Next() OVERRIDE { |
| 132 ProcessRecurseQueue(); | 132 ProcessRecurseQueue(); |
| 133 if (display_stack_.empty()) | 133 if (display_stack_.empty()) |
| 134 return FilePath(); | 134 return base::FilePath(); |
| 135 | 135 |
| 136 current_file_id_ = display_stack_.back(); | 136 current_file_id_ = display_stack_.back(); |
| 137 display_stack_.pop_back(); | 137 display_stack_.pop_back(); |
| 138 | 138 |
| 139 FileInfo file_info; | 139 FileInfo file_info; |
| 140 FilePath platform_file_path; | 140 base::FilePath platform_file_path; |
| 141 base::PlatformFileError error = | 141 base::PlatformFileError error = |
| 142 obfuscated_file_util_->GetFileInfoInternal( | 142 obfuscated_file_util_->GetFileInfoInternal( |
| 143 db_, context_, origin_, type_, current_file_id_, | 143 db_, context_, origin_, type_, current_file_id_, |
| 144 &file_info, ¤t_platform_file_info_, &platform_file_path); | 144 &file_info, ¤t_platform_file_info_, &platform_file_path); |
| 145 if (error != base::PLATFORM_FILE_OK) | 145 if (error != base::PLATFORM_FILE_OK) |
| 146 return Next(); | 146 return Next(); |
| 147 | 147 |
| 148 FilePath virtual_path = | 148 base::FilePath virtual_path = |
| 149 current_parent_virtual_path_.Append(file_info.name); | 149 current_parent_virtual_path_.Append(file_info.name); |
| 150 if (recursive_ && file_info.is_directory()) { | 150 if (recursive_ && file_info.is_directory()) { |
| 151 FileRecord record = { current_file_id_, virtual_path }; | 151 FileRecord record = { current_file_id_, virtual_path }; |
| 152 recurse_queue_.push(record); | 152 recurse_queue_.push(record); |
| 153 } | 153 } |
| 154 return virtual_path; | 154 return virtual_path; |
| 155 } | 155 } |
| 156 | 156 |
| 157 virtual int64 Size() OVERRIDE { | 157 virtual int64 Size() OVERRIDE { |
| 158 return current_platform_file_info_.size; | 158 return current_platform_file_info_.size; |
| 159 } | 159 } |
| 160 | 160 |
| 161 virtual base::Time LastModifiedTime() OVERRIDE { | 161 virtual base::Time LastModifiedTime() OVERRIDE { |
| 162 return current_platform_file_info_.last_modified; | 162 return current_platform_file_info_.last_modified; |
| 163 } | 163 } |
| 164 | 164 |
| 165 virtual bool IsDirectory() OVERRIDE { | 165 virtual bool IsDirectory() OVERRIDE { |
| 166 return current_platform_file_info_.is_directory; | 166 return current_platform_file_info_.is_directory; |
| 167 } | 167 } |
| 168 | 168 |
| 169 private: | 169 private: |
| 170 typedef FileSystemDirectoryDatabase::FileId FileId; | 170 typedef FileSystemDirectoryDatabase::FileId FileId; |
| 171 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; | 171 typedef FileSystemDirectoryDatabase::FileInfo FileInfo; |
| 172 | 172 |
| 173 struct FileRecord { | 173 struct FileRecord { |
| 174 FileId file_id; | 174 FileId file_id; |
| 175 FilePath virtual_path; | 175 base::FilePath virtual_path; |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 void ProcessRecurseQueue() { | 178 void ProcessRecurseQueue() { |
| 179 while (display_stack_.empty() && !recurse_queue_.empty()) { | 179 while (display_stack_.empty() && !recurse_queue_.empty()) { |
| 180 FileRecord entry = recurse_queue_.front(); | 180 FileRecord entry = recurse_queue_.front(); |
| 181 recurse_queue_.pop(); | 181 recurse_queue_.pop(); |
| 182 if (!db_->ListChildren(entry.file_id, &display_stack_)) { | 182 if (!db_->ListChildren(entry.file_id, &display_stack_)) { |
| 183 display_stack_.clear(); | 183 display_stack_.clear(); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 current_parent_virtual_path_ = entry.virtual_path; | 186 current_parent_virtual_path_ = entry.virtual_path; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 FileSystemDirectoryDatabase* db_; | 190 FileSystemDirectoryDatabase* db_; |
| 191 FileSystemOperationContext* context_; | 191 FileSystemOperationContext* context_; |
| 192 ObfuscatedFileUtil* obfuscated_file_util_; | 192 ObfuscatedFileUtil* obfuscated_file_util_; |
| 193 GURL origin_; | 193 GURL origin_; |
| 194 FileSystemType type_; | 194 FileSystemType type_; |
| 195 bool recursive_; | 195 bool recursive_; |
| 196 | 196 |
| 197 std::queue<FileRecord> recurse_queue_; | 197 std::queue<FileRecord> recurse_queue_; |
| 198 std::vector<FileId> display_stack_; | 198 std::vector<FileId> display_stack_; |
| 199 FilePath current_parent_virtual_path_; | 199 base::FilePath current_parent_virtual_path_; |
| 200 | 200 |
| 201 FileId current_file_id_; | 201 FileId current_file_id_; |
| 202 base::PlatformFileInfo current_platform_file_info_; | 202 base::PlatformFileInfo current_platform_file_info_; |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 class ObfuscatedOriginEnumerator | 205 class ObfuscatedOriginEnumerator |
| 206 : public ObfuscatedFileUtil::AbstractOriginEnumerator { | 206 : public ObfuscatedFileUtil::AbstractOriginEnumerator { |
| 207 public: | 207 public: |
| 208 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; | 208 typedef FileSystemOriginDatabase::OriginRecord OriginRecord; |
| 209 ObfuscatedOriginEnumerator( | 209 ObfuscatedOriginEnumerator( |
| 210 FileSystemOriginDatabase* origin_database, | 210 FileSystemOriginDatabase* origin_database, |
| 211 const FilePath& base_file_path) | 211 const base::FilePath& base_file_path) |
| 212 : base_file_path_(base_file_path) { | 212 : base_file_path_(base_file_path) { |
| 213 if (origin_database) | 213 if (origin_database) |
| 214 origin_database->ListAllOrigins(&origins_); | 214 origin_database->ListAllOrigins(&origins_); |
| 215 } | 215 } |
| 216 | 216 |
| 217 ~ObfuscatedOriginEnumerator() {} | 217 ~ObfuscatedOriginEnumerator() {} |
| 218 | 218 |
| 219 // Returns the next origin. Returns empty if there are no more origins. | 219 // Returns the next origin. Returns empty if there are no more origins. |
| 220 virtual GURL Next() OVERRIDE { | 220 virtual GURL Next() OVERRIDE { |
| 221 OriginRecord record; | 221 OriginRecord record; |
| 222 if (!origins_.empty()) { | 222 if (!origins_.empty()) { |
| 223 record = origins_.back(); | 223 record = origins_.back(); |
| 224 origins_.pop_back(); | 224 origins_.pop_back(); |
| 225 } | 225 } |
| 226 current_ = record; | 226 current_ = record; |
| 227 return GetOriginURLFromIdentifier(record.origin); | 227 return GetOriginURLFromIdentifier(record.origin); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Returns the current origin's information. | 230 // Returns the current origin's information. |
| 231 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { | 231 virtual bool HasFileSystemType(FileSystemType type) const OVERRIDE { |
| 232 if (current_.path.empty()) | 232 if (current_.path.empty()) |
| 233 return false; | 233 return false; |
| 234 FilePath::StringType type_string = | 234 base::FilePath::StringType type_string = |
| 235 ObfuscatedFileUtil::GetDirectoryNameForType(type); | 235 ObfuscatedFileUtil::GetDirectoryNameForType(type); |
| 236 if (type_string.empty()) { | 236 if (type_string.empty()) { |
| 237 NOTREACHED(); | 237 NOTREACHED(); |
| 238 return false; | 238 return false; |
| 239 } | 239 } |
| 240 FilePath path = base_file_path_.Append(current_.path).Append(type_string); | 240 base::FilePath path = base_file_path_.Append(current_.path).Append(type_stri
ng); |
| 241 return file_util::DirectoryExists(path); | 241 return file_util::DirectoryExists(path); |
| 242 } | 242 } |
| 243 | 243 |
| 244 private: | 244 private: |
| 245 std::vector<OriginRecord> origins_; | 245 std::vector<OriginRecord> origins_; |
| 246 OriginRecord current_; | 246 OriginRecord current_; |
| 247 FilePath base_file_path_; | 247 base::FilePath base_file_path_; |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 ObfuscatedFileUtil::ObfuscatedFileUtil( | 250 ObfuscatedFileUtil::ObfuscatedFileUtil( |
| 251 const FilePath& file_system_directory) | 251 const base::FilePath& file_system_directory) |
| 252 : file_system_directory_(file_system_directory) { | 252 : file_system_directory_(file_system_directory) { |
| 253 } | 253 } |
| 254 | 254 |
| 255 ObfuscatedFileUtil::~ObfuscatedFileUtil() { | 255 ObfuscatedFileUtil::~ObfuscatedFileUtil() { |
| 256 DropDatabases(); | 256 DropDatabases(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 PlatformFileError ObfuscatedFileUtil::CreateOrOpen( | 259 PlatformFileError ObfuscatedFileUtil::CreateOrOpen( |
| 260 FileSystemOperationContext* context, | 260 FileSystemOperationContext* context, |
| 261 const FileSystemURL& url, int file_flags, | 261 const FileSystemURL& url, int file_flags, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 278 &parent_id)) | 278 &parent_id)) |
| 279 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 279 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 280 FileInfo file_info; | 280 FileInfo file_info; |
| 281 InitFileInfo(&file_info, parent_id, | 281 InitFileInfo(&file_info, parent_id, |
| 282 VirtualPath::BaseName(url.path()).value()); | 282 VirtualPath::BaseName(url.path()).value()); |
| 283 | 283 |
| 284 int64 growth = UsageForPath(file_info.name.size()); | 284 int64 growth = UsageForPath(file_info.name.size()); |
| 285 if (!AllocateQuota(context, growth)) | 285 if (!AllocateQuota(context, growth)) |
| 286 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 286 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
| 287 PlatformFileError error = CreateFile( | 287 PlatformFileError error = CreateFile( |
| 288 context, FilePath(), | 288 context, base::FilePath(), |
| 289 url.origin(), url.type(), &file_info, | 289 url.origin(), url.type(), &file_info, |
| 290 file_flags, file_handle); | 290 file_flags, file_handle); |
| 291 if (created && base::PLATFORM_FILE_OK == error) { | 291 if (created && base::PLATFORM_FILE_OK == error) { |
| 292 *created = true; | 292 *created = true; |
| 293 UpdateUsage(context, url, growth); | 293 UpdateUsage(context, url, growth); |
| 294 context->change_observers()->Notify( | 294 context->change_observers()->Notify( |
| 295 &FileChangeObserver::OnCreateFile, MakeTuple(url)); | 295 &FileChangeObserver::OnCreateFile, MakeTuple(url)); |
| 296 } | 296 } |
| 297 return error; | 297 return error; |
| 298 } | 298 } |
| 299 | 299 |
| 300 if (file_flags & base::PLATFORM_FILE_CREATE) | 300 if (file_flags & base::PLATFORM_FILE_CREATE) |
| 301 return base::PLATFORM_FILE_ERROR_EXISTS; | 301 return base::PLATFORM_FILE_ERROR_EXISTS; |
| 302 | 302 |
| 303 base::PlatformFileInfo platform_file_info; | 303 base::PlatformFileInfo platform_file_info; |
| 304 FilePath local_path; | 304 base::FilePath local_path; |
| 305 FileInfo file_info; | 305 FileInfo file_info; |
| 306 base::PlatformFileError error = GetFileInfoInternal( | 306 base::PlatformFileError error = GetFileInfoInternal( |
| 307 db, context, url.origin(), url.type(), file_id, | 307 db, context, url.origin(), url.type(), file_id, |
| 308 &file_info, &platform_file_info, &local_path); | 308 &file_info, &platform_file_info, &local_path); |
| 309 if (error != base::PLATFORM_FILE_OK) | 309 if (error != base::PLATFORM_FILE_OK) |
| 310 return error; | 310 return error; |
| 311 if (file_info.is_directory()) | 311 if (file_info.is_directory()) |
| 312 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 312 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 313 | 313 |
| 314 int64 delta = 0; | 314 int64 delta = 0; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 371 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 372 | 372 |
| 373 FileInfo file_info; | 373 FileInfo file_info; |
| 374 InitFileInfo(&file_info, parent_id, | 374 InitFileInfo(&file_info, parent_id, |
| 375 VirtualPath::BaseName(url.path()).value()); | 375 VirtualPath::BaseName(url.path()).value()); |
| 376 | 376 |
| 377 int64 growth = UsageForPath(file_info.name.size()); | 377 int64 growth = UsageForPath(file_info.name.size()); |
| 378 if (!AllocateQuota(context, growth)) | 378 if (!AllocateQuota(context, growth)) |
| 379 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 379 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
| 380 PlatformFileError error = CreateFile( | 380 PlatformFileError error = CreateFile( |
| 381 context, FilePath(), url.origin(), url.type(), &file_info, 0, NULL); | 381 context, base::FilePath(), url.origin(), url.type(), &file_info, 0, NULL); |
| 382 if (created && base::PLATFORM_FILE_OK == error) { | 382 if (created && base::PLATFORM_FILE_OK == error) { |
| 383 *created = true; | 383 *created = true; |
| 384 UpdateUsage(context, url, growth); | 384 UpdateUsage(context, url, growth); |
| 385 context->change_observers()->Notify( | 385 context->change_observers()->Notify( |
| 386 &FileChangeObserver::OnCreateFile, MakeTuple(url)); | 386 &FileChangeObserver::OnCreateFile, MakeTuple(url)); |
| 387 } | 387 } |
| 388 return error; | 388 return error; |
| 389 } | 389 } |
| 390 | 390 |
| 391 PlatformFileError ObfuscatedFileUtil::CreateDirectory( | 391 PlatformFileError ObfuscatedFileUtil::CreateDirectory( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 414 return base::PLATFORM_FILE_ERROR_EXISTS; | 414 return base::PLATFORM_FILE_ERROR_EXISTS; |
| 415 if (!db->GetFileInfo(file_id, &file_info)) { | 415 if (!db->GetFileInfo(file_id, &file_info)) { |
| 416 NOTREACHED(); | 416 NOTREACHED(); |
| 417 return base::PLATFORM_FILE_ERROR_FAILED; | 417 return base::PLATFORM_FILE_ERROR_FAILED; |
| 418 } | 418 } |
| 419 if (!file_info.is_directory()) | 419 if (!file_info.is_directory()) |
| 420 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 420 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 421 return base::PLATFORM_FILE_OK; | 421 return base::PLATFORM_FILE_OK; |
| 422 } | 422 } |
| 423 | 423 |
| 424 std::vector<FilePath::StringType> components; | 424 std::vector<base::FilePath::StringType> components; |
| 425 VirtualPath::GetComponents(url.path(), &components); | 425 VirtualPath::GetComponents(url.path(), &components); |
| 426 FileId parent_id = 0; | 426 FileId parent_id = 0; |
| 427 size_t index; | 427 size_t index; |
| 428 for (index = 0; index < components.size(); ++index) { | 428 for (index = 0; index < components.size(); ++index) { |
| 429 FilePath::StringType name = components[index]; | 429 base::FilePath::StringType name = components[index]; |
| 430 if (name == FILE_PATH_LITERAL("/")) | 430 if (name == FILE_PATH_LITERAL("/")) |
| 431 continue; | 431 continue; |
| 432 if (!db->GetChildWithName(parent_id, name, &parent_id)) | 432 if (!db->GetChildWithName(parent_id, name, &parent_id)) |
| 433 break; | 433 break; |
| 434 } | 434 } |
| 435 if (!recursive && components.size() - index > 1) | 435 if (!recursive && components.size() - index > 1) |
| 436 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 436 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 437 bool first = true; | 437 bool first = true; |
| 438 for (; index < components.size(); ++index) { | 438 for (; index < components.size(); ++index) { |
| 439 FileInfo file_info; | 439 FileInfo file_info; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 457 TouchDirectory(db, file_info.parent_id); | 457 TouchDirectory(db, file_info.parent_id); |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 return base::PLATFORM_FILE_OK; | 460 return base::PLATFORM_FILE_OK; |
| 461 } | 461 } |
| 462 | 462 |
| 463 PlatformFileError ObfuscatedFileUtil::GetFileInfo( | 463 PlatformFileError ObfuscatedFileUtil::GetFileInfo( |
| 464 FileSystemOperationContext* context, | 464 FileSystemOperationContext* context, |
| 465 const FileSystemURL& url, | 465 const FileSystemURL& url, |
| 466 base::PlatformFileInfo* file_info, | 466 base::PlatformFileInfo* file_info, |
| 467 FilePath* platform_file_path) { | 467 base::FilePath* platform_file_path) { |
| 468 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 468 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 469 url.origin(), url.type(), false); | 469 url.origin(), url.type(), false); |
| 470 if (!db) | 470 if (!db) |
| 471 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 471 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 472 FileId file_id; | 472 FileId file_id; |
| 473 if (!db->GetFileWithPath(url.path(), &file_id)) | 473 if (!db->GetFileWithPath(url.path(), &file_id)) |
| 474 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 474 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 475 FileInfo local_info; | 475 FileInfo local_info; |
| 476 return GetFileInfoInternal(db, context, | 476 return GetFileInfoInternal(db, context, |
| 477 url.origin(), url.type(), | 477 url.origin(), url.type(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 491 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 491 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
| 492 } | 492 } |
| 493 return make_scoped_ptr(new ObfuscatedFileEnumerator(db, context, this, | 493 return make_scoped_ptr(new ObfuscatedFileEnumerator(db, context, this, |
| 494 root_url, recursive)) | 494 root_url, recursive)) |
| 495 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 495 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 PlatformFileError ObfuscatedFileUtil::GetLocalFilePath( | 498 PlatformFileError ObfuscatedFileUtil::GetLocalFilePath( |
| 499 FileSystemOperationContext* context, | 499 FileSystemOperationContext* context, |
| 500 const FileSystemURL& url, | 500 const FileSystemURL& url, |
| 501 FilePath* local_path) { | 501 base::FilePath* local_path) { |
| 502 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 502 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 503 url.origin(), url.type(), false); | 503 url.origin(), url.type(), false); |
| 504 if (!db) | 504 if (!db) |
| 505 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 505 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 506 FileId file_id; | 506 FileId file_id; |
| 507 if (!db->GetFileWithPath(url.path(), &file_id)) | 507 if (!db->GetFileWithPath(url.path(), &file_id)) |
| 508 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 508 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 509 FileInfo file_info; | 509 FileInfo file_info; |
| 510 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { | 510 if (!db->GetFileInfo(file_id, &file_info) || file_info.is_directory()) { |
| 511 NOTREACHED(); | 511 NOTREACHED(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 536 FileInfo file_info; | 536 FileInfo file_info; |
| 537 if (!db->GetFileInfo(file_id, &file_info)) { | 537 if (!db->GetFileInfo(file_id, &file_info)) { |
| 538 NOTREACHED(); | 538 NOTREACHED(); |
| 539 return base::PLATFORM_FILE_ERROR_FAILED; | 539 return base::PLATFORM_FILE_ERROR_FAILED; |
| 540 } | 540 } |
| 541 if (file_info.is_directory()) { | 541 if (file_info.is_directory()) { |
| 542 if (!db->UpdateModificationTime(file_id, last_modified_time)) | 542 if (!db->UpdateModificationTime(file_id, last_modified_time)) |
| 543 return base::PLATFORM_FILE_ERROR_FAILED; | 543 return base::PLATFORM_FILE_ERROR_FAILED; |
| 544 return base::PLATFORM_FILE_OK; | 544 return base::PLATFORM_FILE_OK; |
| 545 } | 545 } |
| 546 FilePath local_path = DataPathToLocalPath( | 546 base::FilePath local_path = DataPathToLocalPath( |
| 547 url.origin(), url.type(), file_info.data_path); | 547 url.origin(), url.type(), file_info.data_path); |
| 548 return NativeFileUtil::Touch( | 548 return NativeFileUtil::Touch( |
| 549 local_path, last_access_time, last_modified_time); | 549 local_path, last_access_time, last_modified_time); |
| 550 } | 550 } |
| 551 | 551 |
| 552 PlatformFileError ObfuscatedFileUtil::Truncate( | 552 PlatformFileError ObfuscatedFileUtil::Truncate( |
| 553 FileSystemOperationContext* context, | 553 FileSystemOperationContext* context, |
| 554 const FileSystemURL& url, | 554 const FileSystemURL& url, |
| 555 int64 length) { | 555 int64 length) { |
| 556 base::PlatformFileInfo file_info; | 556 base::PlatformFileInfo file_info; |
| 557 FilePath local_path; | 557 base::FilePath local_path; |
| 558 base::PlatformFileError error = | 558 base::PlatformFileError error = |
| 559 GetFileInfo(context, url, &file_info, &local_path); | 559 GetFileInfo(context, url, &file_info, &local_path); |
| 560 if (error != base::PLATFORM_FILE_OK) | 560 if (error != base::PLATFORM_FILE_OK) |
| 561 return error; | 561 return error; |
| 562 | 562 |
| 563 int64 growth = length - file_info.size; | 563 int64 growth = length - file_info.size; |
| 564 if (!AllocateQuota(context, growth)) | 564 if (!AllocateQuota(context, growth)) |
| 565 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 565 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
| 566 error = NativeFileUtil::Truncate(local_path, length); | 566 error = NativeFileUtil::Truncate(local_path, length); |
| 567 if (error == base::PLATFORM_FILE_OK) { | 567 if (error == base::PLATFORM_FILE_OK) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 589 FileId src_file_id; | 589 FileId src_file_id; |
| 590 if (!db->GetFileWithPath(src_url.path(), &src_file_id)) | 590 if (!db->GetFileWithPath(src_url.path(), &src_file_id)) |
| 591 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 591 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 592 | 592 |
| 593 FileId dest_file_id; | 593 FileId dest_file_id; |
| 594 bool overwrite = db->GetFileWithPath(dest_url.path(), | 594 bool overwrite = db->GetFileWithPath(dest_url.path(), |
| 595 &dest_file_id); | 595 &dest_file_id); |
| 596 | 596 |
| 597 FileInfo src_file_info; | 597 FileInfo src_file_info; |
| 598 base::PlatformFileInfo src_platform_file_info; | 598 base::PlatformFileInfo src_platform_file_info; |
| 599 FilePath src_local_path; | 599 base::FilePath src_local_path; |
| 600 base::PlatformFileError error = GetFileInfoInternal( | 600 base::PlatformFileError error = GetFileInfoInternal( |
| 601 db, context, src_url.origin(), src_url.type(), src_file_id, | 601 db, context, src_url.origin(), src_url.type(), src_file_id, |
| 602 &src_file_info, &src_platform_file_info, &src_local_path); | 602 &src_file_info, &src_platform_file_info, &src_local_path); |
| 603 if (error != base::PLATFORM_FILE_OK) | 603 if (error != base::PLATFORM_FILE_OK) |
| 604 return error; | 604 return error; |
| 605 if (src_file_info.is_directory()) | 605 if (src_file_info.is_directory()) |
| 606 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 606 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 607 | 607 |
| 608 FileInfo dest_file_info; | 608 FileInfo dest_file_info; |
| 609 base::PlatformFileInfo dest_platform_file_info; // overwrite case only | 609 base::PlatformFileInfo dest_platform_file_info; // overwrite case only |
| 610 FilePath dest_local_path; // overwrite case only | 610 base::FilePath dest_local_path; // overwrite case only |
| 611 if (overwrite) { | 611 if (overwrite) { |
| 612 base::PlatformFileError error = GetFileInfoInternal( | 612 base::PlatformFileError error = GetFileInfoInternal( |
| 613 db, context, dest_url.origin(), dest_url.type(), dest_file_id, | 613 db, context, dest_url.origin(), dest_url.type(), dest_file_id, |
| 614 &dest_file_info, &dest_platform_file_info, &dest_local_path); | 614 &dest_file_info, &dest_platform_file_info, &dest_local_path); |
| 615 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 615 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
| 616 overwrite = false; // fallback to non-overwrite case | 616 overwrite = false; // fallback to non-overwrite case |
| 617 else if (error != base::PLATFORM_FILE_OK) | 617 else if (error != base::PLATFORM_FILE_OK) |
| 618 return error; | 618 return error; |
| 619 else if (dest_file_info.is_directory()) | 619 else if (dest_file_info.is_directory()) |
| 620 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 620 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 } | 708 } |
| 709 | 709 |
| 710 TouchDirectory(db, dest_file_info.parent_id); | 710 TouchDirectory(db, dest_file_info.parent_id); |
| 711 | 711 |
| 712 UpdateUsage(context, dest_url, growth); | 712 UpdateUsage(context, dest_url, growth); |
| 713 return error; | 713 return error; |
| 714 } | 714 } |
| 715 | 715 |
| 716 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( | 716 PlatformFileError ObfuscatedFileUtil::CopyInForeignFile( |
| 717 FileSystemOperationContext* context, | 717 FileSystemOperationContext* context, |
| 718 const FilePath& src_file_path, | 718 const base::FilePath& src_file_path, |
| 719 const FileSystemURL& dest_url) { | 719 const FileSystemURL& dest_url) { |
| 720 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 720 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 721 dest_url.origin(), dest_url.type(), true); | 721 dest_url.origin(), dest_url.type(), true); |
| 722 if (!db) | 722 if (!db) |
| 723 return base::PLATFORM_FILE_ERROR_FAILED; | 723 return base::PLATFORM_FILE_ERROR_FAILED; |
| 724 | 724 |
| 725 base::PlatformFileInfo src_platform_file_info; | 725 base::PlatformFileInfo src_platform_file_info; |
| 726 if (!file_util::GetFileInfo(src_file_path, &src_platform_file_info)) | 726 if (!file_util::GetFileInfo(src_file_path, &src_platform_file_info)) |
| 727 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 727 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 728 | 728 |
| 729 FileId dest_file_id; | 729 FileId dest_file_id; |
| 730 bool overwrite = db->GetFileWithPath(dest_url.path(), | 730 bool overwrite = db->GetFileWithPath(dest_url.path(), |
| 731 &dest_file_id); | 731 &dest_file_id); |
| 732 | 732 |
| 733 FileInfo dest_file_info; | 733 FileInfo dest_file_info; |
| 734 base::PlatformFileInfo dest_platform_file_info; // overwrite case only | 734 base::PlatformFileInfo dest_platform_file_info; // overwrite case only |
| 735 if (overwrite) { | 735 if (overwrite) { |
| 736 FilePath dest_local_path; | 736 base::FilePath dest_local_path; |
| 737 base::PlatformFileError error = GetFileInfoInternal( | 737 base::PlatformFileError error = GetFileInfoInternal( |
| 738 db, context, dest_url.origin(), dest_url.type(), dest_file_id, | 738 db, context, dest_url.origin(), dest_url.type(), dest_file_id, |
| 739 &dest_file_info, &dest_platform_file_info, &dest_local_path); | 739 &dest_file_info, &dest_platform_file_info, &dest_local_path); |
| 740 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 740 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
| 741 overwrite = false; // fallback to non-overwrite case | 741 overwrite = false; // fallback to non-overwrite case |
| 742 else if (error != base::PLATFORM_FILE_OK) | 742 else if (error != base::PLATFORM_FILE_OK) |
| 743 return error; | 743 return error; |
| 744 else if (dest_file_info.is_directory()) | 744 else if (dest_file_info.is_directory()) |
| 745 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 745 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 746 } | 746 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 759 int64 growth = src_platform_file_info.size; | 759 int64 growth = src_platform_file_info.size; |
| 760 if (overwrite) | 760 if (overwrite) |
| 761 growth -= dest_platform_file_info.size; | 761 growth -= dest_platform_file_info.size; |
| 762 else | 762 else |
| 763 growth += UsageForPath(dest_file_info.name.size()); | 763 growth += UsageForPath(dest_file_info.name.size()); |
| 764 if (!AllocateQuota(context, growth)) | 764 if (!AllocateQuota(context, growth)) |
| 765 return base::PLATFORM_FILE_ERROR_NO_SPACE; | 765 return base::PLATFORM_FILE_ERROR_NO_SPACE; |
| 766 | 766 |
| 767 base::PlatformFileError error; | 767 base::PlatformFileError error; |
| 768 if (overwrite) { | 768 if (overwrite) { |
| 769 FilePath dest_local_path = DataPathToLocalPath( | 769 base::FilePath dest_local_path = DataPathToLocalPath( |
| 770 dest_url.origin(), dest_url.type(), dest_file_info.data_path); | 770 dest_url.origin(), dest_url.type(), dest_file_info.data_path); |
| 771 error = NativeFileUtil::CopyOrMoveFile( | 771 error = NativeFileUtil::CopyOrMoveFile( |
| 772 src_file_path, dest_local_path, true); | 772 src_file_path, dest_local_path, true); |
| 773 } else { | 773 } else { |
| 774 error = CreateFile(context, src_file_path, | 774 error = CreateFile(context, src_file_path, |
| 775 dest_url.origin(), dest_url.type(), | 775 dest_url.origin(), dest_url.type(), |
| 776 &dest_file_info, 0, NULL); | 776 &dest_file_info, 0, NULL); |
| 777 } | 777 } |
| 778 | 778 |
| 779 if (error != base::PLATFORM_FILE_OK) | 779 if (error != base::PLATFORM_FILE_OK) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 798 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 798 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 799 url.origin(), url.type(), true); | 799 url.origin(), url.type(), true); |
| 800 if (!db) | 800 if (!db) |
| 801 return base::PLATFORM_FILE_ERROR_FAILED; | 801 return base::PLATFORM_FILE_ERROR_FAILED; |
| 802 FileId file_id; | 802 FileId file_id; |
| 803 if (!db->GetFileWithPath(url.path(), &file_id)) | 803 if (!db->GetFileWithPath(url.path(), &file_id)) |
| 804 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 804 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 805 | 805 |
| 806 FileInfo file_info; | 806 FileInfo file_info; |
| 807 base::PlatformFileInfo platform_file_info; | 807 base::PlatformFileInfo platform_file_info; |
| 808 FilePath local_path; | 808 base::FilePath local_path; |
| 809 base::PlatformFileError error = GetFileInfoInternal( | 809 base::PlatformFileError error = GetFileInfoInternal( |
| 810 db, context, url.origin(), url.type(), file_id, | 810 db, context, url.origin(), url.type(), file_id, |
| 811 &file_info, &platform_file_info, &local_path); | 811 &file_info, &platform_file_info, &local_path); |
| 812 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && | 812 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && |
| 813 error != base::PLATFORM_FILE_OK) | 813 error != base::PLATFORM_FILE_OK) |
| 814 return error; | 814 return error; |
| 815 | 815 |
| 816 if (file_info.is_directory()) | 816 if (file_info.is_directory()) |
| 817 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 817 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 818 | 818 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 TouchDirectory(db, file_info.parent_id); | 863 TouchDirectory(db, file_info.parent_id); |
| 864 context->change_observers()->Notify( | 864 context->change_observers()->Notify( |
| 865 &FileChangeObserver::OnRemoveDirectory, MakeTuple(url)); | 865 &FileChangeObserver::OnRemoveDirectory, MakeTuple(url)); |
| 866 return base::PLATFORM_FILE_OK; | 866 return base::PLATFORM_FILE_OK; |
| 867 } | 867 } |
| 868 | 868 |
| 869 base::PlatformFileError ObfuscatedFileUtil::CreateSnapshotFile( | 869 base::PlatformFileError ObfuscatedFileUtil::CreateSnapshotFile( |
| 870 FileSystemOperationContext* context, | 870 FileSystemOperationContext* context, |
| 871 const FileSystemURL& url, | 871 const FileSystemURL& url, |
| 872 base::PlatformFileInfo* file_info, | 872 base::PlatformFileInfo* file_info, |
| 873 FilePath* platform_path, | 873 base::FilePath* platform_path, |
| 874 SnapshotFilePolicy* policy) { | 874 SnapshotFilePolicy* policy) { |
| 875 DCHECK(policy); | 875 DCHECK(policy); |
| 876 // We're just returning the local file information. | 876 // We're just returning the local file information. |
| 877 *policy = kSnapshotFileLocal; | 877 *policy = kSnapshotFileLocal; |
| 878 base::PlatformFileError error = GetFileInfo( | 878 base::PlatformFileError error = GetFileInfo( |
| 879 context, url, file_info, platform_path); | 879 context, url, file_info, platform_path); |
| 880 if (error == base::PLATFORM_FILE_OK && file_info->is_directory) { | 880 if (error == base::PLATFORM_FILE_OK && file_info->is_directory) { |
| 881 *file_info = base::PlatformFileInfo(); | 881 *file_info = base::PlatformFileInfo(); |
| 882 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 882 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 883 } | 883 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 902 } | 902 } |
| 903 if (!file_info.is_directory()) | 903 if (!file_info.is_directory()) |
| 904 return true; | 904 return true; |
| 905 std::vector<FileId> children; | 905 std::vector<FileId> children; |
| 906 // TODO(ericu): This could easily be made faster with help from the database. | 906 // TODO(ericu): This could easily be made faster with help from the database. |
| 907 if (!db->ListChildren(file_id, &children)) | 907 if (!db->ListChildren(file_id, &children)) |
| 908 return true; | 908 return true; |
| 909 return children.empty(); | 909 return children.empty(); |
| 910 } | 910 } |
| 911 | 911 |
| 912 FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType( | 912 base::FilePath ObfuscatedFileUtil::GetDirectoryForOriginAndType( |
| 913 const GURL& origin, | 913 const GURL& origin, |
| 914 FileSystemType type, | 914 FileSystemType type, |
| 915 bool create, | 915 bool create, |
| 916 base::PlatformFileError* error_code) { | 916 base::PlatformFileError* error_code) { |
| 917 FilePath origin_dir = GetDirectoryForOrigin(origin, create, error_code); | 917 base::FilePath origin_dir = GetDirectoryForOrigin(origin, create, error_code); |
| 918 if (origin_dir.empty()) | 918 if (origin_dir.empty()) |
| 919 return FilePath(); | 919 return base::FilePath(); |
| 920 FilePath::StringType type_string = GetDirectoryNameForType(type); | 920 base::FilePath::StringType type_string = GetDirectoryNameForType(type); |
| 921 if (type_string.empty()) { | 921 if (type_string.empty()) { |
| 922 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 922 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 923 | 923 |
| 924 if (error_code) | 924 if (error_code) |
| 925 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; | 925 *error_code = base::PLATFORM_FILE_ERROR_INVALID_URL; |
| 926 return FilePath(); | 926 return base::FilePath(); |
| 927 } | 927 } |
| 928 FilePath path = origin_dir.Append(type_string); | 928 base::FilePath path = origin_dir.Append(type_string); |
| 929 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 929 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 930 if (!file_util::DirectoryExists(path) && | 930 if (!file_util::DirectoryExists(path) && |
| 931 (!create || !file_util::CreateDirectory(path))) { | 931 (!create || !file_util::CreateDirectory(path))) { |
| 932 error = create ? | 932 error = create ? |
| 933 base::PLATFORM_FILE_ERROR_FAILED : | 933 base::PLATFORM_FILE_ERROR_FAILED : |
| 934 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 934 base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 935 } | 935 } |
| 936 | 936 |
| 937 if (error_code) | 937 if (error_code) |
| 938 *error_code = error; | 938 *error_code = error; |
| 939 return path; | 939 return path; |
| 940 } | 940 } |
| 941 | 941 |
| 942 bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType( | 942 bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType( |
| 943 const GURL& origin, FileSystemType type) { | 943 const GURL& origin, FileSystemType type) { |
| 944 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 944 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 945 FilePath origin_type_path = GetDirectoryForOriginAndType(origin, type, false, | 945 base::FilePath origin_type_path = GetDirectoryForOriginAndType(origin, type, f
alse, |
| 946 &error); | 946 &error); |
| 947 if (origin_type_path.empty()) | 947 if (origin_type_path.empty()) |
| 948 return true; | 948 return true; |
| 949 | 949 |
| 950 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND) { | 950 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND) { |
| 951 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase. | 951 // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase. |
| 952 // We ignore its error now since 1) it doesn't matter the final result, and | 952 // We ignore its error now since 1) it doesn't matter the final result, and |
| 953 // 2) it always returns false in Windows because of LevelDB's | 953 // 2) it always returns false in Windows because of LevelDB's |
| 954 // implementation. | 954 // implementation. |
| 955 // Information about failure would be useful for debugging. | 955 // Information about failure would be useful for debugging. |
| 956 DestroyDirectoryDatabase(origin, type); | 956 DestroyDirectoryDatabase(origin, type); |
| 957 if (!file_util::Delete(origin_type_path, true /* recursive */)) | 957 if (!file_util::Delete(origin_type_path, true /* recursive */)) |
| 958 return false; | 958 return false; |
| 959 } | 959 } |
| 960 | 960 |
| 961 FilePath origin_path = origin_type_path.DirName(); | 961 base::FilePath origin_path = origin_type_path.DirName(); |
| 962 DCHECK_EQ(origin_path.value(), | 962 DCHECK_EQ(origin_path.value(), |
| 963 GetDirectoryForOrigin(origin, false, NULL).value()); | 963 GetDirectoryForOrigin(origin, false, NULL).value()); |
| 964 | 964 |
| 965 // At this point we are sure we had successfully deleted the origin/type | 965 // At this point we are sure we had successfully deleted the origin/type |
| 966 // directory (i.e. we're ready to just return true). | 966 // directory (i.e. we're ready to just return true). |
| 967 // See if we have other directories in this origin directory. | 967 // See if we have other directories in this origin directory. |
| 968 std::vector<FileSystemType> other_types; | 968 std::vector<FileSystemType> other_types; |
| 969 if (type != kFileSystemTypeTemporary) | 969 if (type != kFileSystemTypeTemporary) |
| 970 other_types.push_back(kFileSystemTypeTemporary); | 970 other_types.push_back(kFileSystemTypeTemporary); |
| 971 if (type != kFileSystemTypePersistent) | 971 if (type != kFileSystemTypePersistent) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 985 InitOriginDatabase(false); | 985 InitOriginDatabase(false); |
| 986 if (origin_database_.get()) | 986 if (origin_database_.get()) |
| 987 origin_database_->RemovePathForOrigin(GetOriginIdentifierFromURL(origin)); | 987 origin_database_->RemovePathForOrigin(GetOriginIdentifierFromURL(origin)); |
| 988 if (!file_util::Delete(origin_path, true /* recursive */)) | 988 if (!file_util::Delete(origin_path, true /* recursive */)) |
| 989 return false; | 989 return false; |
| 990 | 990 |
| 991 return true; | 991 return true; |
| 992 } | 992 } |
| 993 | 993 |
| 994 // static | 994 // static |
| 995 FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType( | 995 base::FilePath::StringType ObfuscatedFileUtil::GetDirectoryNameForType( |
| 996 FileSystemType type) { | 996 FileSystemType type) { |
| 997 switch (type) { | 997 switch (type) { |
| 998 case kFileSystemTypeTemporary: | 998 case kFileSystemTypeTemporary: |
| 999 return kTemporaryDirectoryName; | 999 return kTemporaryDirectoryName; |
| 1000 case kFileSystemTypePersistent: | 1000 case kFileSystemTypePersistent: |
| 1001 return kPersistentDirectoryName; | 1001 return kPersistentDirectoryName; |
| 1002 case kFileSystemTypeSyncable: | 1002 case kFileSystemTypeSyncable: |
| 1003 return kSyncableDirectoryName; | 1003 return kSyncableDirectoryName; |
| 1004 case kFileSystemTypeUnknown: | 1004 case kFileSystemTypeUnknown: |
| 1005 default: | 1005 default: |
| 1006 return FilePath::StringType(); | 1006 return base::FilePath::StringType(); |
| 1007 } | 1007 } |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 ObfuscatedFileUtil::AbstractOriginEnumerator* | 1010 ObfuscatedFileUtil::AbstractOriginEnumerator* |
| 1011 ObfuscatedFileUtil::CreateOriginEnumerator() { | 1011 ObfuscatedFileUtil::CreateOriginEnumerator() { |
| 1012 std::vector<FileSystemOriginDatabase::OriginRecord> origins; | 1012 std::vector<FileSystemOriginDatabase::OriginRecord> origins; |
| 1013 | 1013 |
| 1014 InitOriginDatabase(false); | 1014 InitOriginDatabase(false); |
| 1015 return new ObfuscatedOriginEnumerator( | 1015 return new ObfuscatedOriginEnumerator( |
| 1016 origin_database_.get(), file_system_directory_); | 1016 origin_database_.get(), file_system_directory_); |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 bool ObfuscatedFileUtil::DestroyDirectoryDatabase( | 1019 bool ObfuscatedFileUtil::DestroyDirectoryDatabase( |
| 1020 const GURL& origin, FileSystemType type) { | 1020 const GURL& origin, FileSystemType type) { |
| 1021 std::string type_string = GetFileSystemTypeString(type); | 1021 std::string type_string = GetFileSystemTypeString(type); |
| 1022 if (type_string.empty()) { | 1022 if (type_string.empty()) { |
| 1023 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 1023 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 1024 return true; | 1024 return true; |
| 1025 } | 1025 } |
| 1026 std::string key = GetOriginIdentifierFromURL(origin) + type_string; | 1026 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
| 1027 DirectoryMap::iterator iter = directories_.find(key); | 1027 DirectoryMap::iterator iter = directories_.find(key); |
| 1028 if (iter != directories_.end()) { | 1028 if (iter != directories_.end()) { |
| 1029 FileSystemDirectoryDatabase* database = iter->second; | 1029 FileSystemDirectoryDatabase* database = iter->second; |
| 1030 directories_.erase(iter); | 1030 directories_.erase(iter); |
| 1031 delete database; | 1031 delete database; |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 PlatformFileError error = base::PLATFORM_FILE_OK; | 1034 PlatformFileError error = base::PLATFORM_FILE_OK; |
| 1035 FilePath path = GetDirectoryForOriginAndType(origin, type, false, &error); | 1035 base::FilePath path = GetDirectoryForOriginAndType(origin, type, false, &error
); |
| 1036 if (path.empty() || error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 1036 if (path.empty() || error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
| 1037 return true; | 1037 return true; |
| 1038 return FileSystemDirectoryDatabase::DestroyDatabase(path); | 1038 return FileSystemDirectoryDatabase::DestroyDatabase(path); |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 // static | 1041 // static |
| 1042 int64 ObfuscatedFileUtil::ComputeFilePathCost(const FilePath& path) { | 1042 int64 ObfuscatedFileUtil::ComputeFilePathCost(const base::FilePath& path) { |
| 1043 return UsageForPath(VirtualPath::BaseName(path).value().size()); | 1043 return UsageForPath(VirtualPath::BaseName(path).value().size()); |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( | 1046 PlatformFileError ObfuscatedFileUtil::GetFileInfoInternal( |
| 1047 FileSystemDirectoryDatabase* db, | 1047 FileSystemDirectoryDatabase* db, |
| 1048 FileSystemOperationContext* context, | 1048 FileSystemOperationContext* context, |
| 1049 const GURL& origin, | 1049 const GURL& origin, |
| 1050 FileSystemType type, | 1050 FileSystemType type, |
| 1051 FileId file_id, | 1051 FileId file_id, |
| 1052 FileInfo* local_info, | 1052 FileInfo* local_info, |
| 1053 base::PlatformFileInfo* file_info, | 1053 base::PlatformFileInfo* file_info, |
| 1054 FilePath* platform_file_path) { | 1054 base::FilePath* platform_file_path) { |
| 1055 DCHECK(db); | 1055 DCHECK(db); |
| 1056 DCHECK(context); | 1056 DCHECK(context); |
| 1057 DCHECK(file_info); | 1057 DCHECK(file_info); |
| 1058 DCHECK(platform_file_path); | 1058 DCHECK(platform_file_path); |
| 1059 | 1059 |
| 1060 if (!db->GetFileInfo(file_id, local_info)) { | 1060 if (!db->GetFileInfo(file_id, local_info)) { |
| 1061 NOTREACHED(); | 1061 NOTREACHED(); |
| 1062 return base::PLATFORM_FILE_ERROR_FAILED; | 1062 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 if (local_info->is_directory()) { | 1065 if (local_info->is_directory()) { |
| 1066 file_info->size = 0; | 1066 file_info->size = 0; |
| 1067 file_info->is_directory = true; | 1067 file_info->is_directory = true; |
| 1068 file_info->is_symbolic_link = false; | 1068 file_info->is_symbolic_link = false; |
| 1069 file_info->last_modified = local_info->modification_time; | 1069 file_info->last_modified = local_info->modification_time; |
| 1070 *platform_file_path = FilePath(); | 1070 *platform_file_path = base::FilePath(); |
| 1071 // We don't fill in ctime or atime. | 1071 // We don't fill in ctime or atime. |
| 1072 return base::PLATFORM_FILE_OK; | 1072 return base::PLATFORM_FILE_OK; |
| 1073 } | 1073 } |
| 1074 if (local_info->data_path.empty()) | 1074 if (local_info->data_path.empty()) |
| 1075 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1075 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 1076 FilePath local_path = DataPathToLocalPath( | 1076 base::FilePath local_path = DataPathToLocalPath( |
| 1077 origin, type, local_info->data_path); | 1077 origin, type, local_info->data_path); |
| 1078 base::PlatformFileError error = NativeFileUtil::GetFileInfo( | 1078 base::PlatformFileError error = NativeFileUtil::GetFileInfo( |
| 1079 local_path, file_info); | 1079 local_path, file_info); |
| 1080 // We should not follow symbolic links in sandboxed file system. | 1080 // We should not follow symbolic links in sandboxed file system. |
| 1081 if (file_util::IsLink(local_path)) { | 1081 if (file_util::IsLink(local_path)) { |
| 1082 LOG(WARNING) << "Found a symbolic file."; | 1082 LOG(WARNING) << "Found a symbolic file."; |
| 1083 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1083 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1084 } | 1084 } |
| 1085 if (error == base::PLATFORM_FILE_OK) { | 1085 if (error == base::PLATFORM_FILE_OK) { |
| 1086 *platform_file_path = local_path; | 1086 *platform_file_path = local_path; |
| 1087 } else if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) { | 1087 } else if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) { |
| 1088 LOG(WARNING) << "Lost a backing file."; | 1088 LOG(WARNING) << "Lost a backing file."; |
| 1089 InvalidateUsageCache(context, origin, type); | 1089 InvalidateUsageCache(context, origin, type); |
| 1090 if (!db->RemoveFileInfo(file_id)) | 1090 if (!db->RemoveFileInfo(file_id)) |
| 1091 return base::PLATFORM_FILE_ERROR_FAILED; | 1091 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1092 } | 1092 } |
| 1093 return error; | 1093 return error; |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 PlatformFileError ObfuscatedFileUtil::CreateFile( | 1096 PlatformFileError ObfuscatedFileUtil::CreateFile( |
| 1097 FileSystemOperationContext* context, | 1097 FileSystemOperationContext* context, |
| 1098 const FilePath& src_file_path, | 1098 const base::FilePath& src_file_path, |
| 1099 const GURL& dest_origin, | 1099 const GURL& dest_origin, |
| 1100 FileSystemType dest_type, | 1100 FileSystemType dest_type, |
| 1101 FileInfo* dest_file_info, int file_flags, PlatformFile* handle) { | 1101 FileInfo* dest_file_info, int file_flags, PlatformFile* handle) { |
| 1102 if (handle) | 1102 if (handle) |
| 1103 *handle = base::kInvalidPlatformFileValue; | 1103 *handle = base::kInvalidPlatformFileValue; |
| 1104 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( | 1104 FileSystemDirectoryDatabase* db = GetDirectoryDatabase( |
| 1105 dest_origin, dest_type, true); | 1105 dest_origin, dest_type, true); |
| 1106 | 1106 |
| 1107 PlatformFileError error = base::PLATFORM_FILE_OK; | 1107 PlatformFileError error = base::PLATFORM_FILE_OK; |
| 1108 FilePath root = GetDirectoryForOriginAndType(dest_origin, dest_type, false, | 1108 base::FilePath root = GetDirectoryForOriginAndType(dest_origin, dest_type, fal
se, |
| 1109 &error); | 1109 &error); |
| 1110 if (error != base::PLATFORM_FILE_OK) | 1110 if (error != base::PLATFORM_FILE_OK) |
| 1111 return error; | 1111 return error; |
| 1112 | 1112 |
| 1113 FilePath dest_local_path; | 1113 base::FilePath dest_local_path; |
| 1114 error = GenerateNewLocalPath(db, context, dest_origin, dest_type, | 1114 error = GenerateNewLocalPath(db, context, dest_origin, dest_type, |
| 1115 &dest_local_path); | 1115 &dest_local_path); |
| 1116 if (error != base::PLATFORM_FILE_OK) | 1116 if (error != base::PLATFORM_FILE_OK) |
| 1117 return error; | 1117 return error; |
| 1118 | 1118 |
| 1119 bool created = false; | 1119 bool created = false; |
| 1120 if (!src_file_path.empty()) { | 1120 if (!src_file_path.empty()) { |
| 1121 DCHECK(!file_flags); | 1121 DCHECK(!file_flags); |
| 1122 DCHECK(!handle); | 1122 DCHECK(!handle); |
| 1123 error = NativeFileUtil::CopyOrMoveFile( | 1123 error = NativeFileUtil::CopyOrMoveFile( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1150 if (handle) { | 1150 if (handle) { |
| 1151 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); | 1151 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); |
| 1152 base::ClosePlatformFile(*handle); | 1152 base::ClosePlatformFile(*handle); |
| 1153 file_util::Delete(dest_local_path, false /* recursive */); | 1153 file_util::Delete(dest_local_path, false /* recursive */); |
| 1154 } | 1154 } |
| 1155 return base::PLATFORM_FILE_ERROR_FAILED; | 1155 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 // This removes the root, including the trailing slash, leaving a relative | 1158 // This removes the root, including the trailing slash, leaving a relative |
| 1159 // path. | 1159 // path. |
| 1160 dest_file_info->data_path = FilePath( | 1160 dest_file_info->data_path = base::FilePath( |
| 1161 dest_local_path.value().substr(root.value().length() + 1)); | 1161 dest_local_path.value().substr(root.value().length() + 1)); |
| 1162 | 1162 |
| 1163 FileId file_id; | 1163 FileId file_id; |
| 1164 if (!db->AddFileInfo(*dest_file_info, &file_id)) { | 1164 if (!db->AddFileInfo(*dest_file_info, &file_id)) { |
| 1165 if (handle) { | 1165 if (handle) { |
| 1166 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); | 1166 DCHECK_NE(base::kInvalidPlatformFileValue, *handle); |
| 1167 base::ClosePlatformFile(*handle); | 1167 base::ClosePlatformFile(*handle); |
| 1168 } | 1168 } |
| 1169 file_util::Delete(dest_local_path, false /* recursive */); | 1169 file_util::Delete(dest_local_path, false /* recursive */); |
| 1170 return base::PLATFORM_FILE_ERROR_FAILED; | 1170 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1171 } | 1171 } |
| 1172 TouchDirectory(db, dest_file_info->parent_id); | 1172 TouchDirectory(db, dest_file_info->parent_id); |
| 1173 | 1173 |
| 1174 return base::PLATFORM_FILE_OK; | 1174 return base::PLATFORM_FILE_OK; |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 FilePath ObfuscatedFileUtil::DataPathToLocalPath( | 1177 base::FilePath ObfuscatedFileUtil::DataPathToLocalPath( |
| 1178 const GURL& origin, FileSystemType type, const FilePath& data_path) { | 1178 const GURL& origin, FileSystemType type, const base::FilePath& data_path) { |
| 1179 PlatformFileError error = base::PLATFORM_FILE_OK; | 1179 PlatformFileError error = base::PLATFORM_FILE_OK; |
| 1180 FilePath root = GetDirectoryForOriginAndType(origin, type, false, &error); | 1180 base::FilePath root = GetDirectoryForOriginAndType(origin, type, false, &error
); |
| 1181 if (error != base::PLATFORM_FILE_OK) | 1181 if (error != base::PLATFORM_FILE_OK) |
| 1182 return FilePath(); | 1182 return base::FilePath(); |
| 1183 return root.Append(data_path); | 1183 return root.Append(data_path); |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 // TODO(ericu): How to do the whole validation-without-creation thing? | 1186 // TODO(ericu): How to do the whole validation-without-creation thing? |
| 1187 // We may not have quota even to create the database. | 1187 // We may not have quota even to create the database. |
| 1188 // Ah, in that case don't even get here? | 1188 // Ah, in that case don't even get here? |
| 1189 // Still doesn't answer the quota issue, though. | 1189 // Still doesn't answer the quota issue, though. |
| 1190 FileSystemDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( | 1190 FileSystemDirectoryDatabase* ObfuscatedFileUtil::GetDirectoryDatabase( |
| 1191 const GURL& origin, FileSystemType type, bool create) { | 1191 const GURL& origin, FileSystemType type, bool create) { |
| 1192 std::string type_string = GetFileSystemTypeString(type); | 1192 std::string type_string = GetFileSystemTypeString(type); |
| 1193 if (type_string.empty()) { | 1193 if (type_string.empty()) { |
| 1194 LOG(WARNING) << "Unknown filesystem type requested:" << type; | 1194 LOG(WARNING) << "Unknown filesystem type requested:" << type; |
| 1195 return NULL; | 1195 return NULL; |
| 1196 } | 1196 } |
| 1197 std::string key = GetOriginIdentifierFromURL(origin) + type_string; | 1197 std::string key = GetOriginIdentifierFromURL(origin) + type_string; |
| 1198 DirectoryMap::iterator iter = directories_.find(key); | 1198 DirectoryMap::iterator iter = directories_.find(key); |
| 1199 if (iter != directories_.end()) { | 1199 if (iter != directories_.end()) { |
| 1200 MarkUsed(); | 1200 MarkUsed(); |
| 1201 return iter->second; | 1201 return iter->second; |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 PlatformFileError error = base::PLATFORM_FILE_OK; | 1204 PlatformFileError error = base::PLATFORM_FILE_OK; |
| 1205 FilePath path = GetDirectoryForOriginAndType(origin, type, create, &error); | 1205 base::FilePath path = GetDirectoryForOriginAndType(origin, type, create, &erro
r); |
| 1206 if (error != base::PLATFORM_FILE_OK) { | 1206 if (error != base::PLATFORM_FILE_OK) { |
| 1207 LOG(WARNING) << "Failed to get origin+type directory: " << path.value(); | 1207 LOG(WARNING) << "Failed to get origin+type directory: " << path.value(); |
| 1208 return NULL; | 1208 return NULL; |
| 1209 } | 1209 } |
| 1210 MarkUsed(); | 1210 MarkUsed(); |
| 1211 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); | 1211 FileSystemDirectoryDatabase* database = new FileSystemDirectoryDatabase(path); |
| 1212 directories_[key] = database; | 1212 directories_[key] = database; |
| 1213 return database; | 1213 return database; |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( | 1216 base::FilePath ObfuscatedFileUtil::GetDirectoryForOrigin( |
| 1217 const GURL& origin, bool create, base::PlatformFileError* error_code) { | 1217 const GURL& origin, bool create, base::PlatformFileError* error_code) { |
| 1218 if (!InitOriginDatabase(create)) { | 1218 if (!InitOriginDatabase(create)) { |
| 1219 if (error_code) { | 1219 if (error_code) { |
| 1220 *error_code = create ? | 1220 *error_code = create ? |
| 1221 base::PLATFORM_FILE_ERROR_FAILED : | 1221 base::PLATFORM_FILE_ERROR_FAILED : |
| 1222 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1222 base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1223 } | 1223 } |
| 1224 return FilePath(); | 1224 return base::FilePath(); |
| 1225 } | 1225 } |
| 1226 FilePath directory_name; | 1226 base::FilePath directory_name; |
| 1227 std::string id = GetOriginIdentifierFromURL(origin); | 1227 std::string id = GetOriginIdentifierFromURL(origin); |
| 1228 | 1228 |
| 1229 bool exists_in_db = origin_database_->HasOriginPath(id); | 1229 bool exists_in_db = origin_database_->HasOriginPath(id); |
| 1230 if (!exists_in_db && !create) { | 1230 if (!exists_in_db && !create) { |
| 1231 if (error_code) | 1231 if (error_code) |
| 1232 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1232 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1233 return FilePath(); | 1233 return base::FilePath(); |
| 1234 } | 1234 } |
| 1235 if (!origin_database_->GetPathForOrigin(id, &directory_name)) { | 1235 if (!origin_database_->GetPathForOrigin(id, &directory_name)) { |
| 1236 if (error_code) | 1236 if (error_code) |
| 1237 *error_code = base::PLATFORM_FILE_ERROR_FAILED; | 1237 *error_code = base::PLATFORM_FILE_ERROR_FAILED; |
| 1238 return FilePath(); | 1238 return base::FilePath(); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 FilePath path = file_system_directory_.Append(directory_name); | 1241 base::FilePath path = file_system_directory_.Append(directory_name); |
| 1242 bool exists_in_fs = file_util::DirectoryExists(path); | 1242 bool exists_in_fs = file_util::DirectoryExists(path); |
| 1243 if (!exists_in_db && exists_in_fs) { | 1243 if (!exists_in_db && exists_in_fs) { |
| 1244 if (!file_util::Delete(path, true)) { | 1244 if (!file_util::Delete(path, true)) { |
| 1245 if (error_code) | 1245 if (error_code) |
| 1246 *error_code = base::PLATFORM_FILE_ERROR_FAILED; | 1246 *error_code = base::PLATFORM_FILE_ERROR_FAILED; |
| 1247 return FilePath(); | 1247 return base::FilePath(); |
| 1248 } | 1248 } |
| 1249 exists_in_fs = false; | 1249 exists_in_fs = false; |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 if (!exists_in_fs) { | 1252 if (!exists_in_fs) { |
| 1253 if (!create || !file_util::CreateDirectory(path)) { | 1253 if (!create || !file_util::CreateDirectory(path)) { |
| 1254 if (error_code) | 1254 if (error_code) |
| 1255 *error_code = create ? | 1255 *error_code = create ? |
| 1256 base::PLATFORM_FILE_ERROR_FAILED : | 1256 base::PLATFORM_FILE_ERROR_FAILED : |
| 1257 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1257 base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1258 return FilePath(); | 1258 return base::FilePath(); |
| 1259 } | 1259 } |
| 1260 } | 1260 } |
| 1261 | 1261 |
| 1262 if (error_code) | 1262 if (error_code) |
| 1263 *error_code = base::PLATFORM_FILE_OK; | 1263 *error_code = base::PLATFORM_FILE_OK; |
| 1264 | 1264 |
| 1265 return path; | 1265 return path; |
| 1266 } | 1266 } |
| 1267 | 1267 |
| 1268 void ObfuscatedFileUtil::InvalidateUsageCache( | 1268 void ObfuscatedFileUtil::InvalidateUsageCache( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 new FileSystemOriginDatabase(file_system_directory_)); | 1301 new FileSystemOriginDatabase(file_system_directory_)); |
| 1302 } | 1302 } |
| 1303 return true; | 1303 return true; |
| 1304 } | 1304 } |
| 1305 | 1305 |
| 1306 PlatformFileError ObfuscatedFileUtil::GenerateNewLocalPath( | 1306 PlatformFileError ObfuscatedFileUtil::GenerateNewLocalPath( |
| 1307 FileSystemDirectoryDatabase* db, | 1307 FileSystemDirectoryDatabase* db, |
| 1308 FileSystemOperationContext* context, | 1308 FileSystemOperationContext* context, |
| 1309 const GURL& origin, | 1309 const GURL& origin, |
| 1310 FileSystemType type, | 1310 FileSystemType type, |
| 1311 FilePath* local_path) { | 1311 base::FilePath* local_path) { |
| 1312 DCHECK(local_path); | 1312 DCHECK(local_path); |
| 1313 int64 number; | 1313 int64 number; |
| 1314 if (!db || !db->GetNextInteger(&number)) | 1314 if (!db || !db->GetNextInteger(&number)) |
| 1315 return base::PLATFORM_FILE_ERROR_FAILED; | 1315 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1316 | 1316 |
| 1317 PlatformFileError error = base::PLATFORM_FILE_OK; | 1317 PlatformFileError error = base::PLATFORM_FILE_OK; |
| 1318 FilePath new_local_path = GetDirectoryForOriginAndType(origin, type, false, | 1318 base::FilePath new_local_path = GetDirectoryForOriginAndType(origin, type, |
| 1319 &error); | 1319 false, &error); |
| 1320 if (error != base::PLATFORM_FILE_OK) | 1320 if (error != base::PLATFORM_FILE_OK) |
| 1321 return base::PLATFORM_FILE_ERROR_FAILED; | 1321 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1322 | 1322 |
| 1323 // We use the third- and fourth-to-last digits as the directory. | 1323 // We use the third- and fourth-to-last digits as the directory. |
| 1324 int64 directory_number = number % 10000 / 100; | 1324 int64 directory_number = number % 10000 / 100; |
| 1325 new_local_path = new_local_path.AppendASCII( | 1325 new_local_path = new_local_path.AppendASCII( |
| 1326 StringPrintf("%02" PRId64, directory_number)); | 1326 StringPrintf("%02" PRId64, directory_number)); |
| 1327 | 1327 |
| 1328 error = NativeFileUtil::CreateDirectory( | 1328 error = NativeFileUtil::CreateDirectory( |
| 1329 new_local_path, false /* exclusive */, false /* recursive */); | 1329 new_local_path, false /* exclusive */, false /* recursive */); |
| 1330 if (error != base::PLATFORM_FILE_OK) | 1330 if (error != base::PLATFORM_FILE_OK) |
| 1331 return error; | 1331 return error; |
| 1332 | 1332 |
| 1333 *local_path = new_local_path.AppendASCII(StringPrintf("%08" PRId64, number)); | 1333 *local_path = new_local_path.AppendASCII(StringPrintf("%08" PRId64, number)); |
| 1334 return base::PLATFORM_FILE_OK; | 1334 return base::PLATFORM_FILE_OK; |
| 1335 } | 1335 } |
| 1336 | 1336 |
| 1337 } // namespace fileapi | 1337 } // namespace fileapi |
| OLD | NEW |