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