| 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/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
| 11 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 12 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 13 #include "webkit/fileapi/file_system_context.h" | 12 #include "webkit/fileapi/file_system_context.h" |
| 14 #include "webkit/fileapi/file_system_file_util_proxy.h" | 13 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 15 #include "webkit/fileapi/file_system_mount_point_provider.h" | 14 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 16 #include "webkit/fileapi/file_system_operation_context.h" | 15 #include "webkit/fileapi/file_system_operation_context.h" |
| 17 #include "webkit/fileapi/file_system_quota_util.h" | 16 #include "webkit/fileapi/file_system_quota_util.h" |
| 18 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/file_system_util.h" | 18 #include "webkit/fileapi/file_system_util.h" |
| 20 #include "webkit/fileapi/file_writer_delegate.h" | 19 #include "webkit/fileapi/file_writer_delegate.h" |
| 21 #include "webkit/fileapi/local_file_util.h" | 20 #include "webkit/fileapi/local_file_util.h" |
| 22 #include "webkit/fileapi/quota_file_util.h" | 21 #include "webkit/fileapi/quota_file_util.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 proxy_, | 64 proxy_, |
| 66 base::Bind(&FileSystemFileUtil::Close, | 65 base::Bind(&FileSystemFileUtil::Close, |
| 67 base::Unretained(c->src_file_util()), | 66 base::Unretained(c->src_file_util()), |
| 68 base::Owned(c)), | 67 base::Owned(c)), |
| 69 file_writer_delegate_->file(), | 68 file_writer_delegate_->file(), |
| 70 base::FileUtilProxy::StatusCallback()); | 69 base::FileUtilProxy::StatusCallback()); |
| 71 } | 70 } |
| 72 } | 71 } |
| 73 | 72 |
| 74 void FileSystemOperation::CreateFile(const GURL& path, | 73 void FileSystemOperation::CreateFile(const GURL& path, |
| 75 bool exclusive) { | 74 bool exclusive, |
| 75 const StatusCallback& callback) { |
| 76 #ifndef NDEBUG | 76 #ifndef NDEBUG |
| 77 DCHECK(kOperationNone == pending_operation_); | 77 DCHECK(kOperationNone == pending_operation_); |
| 78 pending_operation_ = kOperationCreateFile; | 78 pending_operation_ = kOperationCreateFile; |
| 79 #endif | 79 #endif |
| 80 if (!SetupSrcContextForWrite(path, true)) { | 80 base::PlatformFileError result = SetupSrcContextForWrite(path, true); |
| 81 if (result != base::PLATFORM_FILE_OK) { |
| 82 callback.Run(result); |
| 81 delete this; | 83 delete this; |
| 82 return; | 84 return; |
| 83 } | 85 } |
| 84 GetUsageAndQuotaThenCallback( | 86 GetUsageAndQuotaThenCallback( |
| 85 operation_context_.src_origin_url(), | 87 operation_context_.src_origin_url(), |
| 86 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, | 88 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, |
| 87 base::Unretained(this), exclusive)); | 89 base::Unretained(this), callback, exclusive)); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void FileSystemOperation::DelayedCreateFileForQuota( | 92 void FileSystemOperation::DelayedCreateFileForQuota( |
| 93 const StatusCallback& callback, |
| 91 bool exclusive, | 94 bool exclusive, |
| 92 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 95 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 93 operation_context_.set_allowed_bytes_growth(quota - usage); | 96 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 94 | 97 |
| 95 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 98 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 96 file_system_context(), | 99 file_system_context(), |
| 97 operation_context_.src_origin_url(), | 100 operation_context_.src_origin_url(), |
| 98 operation_context_.src_type())); | 101 operation_context_.src_type())); |
| 99 | 102 |
| 100 FileSystemFileUtilProxy::RelayEnsureFileExists( | 103 FileSystemFileUtilProxy::RelayEnsureFileExists( |
| 101 proxy_, | 104 proxy_, |
| 102 base::Bind(&FileSystemFileUtil::EnsureFileExists, | 105 base::Bind(&FileSystemFileUtil::EnsureFileExists, |
| 103 base::Unretained(operation_context_.src_file_util()), | 106 base::Unretained(operation_context_.src_file_util()), |
| 104 &operation_context_, src_virtual_path_), | 107 &operation_context_, src_virtual_path_), |
| 105 base::Bind( | 108 base::Bind( |
| 106 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive | 109 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive |
| 107 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, | 110 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, |
| 108 base::Owned(this))); | 111 base::Owned(this), callback)); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void FileSystemOperation::CreateDirectory(const GURL& path, | 114 void FileSystemOperation::CreateDirectory(const GURL& path, |
| 112 bool exclusive, | 115 bool exclusive, |
| 113 bool recursive) { | 116 bool recursive, |
| 117 const StatusCallback& callback) { |
| 114 #ifndef NDEBUG | 118 #ifndef NDEBUG |
| 115 DCHECK(kOperationNone == pending_operation_); | 119 DCHECK(kOperationNone == pending_operation_); |
| 116 pending_operation_ = kOperationCreateDirectory; | 120 pending_operation_ = kOperationCreateDirectory; |
| 117 #endif | 121 #endif |
| 118 if (!SetupSrcContextForWrite(path, true)) { | 122 base::PlatformFileError result = SetupSrcContextForWrite(path, true); |
| 123 if (result != base::PLATFORM_FILE_OK) { |
| 124 callback.Run(result); |
| 119 delete this; | 125 delete this; |
| 120 return; | 126 return; |
| 121 } | 127 } |
| 122 GetUsageAndQuotaThenCallback( | 128 GetUsageAndQuotaThenCallback( |
| 123 operation_context_.src_origin_url(), | 129 operation_context_.src_origin_url(), |
| 124 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, | 130 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, |
| 125 base::Unretained(this), exclusive, recursive)); | 131 base::Unretained(this), callback, exclusive, recursive)); |
| 126 } | 132 } |
| 127 | 133 |
| 128 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 134 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 135 const StatusCallback& callback, |
| 129 bool exclusive, bool recursive, | 136 bool exclusive, bool recursive, |
| 130 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 137 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 131 operation_context_.set_allowed_bytes_growth(quota - usage); | 138 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 132 | 139 |
| 133 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 140 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 134 file_system_context(), | 141 file_system_context(), |
| 135 operation_context_.src_origin_url(), | 142 operation_context_.src_origin_url(), |
| 136 operation_context_.src_type())); | 143 operation_context_.src_type())); |
| 137 | 144 |
| 138 base::FileUtilProxy::RelayFileTask( | 145 base::FileUtilProxy::RelayFileTask( |
| 139 proxy_, FROM_HERE, | 146 proxy_, FROM_HERE, |
| 140 base::Bind(&FileSystemFileUtil::CreateDirectory, | 147 base::Bind(&FileSystemFileUtil::CreateDirectory, |
| 141 base::Unretained(operation_context_.src_file_util()), | 148 base::Unretained(operation_context_.src_file_util()), |
| 142 &operation_context_, | 149 &operation_context_, |
| 143 src_virtual_path_, exclusive, recursive), | 150 src_virtual_path_, exclusive, recursive), |
| 144 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 151 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 145 base::Owned(this))); | 152 base::Owned(this), callback)); |
| 146 } | 153 } |
| 147 | 154 |
| 148 void FileSystemOperation::Copy(const GURL& src_path, | 155 void FileSystemOperation::Copy(const GURL& src_path, |
| 149 const GURL& dest_path) { | 156 const GURL& dest_path, |
| 157 const StatusCallback& callback) { |
| 150 #ifndef NDEBUG | 158 #ifndef NDEBUG |
| 151 DCHECK(kOperationNone == pending_operation_); | 159 DCHECK(kOperationNone == pending_operation_); |
| 152 pending_operation_ = kOperationCopy; | 160 pending_operation_ = kOperationCopy; |
| 153 #endif | 161 #endif |
| 154 if (!SetupSrcContextForRead(src_path) || | 162 base::PlatformFileError result = SetupSrcContextForRead(src_path); |
| 155 !SetupDestContextForWrite(dest_path, true)) { | 163 if (result == base::PLATFORM_FILE_OK) |
| 164 result = SetupDestContextForWrite(dest_path, true); |
| 165 if (result != base::PLATFORM_FILE_OK) { |
| 166 callback.Run(result); |
| 156 delete this; | 167 delete this; |
| 157 return; | 168 return; |
| 158 } | 169 } |
| 159 | 170 |
| 160 GetUsageAndQuotaThenCallback( | 171 GetUsageAndQuotaThenCallback( |
| 161 operation_context_.dest_origin_url(), | 172 operation_context_.dest_origin_url(), |
| 162 base::Bind(&FileSystemOperation::DelayedCopyForQuota, | 173 base::Bind(&FileSystemOperation::DelayedCopyForQuota, |
| 163 base::Unretained(this))); | 174 base::Unretained(this), callback)); |
| 164 } | 175 } |
| 165 | 176 |
| 166 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 177 void FileSystemOperation::DelayedCopyForQuota(const StatusCallback& callback, |
| 178 quota::QuotaStatusCode status, |
| 167 int64 usage, int64 quota) { | 179 int64 usage, int64 quota) { |
| 168 operation_context_.set_allowed_bytes_growth(quota - usage); | 180 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 169 | 181 |
| 170 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 182 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 171 file_system_context(), | 183 file_system_context(), |
| 172 operation_context_.dest_origin_url(), | 184 operation_context_.dest_origin_url(), |
| 173 operation_context_.dest_type())); | 185 operation_context_.dest_type())); |
| 174 | 186 |
| 175 base::FileUtilProxy::RelayFileTask( | 187 base::FileUtilProxy::RelayFileTask( |
| 176 proxy_, FROM_HERE, | 188 proxy_, FROM_HERE, |
| 177 base::Bind(&FileSystemFileUtil::Copy, | 189 base::Bind(&FileSystemFileUtil::Copy, |
| 178 base::Unretained(operation_context_.src_file_util()), | 190 base::Unretained(operation_context_.src_file_util()), |
| 179 &operation_context_, | 191 &operation_context_, |
| 180 src_virtual_path_, dest_virtual_path_), | 192 src_virtual_path_, dest_virtual_path_), |
| 181 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 193 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 182 base::Owned(this))); | 194 base::Owned(this), callback)); |
| 183 } | 195 } |
| 184 | 196 |
| 185 void FileSystemOperation::Move(const GURL& src_path, | 197 void FileSystemOperation::Move(const GURL& src_path, |
| 186 const GURL& dest_path) { | 198 const GURL& dest_path, |
| 199 const StatusCallback& callback) { |
| 187 #ifndef NDEBUG | 200 #ifndef NDEBUG |
| 188 DCHECK(kOperationNone == pending_operation_); | 201 DCHECK(kOperationNone == pending_operation_); |
| 189 pending_operation_ = kOperationMove; | 202 pending_operation_ = kOperationMove; |
| 190 #endif | 203 #endif |
| 191 if (!SetupSrcContextForWrite(src_path, false) || | 204 base::PlatformFileError result = SetupSrcContextForWrite(src_path, false); |
| 192 !SetupDestContextForWrite(dest_path, true)) { | 205 if (result == base::PLATFORM_FILE_OK) |
| 206 result = SetupDestContextForWrite(dest_path, true); |
| 207 if (result != base::PLATFORM_FILE_OK) { |
| 208 callback.Run(result); |
| 193 delete this; | 209 delete this; |
| 194 return; | 210 return; |
| 195 } | 211 } |
| 196 | 212 |
| 197 GetUsageAndQuotaThenCallback( | 213 GetUsageAndQuotaThenCallback( |
| 198 operation_context_.dest_origin_url(), | 214 operation_context_.dest_origin_url(), |
| 199 base::Bind(&FileSystemOperation::DelayedMoveForQuota, | 215 base::Bind(&FileSystemOperation::DelayedMoveForQuota, |
| 200 base::Unretained(this))); | 216 base::Unretained(this), callback)); |
| 201 } | 217 } |
| 202 | 218 |
| 203 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 219 void FileSystemOperation::DelayedMoveForQuota(const StatusCallback& callback, |
| 220 quota::QuotaStatusCode status, |
| 204 int64 usage, int64 quota) { | 221 int64 usage, int64 quota) { |
| 205 operation_context_.set_allowed_bytes_growth(quota - usage); | 222 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 206 | 223 |
| 207 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 224 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 208 file_system_context(), | 225 file_system_context(), |
| 209 operation_context_.dest_origin_url(), | 226 operation_context_.dest_origin_url(), |
| 210 operation_context_.dest_type())); | 227 operation_context_.dest_type())); |
| 211 | 228 |
| 212 base::FileUtilProxy::RelayFileTask( | 229 base::FileUtilProxy::RelayFileTask( |
| 213 proxy_, FROM_HERE, | 230 proxy_, FROM_HERE, |
| 214 base::Bind(&FileSystemFileUtil::Move, | 231 base::Bind(&FileSystemFileUtil::Move, |
| 215 base::Unretained(operation_context_.src_file_util()), | 232 base::Unretained(operation_context_.src_file_util()), |
| 216 &operation_context_, | 233 &operation_context_, |
| 217 src_virtual_path_, dest_virtual_path_), | 234 src_virtual_path_, dest_virtual_path_), |
| 218 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 235 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 219 base::Owned(this))); | 236 base::Owned(this), callback)); |
| 220 } | 237 } |
| 221 | 238 |
| 222 void FileSystemOperation::DirectoryExists(const GURL& path) { | 239 void FileSystemOperation::DirectoryExists(const GURL& path, |
| 240 const StatusCallback& callback) { |
| 223 #ifndef NDEBUG | 241 #ifndef NDEBUG |
| 224 DCHECK(kOperationNone == pending_operation_); | 242 DCHECK(kOperationNone == pending_operation_); |
| 225 pending_operation_ = kOperationDirectoryExists; | 243 pending_operation_ = kOperationDirectoryExists; |
| 226 #endif | 244 #endif |
| 227 if (!SetupSrcContextForRead(path)) { | 245 base::PlatformFileError result = SetupSrcContextForRead(path); |
| 246 if (result != base::PLATFORM_FILE_OK) { |
| 247 callback.Run(result); |
| 228 delete this; | 248 delete this; |
| 229 return; | 249 return; |
| 230 } | 250 } |
| 231 | 251 |
| 232 FileSystemFileUtilProxy::RelayGetFileInfo( | 252 FileSystemFileUtilProxy::RelayGetFileInfo( |
| 233 proxy_, | 253 proxy_, |
| 234 base::Bind(&FileSystemFileUtil::GetFileInfo, | 254 base::Bind(&FileSystemFileUtil::GetFileInfo, |
| 235 base::Unretained(operation_context_.src_file_util()), | 255 base::Unretained(operation_context_.src_file_util()), |
| 236 &operation_context_, src_virtual_path_), | 256 &operation_context_, src_virtual_path_), |
| 237 base::Bind(&FileSystemOperation::DidDirectoryExists, base::Owned(this))); | 257 base::Bind(&FileSystemOperation::DidDirectoryExists, |
| 258 base::Owned(this), callback)); |
| 238 } | 259 } |
| 239 | 260 |
| 240 void FileSystemOperation::FileExists(const GURL& path) { | 261 void FileSystemOperation::FileExists(const GURL& path, |
| 262 const StatusCallback& callback) { |
| 241 #ifndef NDEBUG | 263 #ifndef NDEBUG |
| 242 DCHECK(kOperationNone == pending_operation_); | 264 DCHECK(kOperationNone == pending_operation_); |
| 243 pending_operation_ = kOperationFileExists; | 265 pending_operation_ = kOperationFileExists; |
| 244 #endif | 266 #endif |
| 245 if (!SetupSrcContextForRead(path)) { | 267 base::PlatformFileError result = SetupSrcContextForRead(path); |
| 268 if (result != base::PLATFORM_FILE_OK) { |
| 269 callback.Run(result); |
| 246 delete this; | 270 delete this; |
| 247 return; | 271 return; |
| 248 } | 272 } |
| 249 | 273 |
| 250 FileSystemFileUtilProxy::RelayGetFileInfo( | 274 FileSystemFileUtilProxy::RelayGetFileInfo( |
| 251 proxy_, | 275 proxy_, |
| 252 base::Bind(&FileSystemFileUtil::GetFileInfo, | 276 base::Bind(&FileSystemFileUtil::GetFileInfo, |
| 253 base::Unretained(operation_context_.src_file_util()), | 277 base::Unretained(operation_context_.src_file_util()), |
| 254 &operation_context_, src_virtual_path_), | 278 &operation_context_, src_virtual_path_), |
| 255 base::Bind(&FileSystemOperation::DidFileExists, base::Owned(this))); | 279 base::Bind(&FileSystemOperation::DidFileExists, |
| 280 base::Owned(this), callback)); |
| 256 } | 281 } |
| 257 | 282 |
| 258 void FileSystemOperation::GetMetadata(const GURL& path) { | 283 void FileSystemOperation::GetMetadata(const GURL& path, |
| 284 const GetMetadataCallback& callback) { |
| 259 #ifndef NDEBUG | 285 #ifndef NDEBUG |
| 260 DCHECK(kOperationNone == pending_operation_); | 286 DCHECK(kOperationNone == pending_operation_); |
| 261 pending_operation_ = kOperationGetMetadata; | 287 pending_operation_ = kOperationGetMetadata; |
| 262 #endif | 288 #endif |
| 263 if (!SetupSrcContextForRead(path)) { | 289 base::PlatformFileError result = SetupSrcContextForRead(path); |
| 290 if (result != base::PLATFORM_FILE_OK) { |
| 291 callback.Run(result, base::PlatformFileInfo(), FilePath()); |
| 264 delete this; | 292 delete this; |
| 265 return; | 293 return; |
| 266 } | 294 } |
| 267 | 295 |
| 268 FileSystemFileUtilProxy::RelayGetFileInfo( | 296 FileSystemFileUtilProxy::RelayGetFileInfo( |
| 269 proxy_, | 297 proxy_, |
| 270 base::Bind(&FileSystemFileUtil::GetFileInfo, | 298 base::Bind(&FileSystemFileUtil::GetFileInfo, |
| 271 base::Unretained(operation_context_.src_file_util()), | 299 base::Unretained(operation_context_.src_file_util()), |
| 272 &operation_context_, src_virtual_path_), | 300 &operation_context_, src_virtual_path_), |
| 273 base::Bind(&FileSystemOperation::DidGetMetadata, base::Owned(this))); | 301 base::Bind(&FileSystemOperation::DidGetMetadata, |
| 302 base::Owned(this), callback)); |
| 274 } | 303 } |
| 275 | 304 |
| 276 void FileSystemOperation::ReadDirectory(const GURL& path) { | 305 void FileSystemOperation::ReadDirectory(const GURL& path, |
| 306 const ReadDirectoryCallback& callback) { |
| 277 #ifndef NDEBUG | 307 #ifndef NDEBUG |
| 278 DCHECK(kOperationNone == pending_operation_); | 308 DCHECK(kOperationNone == pending_operation_); |
| 279 pending_operation_ = kOperationReadDirectory; | 309 pending_operation_ = kOperationReadDirectory; |
| 280 #endif | 310 #endif |
| 281 if (!SetupSrcContextForRead(path)) { | 311 base::PlatformFileError result = SetupSrcContextForRead(path); |
| 312 if (result != base::PLATFORM_FILE_OK) { |
| 313 callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false); |
| 282 delete this; | 314 delete this; |
| 283 return; | 315 return; |
| 284 } | 316 } |
| 285 | 317 |
| 286 FileSystemFileUtilProxy::RelayReadDirectory( | 318 FileSystemFileUtilProxy::RelayReadDirectory( |
| 287 proxy_, | 319 proxy_, |
| 288 base::Bind(&FileSystemFileUtil::ReadDirectory, | 320 base::Bind(&FileSystemFileUtil::ReadDirectory, |
| 289 base::Unretained(operation_context_.src_file_util()), | 321 base::Unretained(operation_context_.src_file_util()), |
| 290 &operation_context_, src_virtual_path_), | 322 &operation_context_, src_virtual_path_), |
| 291 base::Bind(&FileSystemOperation::DidReadDirectory, base::Owned(this))); | 323 base::Bind(&FileSystemOperation::DidReadDirectory, |
| 324 base::Owned(this), callback)); |
| 292 } | 325 } |
| 293 | 326 |
| 294 void FileSystemOperation::Remove(const GURL& path, bool recursive) { | 327 void FileSystemOperation::Remove(const GURL& path, bool recursive, |
| 328 const StatusCallback& callback) { |
| 295 #ifndef NDEBUG | 329 #ifndef NDEBUG |
| 296 DCHECK(kOperationNone == pending_operation_); | 330 DCHECK(kOperationNone == pending_operation_); |
| 297 pending_operation_ = kOperationRemove; | 331 pending_operation_ = kOperationRemove; |
| 298 #endif | 332 #endif |
| 299 if (!SetupSrcContextForWrite(path, false)) { | 333 base::PlatformFileError result = SetupSrcContextForWrite(path, false); |
| 334 if (result != base::PLATFORM_FILE_OK) { |
| 335 callback.Run(result); |
| 300 delete this; | 336 delete this; |
| 301 return; | 337 return; |
| 302 } | 338 } |
| 303 | 339 |
| 304 base::FileUtilProxy::RelayFileTask( | 340 base::FileUtilProxy::RelayFileTask( |
| 305 proxy_, FROM_HERE, | 341 proxy_, FROM_HERE, |
| 306 base::Bind(&FileSystemFileUtil::Delete, | 342 base::Bind(&FileSystemFileUtil::Delete, |
| 307 base::Unretained(operation_context_.src_file_util()), | 343 base::Unretained(operation_context_.src_file_util()), |
| 308 &operation_context_, src_virtual_path_, recursive), | 344 &operation_context_, src_virtual_path_, recursive), |
| 309 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 345 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 310 base::Owned(this))); | 346 base::Owned(this), callback)); |
| 311 } | 347 } |
| 312 | 348 |
| 313 void FileSystemOperation::Write( | 349 void FileSystemOperation::Write( |
| 314 const net::URLRequestContext* url_request_context, | 350 const net::URLRequestContext* url_request_context, |
| 315 const GURL& path, | 351 const GURL& path, |
| 316 const GURL& blob_url, | 352 const GURL& blob_url, |
| 317 int64 offset) { | 353 int64 offset, |
| 354 const WriteCallback& callback) { |
| 318 #ifndef NDEBUG | 355 #ifndef NDEBUG |
| 319 DCHECK(kOperationNone == pending_operation_); | 356 DCHECK(kOperationNone == pending_operation_); |
| 320 pending_operation_ = kOperationWrite; | 357 pending_operation_ = kOperationWrite; |
| 321 #endif | 358 #endif |
| 322 if (!SetupSrcContextForWrite(path, true)) { | 359 base::PlatformFileError result = SetupSrcContextForWrite(path, true); |
| 360 if (result != base::PLATFORM_FILE_OK) { |
| 361 callback.Run(result, 0, false); |
| 323 delete this; | 362 delete this; |
| 324 return; | 363 return; |
| 325 } | 364 } |
| 326 DCHECK(blob_url.is_valid()); | 365 DCHECK(blob_url.is_valid()); |
| 327 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 366 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
| 367 set_write_callback(callback); |
| 328 blob_request_.reset( | 368 blob_request_.reset( |
| 329 new net::URLRequest(blob_url, file_writer_delegate_.get())); | 369 new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| 330 blob_request_->set_context(url_request_context); | 370 blob_request_->set_context(url_request_context); |
| 331 | 371 |
| 332 GetUsageAndQuotaThenCallback( | 372 GetUsageAndQuotaThenCallback( |
| 333 operation_context_.src_origin_url(), | 373 operation_context_.src_origin_url(), |
| 334 base::Bind(&FileSystemOperation::DelayedWriteForQuota, | 374 base::Bind(&FileSystemOperation::DelayedWriteForQuota, |
| 335 base::Unretained(this))); | 375 base::Unretained(this))); |
| 336 } | 376 } |
| 337 | 377 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 353 base::Bind(&FileSystemFileUtil::CreateOrOpen, | 393 base::Bind(&FileSystemFileUtil::CreateOrOpen, |
| 354 base::Unretained(operation_context_.src_file_util()), | 394 base::Unretained(operation_context_.src_file_util()), |
| 355 &operation_context_, src_virtual_path_, file_flags), | 395 &operation_context_, src_virtual_path_, file_flags), |
| 356 base::Bind(&FileSystemFileUtil::Close, | 396 base::Bind(&FileSystemFileUtil::Close, |
| 357 base::Unretained(operation_context_.src_file_util()), | 397 base::Unretained(operation_context_.src_file_util()), |
| 358 &operation_context_), | 398 &operation_context_), |
| 359 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, | 399 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, |
| 360 base::Unretained(this))); | 400 base::Unretained(this))); |
| 361 } | 401 } |
| 362 | 402 |
| 363 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 403 void FileSystemOperation::Truncate(const GURL& path, int64 length, |
| 404 const StatusCallback& callback) { |
| 364 #ifndef NDEBUG | 405 #ifndef NDEBUG |
| 365 DCHECK(kOperationNone == pending_operation_); | 406 DCHECK(kOperationNone == pending_operation_); |
| 366 pending_operation_ = kOperationTruncate; | 407 pending_operation_ = kOperationTruncate; |
| 367 #endif | 408 #endif |
| 368 if (!SetupSrcContextForWrite(path, false)) { | 409 base::PlatformFileError result = SetupSrcContextForWrite(path, false); |
| 410 if (result != base::PLATFORM_FILE_OK) { |
| 411 callback.Run(result); |
| 369 delete this; | 412 delete this; |
| 370 return; | 413 return; |
| 371 } | 414 } |
| 372 GetUsageAndQuotaThenCallback( | 415 GetUsageAndQuotaThenCallback( |
| 373 operation_context_.src_origin_url(), | 416 operation_context_.src_origin_url(), |
| 374 base::Bind(&FileSystemOperation::DelayedTruncateForQuota, | 417 base::Bind(&FileSystemOperation::DelayedTruncateForQuota, |
| 375 base::Unretained(this), length)); | 418 base::Unretained(this), callback, length)); |
| 376 } | 419 } |
| 377 | 420 |
| 378 void FileSystemOperation::DelayedTruncateForQuota(int64 length, | 421 void FileSystemOperation::DelayedTruncateForQuota( |
| 379 quota::QuotaStatusCode status, | 422 const StatusCallback& callback, |
| 380 int64 usage, int64 quota) { | 423 int64 length, quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 381 operation_context_.set_allowed_bytes_growth(quota - usage); | 424 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 382 | 425 |
| 383 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 426 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 384 file_system_context(), | 427 file_system_context(), |
| 385 operation_context_.src_origin_url(), | 428 operation_context_.src_origin_url(), |
| 386 operation_context_.src_type())); | 429 operation_context_.src_type())); |
| 387 | 430 |
| 388 base::FileUtilProxy::RelayFileTask( | 431 base::FileUtilProxy::RelayFileTask( |
| 389 proxy_, FROM_HERE, | 432 proxy_, FROM_HERE, |
| 390 base::Bind(&FileSystemFileUtil::Truncate, | 433 base::Bind(&FileSystemFileUtil::Truncate, |
| 391 base::Unretained(operation_context_.src_file_util()), | 434 base::Unretained(operation_context_.src_file_util()), |
| 392 &operation_context_, src_virtual_path_, length), | 435 &operation_context_, src_virtual_path_, length), |
| 393 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 436 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 394 base::Owned(this))); | 437 base::Owned(this), callback)); |
| 395 } | 438 } |
| 396 | 439 |
| 397 void FileSystemOperation::TouchFile(const GURL& path, | 440 void FileSystemOperation::TouchFile(const GURL& path, |
| 398 const base::Time& last_access_time, | 441 const base::Time& last_access_time, |
| 399 const base::Time& last_modified_time) { | 442 const base::Time& last_modified_time, |
| 443 const StatusCallback& callback) { |
| 400 #ifndef NDEBUG | 444 #ifndef NDEBUG |
| 401 DCHECK(kOperationNone == pending_operation_); | 445 DCHECK(kOperationNone == pending_operation_); |
| 402 pending_operation_ = kOperationTouchFile; | 446 pending_operation_ = kOperationTouchFile; |
| 403 #endif | 447 #endif |
| 404 if (!SetupSrcContextForWrite(path, true)) { | 448 base::PlatformFileError result = SetupSrcContextForWrite(path, true); |
| 449 if (result != base::PLATFORM_FILE_OK) { |
| 450 callback.Run(result); |
| 405 delete this; | 451 delete this; |
| 406 return; | 452 return; |
| 407 } | 453 } |
| 408 | 454 |
| 409 base::FileUtilProxy::RelayFileTask( | 455 base::FileUtilProxy::RelayFileTask( |
| 410 proxy_, FROM_HERE, | 456 proxy_, FROM_HERE, |
| 411 base::Bind(&FileSystemFileUtil::Touch, | 457 base::Bind(&FileSystemFileUtil::Touch, |
| 412 base::Unretained(operation_context_.src_file_util()), | 458 base::Unretained(operation_context_.src_file_util()), |
| 413 &operation_context_, | 459 &operation_context_, |
| 414 src_virtual_path_, last_access_time, last_modified_time), | 460 src_virtual_path_, last_access_time, last_modified_time), |
| 415 base::Bind(&FileSystemOperation::DidTouchFile, base::Owned(this))); | 461 base::Bind(&FileSystemOperation::DidTouchFile, |
| 462 base::Owned(this), callback)); |
| 416 } | 463 } |
| 417 | 464 |
| 418 void FileSystemOperation::OpenFile(const GURL& path, | 465 void FileSystemOperation::OpenFile(const GURL& path, |
| 419 int file_flags, | 466 int file_flags, |
| 420 base::ProcessHandle peer_handle) { | 467 base::ProcessHandle peer_handle, |
| 468 const OpenFileCallback& callback) { |
| 421 #ifndef NDEBUG | 469 #ifndef NDEBUG |
| 422 DCHECK(kOperationNone == pending_operation_); | 470 DCHECK(kOperationNone == pending_operation_); |
| 423 pending_operation_ = kOperationOpenFile; | 471 pending_operation_ = kOperationOpenFile; |
| 424 #endif | 472 #endif |
| 425 peer_handle_ = peer_handle; | 473 peer_handle_ = peer_handle; |
| 426 | 474 |
| 427 if (file_flags & ( | 475 if (file_flags & ( |
| 428 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 476 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 429 base::PLATFORM_FILE_HIDDEN))) { | 477 base::PLATFORM_FILE_HIDDEN))) { |
| 478 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, |
| 479 base::PlatformFile(), base::ProcessHandle()); |
| 430 delete this; | 480 delete this; |
| 431 return; | 481 return; |
| 432 } | 482 } |
| 433 if (file_flags & | 483 if (file_flags & |
| 434 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 484 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 435 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 485 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 436 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 486 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 437 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 487 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 438 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 488 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 439 if (!SetupSrcContextForWrite(path, true)) { | 489 base::PlatformFileError result = SetupSrcContextForWrite(path, true); |
| 490 if (result != base::PLATFORM_FILE_OK) { |
| 491 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); |
| 440 delete this; | 492 delete this; |
| 441 return; | 493 return; |
| 442 } | 494 } |
| 443 } else { | 495 } else { |
| 444 if (!SetupSrcContextForRead(path)) { | 496 base::PlatformFileError result = SetupSrcContextForRead(path); |
| 497 if (result != base::PLATFORM_FILE_OK) { |
| 498 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); |
| 445 delete this; | 499 delete this; |
| 446 return; | 500 return; |
| 447 } | 501 } |
| 448 } | 502 } |
| 449 GetUsageAndQuotaThenCallback( | 503 GetUsageAndQuotaThenCallback( |
| 450 operation_context_.src_origin_url(), | 504 operation_context_.src_origin_url(), |
| 451 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, | 505 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, |
| 452 base::Unretained(this), file_flags)); | 506 base::Unretained(this), callback, file_flags)); |
| 453 } | 507 } |
| 454 | 508 |
| 455 void FileSystemOperation::DelayedOpenFileForQuota(int file_flags, | 509 void FileSystemOperation::DelayedOpenFileForQuota( |
| 456 quota::QuotaStatusCode status, | 510 const OpenFileCallback& callback, |
| 457 int64 usage, int64 quota) { | 511 int file_flags, quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 458 operation_context_.set_allowed_bytes_growth(quota - usage); | 512 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 459 | 513 |
| 460 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 514 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 461 file_system_context(), | 515 file_system_context(), |
| 462 operation_context_.src_origin_url(), | 516 operation_context_.src_origin_url(), |
| 463 operation_context_.src_type())); | 517 operation_context_.src_type())); |
| 464 | 518 |
| 465 base::FileUtilProxy::RelayCreateOrOpen( | 519 base::FileUtilProxy::RelayCreateOrOpen( |
| 466 proxy_, | 520 proxy_, |
| 467 base::Bind(&FileSystemFileUtil::CreateOrOpen, | 521 base::Bind(&FileSystemFileUtil::CreateOrOpen, |
| 468 base::Unretained(operation_context_.src_file_util()), | 522 base::Unretained(operation_context_.src_file_util()), |
| 469 &operation_context_, | 523 &operation_context_, |
| 470 src_virtual_path_, file_flags), | 524 src_virtual_path_, file_flags), |
| 471 base::Bind(&FileSystemFileUtil::Close, | 525 base::Bind(&FileSystemFileUtil::Close, |
| 472 base::Unretained(operation_context_.src_file_util()), | 526 base::Unretained(operation_context_.src_file_util()), |
| 473 &operation_context_), | 527 &operation_context_), |
| 474 base::Bind(&FileSystemOperation::DidOpenFile, base::Owned(this))); | 528 base::Bind(&FileSystemOperation::DidOpenFile, |
| 529 base::Owned(this), callback)); |
| 475 } | 530 } |
| 476 | 531 |
| 477 // We can only get here on a write or truncate that's not yet completed. | 532 // We can only get here on a write or truncate that's not yet completed. |
| 478 // We don't support cancelling any other operation at this time. | 533 // We don't support cancelling any other operation at this time. |
| 479 void FileSystemOperation::Cancel( | 534 void FileSystemOperation::Cancel(const StatusCallback& cancel_callback) { |
| 480 scoped_ptr<FileSystemCallbackDispatcher> cancel_dispatcher) { | |
| 481 if (file_writer_delegate_.get()) { | 535 if (file_writer_delegate_.get()) { |
| 482 #ifndef NDEBUG | 536 #ifndef NDEBUG |
| 483 DCHECK(kOperationWrite == pending_operation_); | 537 DCHECK(kOperationWrite == pending_operation_); |
| 484 #endif | 538 #endif |
| 485 // Writes are done without proxying through FileUtilProxy after the initial | 539 // Writes are done without proxying through FileUtilProxy after the initial |
| 486 // opening of the PlatformFile. All state changes are done on this thread, | 540 // opening of the PlatformFile. All state changes are done on this thread, |
| 487 // so we're guaranteed to be able to shut down atomically. We do need to | 541 // so we're guaranteed to be able to shut down atomically. We do need to |
| 488 // check that the file has been opened [which means the blob_request_ has | 542 // check that the file has been opened [which means the blob_request_ has |
| 489 // been created], so we know how much we need to do. | 543 // been created], so we know how much we need to do. |
| 490 if (blob_request_.get()) | 544 if (blob_request_.get()) |
| 491 // This halts any calls to file_writer_delegate_ from blob_request_. | 545 // This halts any calls to file_writer_delegate_ from blob_request_. |
| 492 blob_request_->Cancel(); | 546 blob_request_->Cancel(); |
| 493 | 547 |
| 494 if (dispatcher_.get()) | 548 if (!write_callback_.is_null()) { |
| 495 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 549 // Notify the failure status to the ongoing operation's callback. |
| 496 cancel_dispatcher->DidSucceed(); | 550 write_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT, 0, false); |
| 497 dispatcher_.reset(); | 551 // Do not delete this FileSystemOperation object yet. As a result of |
| 552 // abort, this->DidWrite is called later and there we delete this object. |
| 553 } |
| 554 cancel_callback.Run(base::PLATFORM_FILE_OK); |
| 555 write_callback_.Reset(); |
| 498 } else { | 556 } else { |
| 499 #ifndef NDEBUG | 557 #ifndef NDEBUG |
| 500 DCHECK(kOperationTruncate == pending_operation_); | 558 DCHECK(kOperationTruncate == pending_operation_); |
| 501 #endif | 559 #endif |
| 502 // We're cancelling a truncate operation, but we can't actually stop it | 560 // We're cancelling a truncate operation, but we can't actually stop it |
| 503 // since it's been proxied to another thread. We need to save the | 561 // since it's been proxied to another thread. We need to save the |
| 504 // cancel_dispatcher so that when the truncate returns, it can see that it's | 562 // cancel_callback so that when the truncate returns, it can see that it's |
| 505 // been cancelled, report it, and report that the cancel has succeeded. | 563 // been cancelled, report it, and report that the cancel has succeeded. |
| 506 DCHECK(!cancel_dispatcher_.get()); | 564 DCHECK(cancel_callback_.is_null()); |
| 507 cancel_dispatcher_ = cancel_dispatcher.Pass(); | 565 cancel_callback_ = cancel_callback; |
| 508 } | 566 } |
| 509 } | 567 } |
| 510 | 568 |
| 511 FileSystemOperation* FileSystemOperation::AsFileSystemOperation() { | 569 FileSystemOperation* FileSystemOperation::AsFileSystemOperation() { |
| 512 return this; | 570 return this; |
| 513 } | 571 } |
| 514 | 572 |
| 515 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, | 573 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, |
| 516 FilePath* platform_path) { | 574 FilePath* platform_path) { |
| 517 #ifndef NDEBUG | 575 #ifndef NDEBUG |
| 518 DCHECK(kOperationNone == pending_operation_); | 576 DCHECK(kOperationNone == pending_operation_); |
| 519 pending_operation_ = kOperationGetLocalPath; | 577 pending_operation_ = kOperationGetLocalPath; |
| 520 #endif | 578 #endif |
| 521 if (!SetupSrcContextForRead(path)) { | 579 base::PlatformFileError result = SetupSrcContextForRead(path); |
| 580 if (result != base::PLATFORM_FILE_OK) { |
| 522 delete this; | 581 delete this; |
| 523 return; | 582 return; |
| 524 } | 583 } |
| 525 | 584 |
| 526 operation_context_.src_file_util()->GetLocalFilePath( | 585 operation_context_.src_file_util()->GetLocalFilePath( |
| 527 &operation_context_, src_virtual_path_, platform_path); | 586 &operation_context_, src_virtual_path_, platform_path); |
| 528 | 587 |
| 529 delete this; | 588 delete this; |
| 530 } | 589 } |
| 531 | 590 |
| 532 FileSystemOperation::FileSystemOperation( | 591 FileSystemOperation::FileSystemOperation( |
| 533 scoped_ptr<FileSystemCallbackDispatcher> dispatcher, | |
| 534 scoped_refptr<base::MessageLoopProxy> proxy, | 592 scoped_refptr<base::MessageLoopProxy> proxy, |
| 535 FileSystemContext* file_system_context) | 593 FileSystemContext* file_system_context) |
| 536 : proxy_(proxy), | 594 : proxy_(proxy), |
| 537 dispatcher_(dispatcher.Pass()), | |
| 538 operation_context_(file_system_context, NULL), | 595 operation_context_(file_system_context, NULL), |
| 539 peer_handle_(base::kNullProcessHandle) { | 596 peer_handle_(base::kNullProcessHandle) { |
| 540 #ifndef NDEBUG | 597 #ifndef NDEBUG |
| 541 pending_operation_ = kOperationNone; | 598 pending_operation_ = kOperationNone; |
| 542 #endif | 599 #endif |
| 543 } | 600 } |
| 544 | 601 |
| 545 void FileSystemOperation::GetUsageAndQuotaThenCallback( | 602 void FileSystemOperation::GetUsageAndQuotaThenCallback( |
| 546 const GURL& origin_url, | 603 const GURL& origin_url, |
| 547 const quota::QuotaManager::GetUsageAndQuotaCallback& callback) { | 604 const quota::QuotaManager::GetUsageAndQuotaCallback& callback) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 558 DCHECK(quota_manager_proxy); | 615 DCHECK(quota_manager_proxy); |
| 559 DCHECK(quota_manager_proxy->quota_manager()); | 616 DCHECK(quota_manager_proxy->quota_manager()); |
| 560 quota_manager_proxy->quota_manager()->GetUsageAndQuota( | 617 quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
| 561 operation_context_.src_origin_url(), | 618 operation_context_.src_origin_url(), |
| 562 FileSystemTypeToQuotaStorageType( | 619 FileSystemTypeToQuotaStorageType( |
| 563 operation_context_.src_type()), | 620 operation_context_.src_type()), |
| 564 callback); | 621 callback); |
| 565 } | 622 } |
| 566 | 623 |
| 567 void FileSystemOperation::DidEnsureFileExistsExclusive( | 624 void FileSystemOperation::DidEnsureFileExistsExclusive( |
| 625 const StatusCallback& callback, |
| 568 base::PlatformFileError rv, bool created) { | 626 base::PlatformFileError rv, bool created) { |
| 569 if (rv == base::PLATFORM_FILE_OK && !created) { | 627 if (rv == base::PLATFORM_FILE_OK && !created) { |
| 570 if (dispatcher_.get()) | 628 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); |
| 571 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); | |
| 572 } else { | 629 } else { |
| 573 DidFinishFileOperation(rv); | 630 DidFinishFileOperation(callback, rv); |
| 574 } | 631 } |
| 575 } | 632 } |
| 576 | 633 |
| 577 void FileSystemOperation::DidEnsureFileExistsNonExclusive( | 634 void FileSystemOperation::DidEnsureFileExistsNonExclusive( |
| 635 const StatusCallback& callback, |
| 578 base::PlatformFileError rv, bool /* created */) { | 636 base::PlatformFileError rv, bool /* created */) { |
| 579 DidFinishFileOperation(rv); | 637 DidFinishFileOperation(callback, rv); |
| 580 } | 638 } |
| 581 | 639 |
| 582 void FileSystemOperation::DidFinishFileOperation( | 640 void FileSystemOperation::DidFinishFileOperation( |
| 641 const StatusCallback& callback, |
| 583 base::PlatformFileError rv) { | 642 base::PlatformFileError rv) { |
| 584 if (cancel_dispatcher_.get()) { | 643 if (!cancel_callback_.is_null()) { |
| 585 #ifndef NDEBUG | 644 #ifndef NDEBUG |
| 586 DCHECK(kOperationTruncate == pending_operation_); | 645 DCHECK(kOperationTruncate == pending_operation_); |
| 587 #endif | 646 #endif |
| 588 | 647 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); |
| 589 if (dispatcher_.get()) | 648 cancel_callback_.Run(base::PLATFORM_FILE_OK); |
| 590 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 649 cancel_callback_.Reset(); |
| 591 cancel_dispatcher_->DidSucceed(); | 650 } else { |
| 592 } else if (dispatcher_.get()) { | 651 callback.Run(rv); |
| 593 if (rv == base::PLATFORM_FILE_OK) | |
| 594 dispatcher_->DidSucceed(); | |
| 595 else | |
| 596 dispatcher_->DidFail(rv); | |
| 597 } | 652 } |
| 598 } | 653 } |
| 599 | 654 |
| 600 void FileSystemOperation::DidDirectoryExists( | 655 void FileSystemOperation::DidDirectoryExists( |
| 656 const StatusCallback& callback, |
| 601 base::PlatformFileError rv, | 657 base::PlatformFileError rv, |
| 602 const base::PlatformFileInfo& file_info, | 658 const base::PlatformFileInfo& file_info, |
| 603 const FilePath& unused) { | 659 const FilePath& unused) { |
| 604 if (!dispatcher_.get()) | 660 if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory) |
| 605 return; | 661 rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 606 if (rv == base::PLATFORM_FILE_OK) { | 662 callback.Run(rv); |
| 607 if (file_info.is_directory) | |
| 608 dispatcher_->DidSucceed(); | |
| 609 else | |
| 610 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY); | |
| 611 } else { | |
| 612 dispatcher_->DidFail(rv); | |
| 613 } | |
| 614 } | 663 } |
| 615 | 664 |
| 616 void FileSystemOperation::DidFileExists( | 665 void FileSystemOperation::DidFileExists( |
| 666 const StatusCallback& callback, |
| 617 base::PlatformFileError rv, | 667 base::PlatformFileError rv, |
| 618 const base::PlatformFileInfo& file_info, | 668 const base::PlatformFileInfo& file_info, |
| 619 const FilePath& unused) { | 669 const FilePath& unused) { |
| 620 if (!dispatcher_.get()) | 670 if (rv == base::PLATFORM_FILE_OK && file_info.is_directory) |
| 621 return; | 671 rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
| 622 if (rv == base::PLATFORM_FILE_OK) { | 672 callback.Run(rv); |
| 623 if (file_info.is_directory) | |
| 624 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); | |
| 625 else | |
| 626 dispatcher_->DidSucceed(); | |
| 627 } else { | |
| 628 dispatcher_->DidFail(rv); | |
| 629 } | |
| 630 } | 673 } |
| 631 | 674 |
| 632 void FileSystemOperation::DidGetMetadata( | 675 void FileSystemOperation::DidGetMetadata( |
| 676 const GetMetadataCallback& callback, |
| 633 base::PlatformFileError rv, | 677 base::PlatformFileError rv, |
| 634 const base::PlatformFileInfo& file_info, | 678 const base::PlatformFileInfo& file_info, |
| 635 const FilePath& platform_path) { | 679 const FilePath& platform_path) { |
| 636 if (!dispatcher_.get()) | 680 callback.Run(rv, file_info, platform_path); |
| 637 return; | |
| 638 if (rv == base::PLATFORM_FILE_OK) | |
| 639 dispatcher_->DidReadMetadata(file_info, platform_path); | |
| 640 else | |
| 641 dispatcher_->DidFail(rv); | |
| 642 } | 681 } |
| 643 | 682 |
| 644 void FileSystemOperation::DidReadDirectory( | 683 void FileSystemOperation::DidReadDirectory( |
| 684 const ReadDirectoryCallback& callback, |
| 645 base::PlatformFileError rv, | 685 base::PlatformFileError rv, |
| 646 const std::vector<base::FileUtilProxy::Entry>& entries) { | 686 const std::vector<base::FileUtilProxy::Entry>& entries) { |
| 647 if (!dispatcher_.get()) | 687 callback.Run(rv, entries, false /* has_more */); |
| 648 return; | |
| 649 | |
| 650 if (rv == base::PLATFORM_FILE_OK) | |
| 651 dispatcher_->DidReadDirectory(entries, false /* has_more */); | |
| 652 else | |
| 653 dispatcher_->DidFail(rv); | |
| 654 } | 688 } |
| 655 | 689 |
| 656 void FileSystemOperation::DidWrite( | 690 void FileSystemOperation::DidWrite( |
| 657 base::PlatformFileError rv, | 691 base::PlatformFileError rv, |
| 658 int64 bytes, | 692 int64 bytes, |
| 659 bool complete) { | 693 bool complete) { |
| 660 if (!dispatcher_.get()) { | 694 if (write_callback_.is_null()) { |
| 695 // If cancelled, callback is already invoked and set to null in Cancel(). |
| 696 // We must not call it twice. Just shut down this operation object. |
| 661 delete this; | 697 delete this; |
| 662 return; | 698 return; |
| 663 } | 699 } |
| 664 if (rv == base::PLATFORM_FILE_OK) | 700 write_callback_.Run(rv, bytes, complete); |
| 665 dispatcher_->DidWrite(bytes, complete); | |
| 666 else | |
| 667 dispatcher_->DidFail(rv); | |
| 668 if (complete || rv != base::PLATFORM_FILE_OK) | 701 if (complete || rv != base::PLATFORM_FILE_OK) |
| 669 delete this; | 702 delete this; |
| 670 } | 703 } |
| 671 | 704 |
| 672 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { | 705 void FileSystemOperation::DidTouchFile(const StatusCallback& callback, |
| 673 if (!dispatcher_.get()) | 706 base::PlatformFileError rv) { |
| 674 return; | 707 callback.Run(rv); |
| 675 if (rv == base::PLATFORM_FILE_OK) | |
| 676 dispatcher_->DidSucceed(); | |
| 677 else | |
| 678 dispatcher_->DidFail(rv); | |
| 679 } | 708 } |
| 680 | 709 |
| 681 void FileSystemOperation::DidOpenFile( | 710 void FileSystemOperation::DidOpenFile( |
| 711 const OpenFileCallback& callback, |
| 682 base::PlatformFileError rv, | 712 base::PlatformFileError rv, |
| 683 base::PassPlatformFile file, | 713 base::PassPlatformFile file, |
| 684 bool unused) { | 714 bool unused) { |
| 685 if (!dispatcher_.get()) | 715 if (rv == base::PLATFORM_FILE_OK) |
| 686 return; | |
| 687 if (rv == base::PLATFORM_FILE_OK) { | |
| 688 CHECK_NE(base::kNullProcessHandle, peer_handle_); | 716 CHECK_NE(base::kNullProcessHandle, peer_handle_); |
| 689 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); | 717 callback.Run(rv, file.ReleaseValue(), peer_handle_); |
| 690 } else { | |
| 691 dispatcher_->DidFail(rv); | |
| 692 } | |
| 693 } | 718 } |
| 694 | 719 |
| 695 void FileSystemOperation::OnFileOpenedForWrite( | 720 void FileSystemOperation::OnFileOpenedForWrite( |
| 696 base::PlatformFileError rv, | 721 base::PlatformFileError rv, |
| 697 base::PassPlatformFile file, | 722 base::PassPlatformFile file, |
| 698 bool created) { | 723 bool created) { |
| 699 if (base::PLATFORM_FILE_OK != rv || !dispatcher_.get()) { | 724 if (rv != base::PLATFORM_FILE_OK) { |
| 700 if (dispatcher_.get()) | 725 if (!write_callback_.is_null()) |
| 701 dispatcher_->DidFail(rv); | 726 write_callback_.Run(rv, 0, false); |
| 702 delete this; | 727 delete this; |
| 703 return; | 728 return; |
| 704 } | 729 } |
| 705 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); | 730 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); |
| 706 } | 731 } |
| 707 | 732 |
| 708 bool FileSystemOperation::VerifyFileSystemPathForRead( | 733 base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForRead( |
| 709 const GURL& path, GURL* origin_url, FileSystemType* type, | 734 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 710 FilePath* virtual_path, FileSystemFileUtil** file_util) { | 735 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 711 if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util)) | 736 base::PlatformFileError rv = |
| 712 return false; | 737 VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util); |
| 738 if (rv != base::PLATFORM_FILE_OK) |
| 739 return rv; |
| 713 | 740 |
| 714 // We notify this read access whether the read access succeeds or not. | 741 // We notify this read access whether the read access succeeds or not. |
| 715 // This must be ok since this is used to let the QM's eviction logic know | 742 // This must be ok since this is used to let the QM's eviction logic know |
| 716 // someone is interested in reading the origin data and therefore to indicate | 743 // someone is interested in reading the origin data and therefore to indicate |
| 717 // that evicting this origin may not be a good idea. | 744 // that evicting this origin may not be a good idea. |
| 718 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); | 745 FileSystemQuotaUtil* quota_util = file_system_context()->GetQuotaUtil(*type); |
| 719 if (quota_util) { | 746 if (quota_util) { |
| 720 quota_util->NotifyOriginWasAccessedOnIOThread( | 747 quota_util->NotifyOriginWasAccessedOnIOThread( |
| 721 file_system_context()->quota_manager_proxy(), | 748 file_system_context()->quota_manager_proxy(), |
| 722 *origin_url, | 749 *origin_url, |
| 723 *type); | 750 *type); |
| 724 } | 751 } |
| 725 | 752 |
| 726 return true; | 753 return base::PLATFORM_FILE_OK; |
| 727 } | 754 } |
| 728 | 755 |
| 729 bool FileSystemOperation::VerifyFileSystemPathForWrite( | 756 base::PlatformFileError FileSystemOperation::VerifyFileSystemPathForWrite( |
| 730 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, | 757 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, |
| 731 FilePath* virtual_path, FileSystemFileUtil** file_util) { | 758 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 732 if (!VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util)) | 759 base::PlatformFileError rv = |
| 733 return false; | 760 VerifyFileSystemPath(path, origin_url, type, virtual_path, file_util); |
| 761 if (rv != base::PLATFORM_FILE_OK) |
| 762 return rv; |
| 734 | 763 |
| 735 // Any write access is disallowed on the root path. | 764 // Any write access is disallowed on the root path. |
| 736 if (virtual_path->value().length() == 0 || | 765 if (virtual_path->value().length() == 0 || |
| 737 virtual_path->DirName().value() == virtual_path->value()) { | 766 virtual_path->DirName().value() == virtual_path->value()) { |
| 738 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 767 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 739 return false; | |
| 740 } | 768 } |
| 741 if (create && | 769 if (create && |
| 742 file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName( | 770 file_system_context()->GetMountPointProvider(*type)->IsRestrictedFileName( |
| 743 virtual_path->BaseName())) { | 771 virtual_path->BaseName())) { |
| 744 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 772 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 745 return false; | |
| 746 } | 773 } |
| 747 | 774 |
| 748 return true; | 775 return base::PLATFORM_FILE_OK; |
| 749 } | 776 } |
| 750 | 777 |
| 751 bool FileSystemOperation::VerifyFileSystemPath( | 778 base::PlatformFileError FileSystemOperation::VerifyFileSystemPath( |
| 752 const GURL& path, GURL* origin_url, FileSystemType* type, | 779 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 753 FilePath* virtual_path, FileSystemFileUtil** file_util) { | 780 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 754 DCHECK(file_system_context()); | 781 DCHECK(file_system_context()); |
| 755 | 782 |
| 756 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { | 783 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| 757 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); | 784 return base::PLATFORM_FILE_ERROR_INVALID_URL; |
| 758 return false; | |
| 759 } | 785 } |
| 760 if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed( | 786 if (!file_system_context()->GetMountPointProvider(*type)->IsAccessAllowed( |
| 761 *origin_url, *type, *virtual_path)) { | 787 *origin_url, *type, *virtual_path)) { |
| 762 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 788 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 763 return false; | |
| 764 } | 789 } |
| 765 DCHECK(file_util); | 790 DCHECK(file_util); |
| 766 *file_util = file_system_context()->GetFileUtil(*type); | 791 *file_util = file_system_context()->GetFileUtil(*type); |
| 767 DCHECK(*file_util); | 792 DCHECK(*file_util); |
| 768 | 793 |
| 769 return true; | 794 return base::PLATFORM_FILE_OK; |
| 770 } | 795 } |
| 771 | 796 |
| 772 bool FileSystemOperation::SetupSrcContextForRead(const GURL& path) { | 797 base::PlatformFileError FileSystemOperation::SetupSrcContextForRead( |
| 798 const GURL& path) { |
| 773 GURL origin_url; | 799 GURL origin_url; |
| 774 FileSystemType type; | 800 FileSystemType type; |
| 775 FileSystemFileUtil* file_util; | 801 FileSystemFileUtil* file_util; |
| 776 bool result = VerifyFileSystemPathForRead( | 802 base::PlatformFileError result = VerifyFileSystemPathForRead( |
| 777 path, &origin_url, &type, &src_virtual_path_, &file_util); | 803 path, &origin_url, &type, &src_virtual_path_, &file_util); |
| 778 operation_context_.set_src_origin_url(origin_url); | 804 operation_context_.set_src_origin_url(origin_url); |
| 779 operation_context_.set_src_type(type); | 805 operation_context_.set_src_type(type); |
| 780 if (!operation_context_.src_file_util()) | 806 if (!operation_context_.src_file_util()) |
| 781 operation_context_.set_src_file_util(file_util); | 807 operation_context_.set_src_file_util(file_util); |
| 782 return result; | 808 return result; |
| 783 } | 809 } |
| 784 | 810 |
| 785 bool FileSystemOperation::SetupSrcContextForWrite(const GURL& path, | 811 base::PlatformFileError FileSystemOperation::SetupSrcContextForWrite( |
| 786 bool create) { | 812 const GURL& path, |
| 813 bool create) { |
| 787 GURL origin_url; | 814 GURL origin_url; |
| 788 FileSystemType type; | 815 FileSystemType type; |
| 789 FileSystemFileUtil* file_util = NULL; | 816 FileSystemFileUtil* file_util = NULL; |
| 790 bool result = VerifyFileSystemPathForWrite( | 817 base::PlatformFileError result = VerifyFileSystemPathForWrite( |
| 791 path, create, &origin_url, &type, &src_virtual_path_, &file_util); | 818 path, create, &origin_url, &type, &src_virtual_path_, &file_util); |
| 792 operation_context_.set_src_origin_url(origin_url); | 819 operation_context_.set_src_origin_url(origin_url); |
| 793 operation_context_.set_src_type(type); | 820 operation_context_.set_src_type(type); |
| 794 if (!operation_context_.src_file_util()) | 821 if (!operation_context_.src_file_util()) |
| 795 operation_context_.set_src_file_util(file_util); | 822 operation_context_.set_src_file_util(file_util); |
| 796 return result; | 823 return result; |
| 797 } | 824 } |
| 798 | 825 |
| 799 bool FileSystemOperation::SetupDestContextForWrite(const GURL& path, | 826 base::PlatformFileError FileSystemOperation::SetupDestContextForWrite( |
| 800 bool create) { | 827 const GURL& path, |
| 828 bool create) { |
| 801 GURL origin_url; | 829 GURL origin_url; |
| 802 FileSystemType type; | 830 FileSystemType type; |
| 803 FileSystemFileUtil* file_util = NULL; | 831 FileSystemFileUtil* file_util = NULL; |
| 804 bool result = VerifyFileSystemPathForWrite( | 832 base::PlatformFileError result = VerifyFileSystemPathForWrite( |
| 805 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); | 833 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); |
| 806 operation_context_.set_dest_origin_url(origin_url); | 834 operation_context_.set_dest_origin_url(origin_url); |
| 807 operation_context_.set_dest_type(type); | 835 operation_context_.set_dest_type(type); |
| 808 if (!operation_context_.dest_file_util()) | 836 if (!operation_context_.dest_file_util()) |
| 809 operation_context_.set_dest_file_util(file_util); | 837 operation_context_.set_dest_file_util(file_util); |
| 810 return result; | 838 return result; |
| 811 } | 839 } |
| 812 | 840 |
| 813 } // namespace fileapi | 841 } // namespace fileapi |
| OLD | NEW |