| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/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" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); | 56 quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 FileSystemOperation::FileSystemOperation( | 60 FileSystemOperation::FileSystemOperation( |
| 61 FileSystemCallbackDispatcher* dispatcher, | 61 FileSystemCallbackDispatcher* dispatcher, |
| 62 scoped_refptr<base::MessageLoopProxy> proxy, | 62 scoped_refptr<base::MessageLoopProxy> proxy, |
| 63 FileSystemContext* file_system_context) | 63 FileSystemContext* file_system_context) |
| 64 : proxy_(proxy), | 64 : proxy_(proxy), |
| 65 dispatcher_(dispatcher), | 65 dispatcher_(dispatcher), |
| 66 operation_context_(file_system_context, NULL), | 66 operation_context_(file_system_context, NULL) { |
| 67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
| 68 #ifndef NDEBUG | 67 #ifndef NDEBUG |
| 69 pending_operation_ = kOperationNone; | 68 pending_operation_ = kOperationNone; |
| 70 #endif | 69 #endif |
| 71 } | 70 } |
| 72 | 71 |
| 73 FileSystemOperation::~FileSystemOperation() { | 72 FileSystemOperation::~FileSystemOperation() { |
| 74 if (file_writer_delegate_.get()) | 73 if (file_writer_delegate_.get()) { |
| 75 FileSystemFileUtilProxy::Close( | 74 FileSystemOperationContext* c = |
| 76 operation_context_, proxy_, file_writer_delegate_->file(), | 75 new FileSystemOperationContext(operation_context_); |
| 77 FileSystemFileUtilProxy::StatusCallback()); | 76 base::FileUtilProxy::RelayClose( |
| 77 proxy_, |
| 78 base::Bind(&FileSystemFileUtil::Close, |
| 79 base::Unretained(c->src_file_util()), |
| 80 base::Owned(c)), |
| 81 file_writer_delegate_->file(), |
| 82 base::FileUtilProxy::StatusCallback()); |
| 83 } |
| 78 } | 84 } |
| 79 | 85 |
| 80 void FileSystemOperation::OpenFileSystem( | 86 void FileSystemOperation::OpenFileSystem( |
| 81 const GURL& origin_url, fileapi::FileSystemType type, bool create) { | 87 const GURL& origin_url, fileapi::FileSystemType type, bool create) { |
| 82 #ifndef NDEBUG | 88 #ifndef NDEBUG |
| 83 DCHECK(dispatcher_.get()); | |
| 84 DCHECK(kOperationNone == pending_operation_); | 89 DCHECK(kOperationNone == pending_operation_); |
| 85 pending_operation_ = static_cast<FileSystemOperation::OperationType>( | 90 pending_operation_ = static_cast<FileSystemOperation::OperationType>( |
| 86 kOperationOpenFileSystem); | 91 kOperationOpenFileSystem); |
| 87 #endif | 92 #endif |
| 88 | 93 |
| 89 DCHECK(file_system_context()); | 94 DCHECK(file_system_context()); |
| 90 operation_context_.set_src_origin_url(origin_url); | 95 operation_context_.set_src_origin_url(origin_url); |
| 91 operation_context_.set_src_type(type); | 96 operation_context_.set_src_type(type); |
| 92 // TODO(ericu): We don't really need to make this call if !create. | 97 // TODO(ericu): We don't really need to make this call if !create. |
| 93 // Also, in the future we won't need it either way, as long as we do all | 98 // Also, in the future we won't need it either way, as long as we do all |
| 94 // permission+quota checks beforehand. We only need it now because we have to | 99 // permission+quota checks beforehand. We only need it now because we have to |
| 95 // create an unpredictable directory name. Without that, we could lazily | 100 // create an unpredictable directory name. Without that, we could lazily |
| 96 // create the root later on the first filesystem write operation, and just | 101 // create the root later on the first filesystem write operation, and just |
| 97 // return GetFileSystemRootURI() here. | 102 // return GetFileSystemRootURI() here. |
| 98 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( | 103 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( |
| 99 origin_url, type, create, | 104 origin_url, type, create, |
| 100 base::Bind(&FileSystemOperation::DidGetRootPath, | 105 base::Bind(&FileSystemOperation::DidGetRootPath, |
| 101 weak_factory_.GetWeakPtr())); | 106 base::Owned(this))); |
| 102 } | 107 } |
| 103 | 108 |
| 104 void FileSystemOperation::CreateFile(const GURL& path, | 109 void FileSystemOperation::CreateFile(const GURL& path, |
| 105 bool exclusive) { | 110 bool exclusive) { |
| 106 #ifndef NDEBUG | 111 #ifndef NDEBUG |
| 107 DCHECK(dispatcher_.get()); | |
| 108 DCHECK(kOperationNone == pending_operation_); | 112 DCHECK(kOperationNone == pending_operation_); |
| 109 pending_operation_ = kOperationCreateFile; | 113 pending_operation_ = kOperationCreateFile; |
| 110 #endif | 114 #endif |
| 111 if (!SetupSrcContextForWrite(path, true)) { | 115 if (!SetupSrcContextForWrite(path, true)) { |
| 112 delete this; | 116 delete this; |
| 113 return; | 117 return; |
| 114 } | 118 } |
| 115 exclusive_ = exclusive; | |
| 116 | |
| 117 GetUsageAndQuotaThenCallback( | 119 GetUsageAndQuotaThenCallback( |
| 118 operation_context_.src_origin_url(), | 120 operation_context_.src_origin_url(), |
| 119 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, | 121 base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, |
| 120 weak_factory_.GetWeakPtr())); | 122 base::Unretained(this), exclusive)); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void FileSystemOperation::DelayedCreateFileForQuota( | 125 void FileSystemOperation::DelayedCreateFileForQuota( |
| 126 bool exclusive, |
| 124 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 127 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 125 operation_context_.set_allowed_bytes_growth(quota - usage); | 128 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 126 | 129 |
| 127 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 130 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 128 file_system_context(), | 131 file_system_context(), |
| 129 operation_context_.src_origin_url(), | 132 operation_context_.src_origin_url(), |
| 130 operation_context_.src_type())); | 133 operation_context_.src_type())); |
| 131 | 134 |
| 132 FileSystemFileUtilProxy::EnsureFileExists( | 135 FileSystemFileUtilProxy::EnsureFileExists( |
| 133 operation_context_, | 136 operation_context_, |
| 134 proxy_, | 137 proxy_, |
| 135 src_virtual_path_, | 138 src_virtual_path_, |
| 136 base::Bind( | 139 base::Bind( |
| 137 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive | 140 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive |
| 138 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, | 141 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, |
| 139 weak_factory_.GetWeakPtr())); | 142 base::Owned(this))); |
| 140 } | 143 } |
| 141 | 144 |
| 142 void FileSystemOperation::CreateDirectory(const GURL& path, | 145 void FileSystemOperation::CreateDirectory(const GURL& path, |
| 143 bool exclusive, | 146 bool exclusive, |
| 144 bool recursive) { | 147 bool recursive) { |
| 145 #ifndef NDEBUG | 148 #ifndef NDEBUG |
| 146 DCHECK(dispatcher_.get()); | |
| 147 DCHECK(kOperationNone == pending_operation_); | 149 DCHECK(kOperationNone == pending_operation_); |
| 148 pending_operation_ = kOperationCreateDirectory; | 150 pending_operation_ = kOperationCreateDirectory; |
| 149 #endif | 151 #endif |
| 150 if (!SetupSrcContextForWrite(path, true)) { | 152 if (!SetupSrcContextForWrite(path, true)) { |
| 151 delete this; | 153 delete this; |
| 152 return; | 154 return; |
| 153 } | 155 } |
| 154 exclusive_ = exclusive; | |
| 155 recursive_ = recursive; | |
| 156 | |
| 157 GetUsageAndQuotaThenCallback( | 156 GetUsageAndQuotaThenCallback( |
| 158 operation_context_.src_origin_url(), | 157 operation_context_.src_origin_url(), |
| 159 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, | 158 base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, |
| 160 weak_factory_.GetWeakPtr())); | 159 base::Unretained(this), exclusive, recursive)); |
| 161 } | 160 } |
| 162 | 161 |
| 163 void FileSystemOperation::DelayedCreateDirectoryForQuota( | 162 void FileSystemOperation::DelayedCreateDirectoryForQuota( |
| 163 bool exclusive, bool recursive, |
| 164 quota::QuotaStatusCode status, int64 usage, int64 quota) { | 164 quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| 165 operation_context_.set_allowed_bytes_growth(quota - usage); | 165 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 166 | 166 |
| 167 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 167 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 168 file_system_context(), | 168 file_system_context(), |
| 169 operation_context_.src_origin_url(), | 169 operation_context_.src_origin_url(), |
| 170 operation_context_.src_type())); | 170 operation_context_.src_type())); |
| 171 | 171 |
| 172 FileSystemFileUtilProxy::CreateDirectory( | 172 base::FileUtilProxy::RelayFileTask( |
| 173 operation_context_, proxy_, src_virtual_path_, exclusive_, | 173 proxy_, FROM_HERE, |
| 174 recursive_, | 174 base::Bind(&FileSystemFileUtil::CreateDirectory, |
| 175 base::Unretained(operation_context_.src_file_util()), |
| 176 &operation_context_, |
| 177 src_virtual_path_, exclusive, recursive), |
| 175 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 178 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 176 weak_factory_.GetWeakPtr())); | 179 base::Owned(this))); |
| 177 } | 180 } |
| 178 | 181 |
| 179 void FileSystemOperation::Copy(const GURL& src_path, | 182 void FileSystemOperation::Copy(const GURL& src_path, |
| 180 const GURL& dest_path) { | 183 const GURL& dest_path) { |
| 181 #ifndef NDEBUG | 184 #ifndef NDEBUG |
| 182 DCHECK(dispatcher_.get()); | |
| 183 DCHECK(kOperationNone == pending_operation_); | 185 DCHECK(kOperationNone == pending_operation_); |
| 184 pending_operation_ = kOperationCopy; | 186 pending_operation_ = kOperationCopy; |
| 185 #endif | 187 #endif |
| 186 if (!SetupSrcContextForRead(src_path) || | 188 if (!SetupSrcContextForRead(src_path) || |
| 187 !SetupDestContextForWrite(dest_path, true)) { | 189 !SetupDestContextForWrite(dest_path, true)) { |
| 188 delete this; | 190 delete this; |
| 189 return; | 191 return; |
| 190 } | 192 } |
| 191 | 193 |
| 192 GetUsageAndQuotaThenCallback( | 194 GetUsageAndQuotaThenCallback( |
| 193 operation_context_.dest_origin_url(), | 195 operation_context_.dest_origin_url(), |
| 194 base::Bind(&FileSystemOperation::DelayedCopyForQuota, | 196 base::Bind(&FileSystemOperation::DelayedCopyForQuota, |
| 195 weak_factory_.GetWeakPtr())); | 197 base::Unretained(this))); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, | 200 void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, |
| 199 int64 usage, int64 quota) { | 201 int64 usage, int64 quota) { |
| 200 operation_context_.set_allowed_bytes_growth(quota - usage); | 202 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 201 | 203 |
| 202 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 204 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 203 file_system_context(), | 205 file_system_context(), |
| 204 operation_context_.dest_origin_url(), | 206 operation_context_.dest_origin_url(), |
| 205 operation_context_.dest_type())); | 207 operation_context_.dest_type())); |
| 206 | 208 |
| 207 FileSystemFileUtilProxy::Copy( | 209 base::FileUtilProxy::RelayFileTask( |
| 208 operation_context_, proxy_, src_virtual_path_, | 210 proxy_, FROM_HERE, |
| 209 dest_virtual_path_, | 211 base::Bind(&FileSystemFileUtil::Copy, |
| 212 base::Unretained(operation_context_.src_file_util()), |
| 213 &operation_context_, |
| 214 src_virtual_path_, dest_virtual_path_), |
| 210 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 215 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 211 weak_factory_.GetWeakPtr())); | 216 base::Owned(this))); |
| 212 } | 217 } |
| 213 | 218 |
| 214 void FileSystemOperation::Move(const GURL& src_path, | 219 void FileSystemOperation::Move(const GURL& src_path, |
| 215 const GURL& dest_path) { | 220 const GURL& dest_path) { |
| 216 #ifndef NDEBUG | 221 #ifndef NDEBUG |
| 217 DCHECK(dispatcher_.get()); | |
| 218 DCHECK(kOperationNone == pending_operation_); | 222 DCHECK(kOperationNone == pending_operation_); |
| 219 pending_operation_ = kOperationMove; | 223 pending_operation_ = kOperationMove; |
| 220 #endif | 224 #endif |
| 221 if (!SetupSrcContextForWrite(src_path, false) || | 225 if (!SetupSrcContextForWrite(src_path, false) || |
| 222 !SetupDestContextForWrite(dest_path, true)) { | 226 !SetupDestContextForWrite(dest_path, true)) { |
| 223 delete this; | 227 delete this; |
| 224 return; | 228 return; |
| 225 } | 229 } |
| 226 | 230 |
| 227 GetUsageAndQuotaThenCallback( | 231 GetUsageAndQuotaThenCallback( |
| 228 operation_context_.dest_origin_url(), | 232 operation_context_.dest_origin_url(), |
| 229 base::Bind(&FileSystemOperation::DelayedMoveForQuota, | 233 base::Bind(&FileSystemOperation::DelayedMoveForQuota, |
| 230 weak_factory_.GetWeakPtr())); | 234 base::Unretained(this))); |
| 231 } | 235 } |
| 232 | 236 |
| 233 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, | 237 void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, |
| 234 int64 usage, int64 quota) { | 238 int64 usage, int64 quota) { |
| 235 operation_context_.set_allowed_bytes_growth(quota - usage); | 239 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 236 | 240 |
| 237 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 241 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 238 file_system_context(), | 242 file_system_context(), |
| 239 operation_context_.dest_origin_url(), | 243 operation_context_.dest_origin_url(), |
| 240 operation_context_.dest_type())); | 244 operation_context_.dest_type())); |
| 241 | 245 |
| 242 FileSystemFileUtilProxy::Move( | 246 base::FileUtilProxy::RelayFileTask( |
| 243 operation_context_, proxy_, src_virtual_path_, | 247 proxy_, FROM_HERE, |
| 244 dest_virtual_path_, | 248 base::Bind(&FileSystemFileUtil::Move, |
| 249 base::Unretained(operation_context_.src_file_util()), |
| 250 &operation_context_, |
| 251 src_virtual_path_, dest_virtual_path_), |
| 245 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 252 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 246 weak_factory_.GetWeakPtr())); | 253 base::Owned(this))); |
| 247 } | 254 } |
| 248 | 255 |
| 249 void FileSystemOperation::DirectoryExists(const GURL& path) { | 256 void FileSystemOperation::DirectoryExists(const GURL& path) { |
| 250 #ifndef NDEBUG | 257 #ifndef NDEBUG |
| 251 DCHECK(dispatcher_.get()); | |
| 252 DCHECK(kOperationNone == pending_operation_); | 258 DCHECK(kOperationNone == pending_operation_); |
| 253 pending_operation_ = kOperationDirectoryExists; | 259 pending_operation_ = kOperationDirectoryExists; |
| 254 #endif | 260 #endif |
| 255 if (!SetupSrcContextForRead(path)) { | 261 if (!SetupSrcContextForRead(path)) { |
| 256 delete this; | 262 delete this; |
| 257 return; | 263 return; |
| 258 } | 264 } |
| 259 | 265 |
| 260 FileSystemFileUtilProxy::GetFileInfo( | 266 FileSystemFileUtilProxy::GetFileInfo( |
| 261 operation_context_, proxy_, src_virtual_path_, | 267 operation_context_, proxy_, src_virtual_path_, |
| 262 base::Bind(&FileSystemOperation::DidDirectoryExists, | 268 base::Bind(&FileSystemOperation::DidDirectoryExists, base::Owned(this))); |
| 263 weak_factory_.GetWeakPtr())); | |
| 264 } | 269 } |
| 265 | 270 |
| 266 void FileSystemOperation::FileExists(const GURL& path) { | 271 void FileSystemOperation::FileExists(const GURL& path) { |
| 267 #ifndef NDEBUG | 272 #ifndef NDEBUG |
| 268 DCHECK(dispatcher_.get()); | |
| 269 DCHECK(kOperationNone == pending_operation_); | 273 DCHECK(kOperationNone == pending_operation_); |
| 270 pending_operation_ = kOperationFileExists; | 274 pending_operation_ = kOperationFileExists; |
| 271 #endif | 275 #endif |
| 272 if (!SetupSrcContextForRead(path)) { | 276 if (!SetupSrcContextForRead(path)) { |
| 273 delete this; | 277 delete this; |
| 274 return; | 278 return; |
| 275 } | 279 } |
| 276 | 280 |
| 277 FileSystemFileUtilProxy::GetFileInfo( | 281 FileSystemFileUtilProxy::GetFileInfo( |
| 278 operation_context_, proxy_, src_virtual_path_, | 282 operation_context_, proxy_, src_virtual_path_, |
| 279 base::Bind(&FileSystemOperation::DidFileExists, | 283 base::Bind(&FileSystemOperation::DidFileExists, base::Owned(this))); |
| 280 weak_factory_.GetWeakPtr())); | |
| 281 } | 284 } |
| 282 | 285 |
| 283 void FileSystemOperation::GetMetadata(const GURL& path) { | 286 void FileSystemOperation::GetMetadata(const GURL& path) { |
| 284 #ifndef NDEBUG | 287 #ifndef NDEBUG |
| 285 DCHECK(dispatcher_.get()); | |
| 286 DCHECK(kOperationNone == pending_operation_); | 288 DCHECK(kOperationNone == pending_operation_); |
| 287 pending_operation_ = kOperationGetMetadata; | 289 pending_operation_ = kOperationGetMetadata; |
| 288 #endif | 290 #endif |
| 289 if (!SetupSrcContextForRead(path)) { | 291 if (!SetupSrcContextForRead(path)) { |
| 290 delete this; | 292 delete this; |
| 291 return; | 293 return; |
| 292 } | 294 } |
| 293 | 295 |
| 294 FileSystemFileUtilProxy::GetFileInfo( | 296 FileSystemFileUtilProxy::GetFileInfo( |
| 295 operation_context_, proxy_, src_virtual_path_, | 297 operation_context_, proxy_, src_virtual_path_, |
| 296 base::Bind(&FileSystemOperation::DidGetMetadata, | 298 base::Bind(&FileSystemOperation::DidGetMetadata, base::Owned(this))); |
| 297 weak_factory_.GetWeakPtr())); | |
| 298 } | 299 } |
| 299 | 300 |
| 300 void FileSystemOperation::ReadDirectory(const GURL& path) { | 301 void FileSystemOperation::ReadDirectory(const GURL& path) { |
| 301 #ifndef NDEBUG | 302 #ifndef NDEBUG |
| 302 DCHECK(dispatcher_.get()); | |
| 303 DCHECK(kOperationNone == pending_operation_); | 303 DCHECK(kOperationNone == pending_operation_); |
| 304 pending_operation_ = kOperationReadDirectory; | 304 pending_operation_ = kOperationReadDirectory; |
| 305 #endif | 305 #endif |
| 306 if (!SetupSrcContextForRead(path)) { | 306 if (!SetupSrcContextForRead(path)) { |
| 307 delete this; | 307 delete this; |
| 308 return; | 308 return; |
| 309 } | 309 } |
| 310 | 310 |
| 311 FileSystemFileUtilProxy::ReadDirectory( | 311 FileSystemFileUtilProxy::ReadDirectory( |
| 312 operation_context_, proxy_, src_virtual_path_, | 312 operation_context_, proxy_, src_virtual_path_, |
| 313 base::Bind(&FileSystemOperation::DidReadDirectory, | 313 base::Bind(&FileSystemOperation::DidReadDirectory, base::Owned(this))); |
| 314 weak_factory_.GetWeakPtr())); | |
| 315 } | 314 } |
| 316 | 315 |
| 317 void FileSystemOperation::Remove(const GURL& path, bool recursive) { | 316 void FileSystemOperation::Remove(const GURL& path, bool recursive) { |
| 318 #ifndef NDEBUG | 317 #ifndef NDEBUG |
| 319 DCHECK(dispatcher_.get()); | |
| 320 DCHECK(kOperationNone == pending_operation_); | 318 DCHECK(kOperationNone == pending_operation_); |
| 321 pending_operation_ = kOperationRemove; | 319 pending_operation_ = kOperationRemove; |
| 322 #endif | 320 #endif |
| 323 if (!SetupSrcContextForWrite(path, false)) { | 321 if (!SetupSrcContextForWrite(path, false)) { |
| 324 delete this; | 322 delete this; |
| 325 return; | 323 return; |
| 326 } | 324 } |
| 327 | 325 |
| 328 FileSystemFileUtilProxy::Delete( | 326 base::FileUtilProxy::RelayFileTask( |
| 329 operation_context_, proxy_, src_virtual_path_, recursive, | 327 proxy_, FROM_HERE, |
| 328 base::Bind(&FileSystemFileUtil::Delete, |
| 329 base::Unretained(operation_context_.src_file_util()), |
| 330 &operation_context_, |
| 331 src_virtual_path_, recursive), |
| 330 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 332 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 331 weak_factory_.GetWeakPtr())); | 333 base::Owned(this))); |
| 332 } | 334 } |
| 333 | 335 |
| 334 void FileSystemOperation::Write( | 336 void FileSystemOperation::Write( |
| 335 scoped_refptr<net::URLRequestContext> url_request_context, | 337 scoped_refptr<net::URLRequestContext> url_request_context, |
| 336 const GURL& path, | 338 const GURL& path, |
| 337 const GURL& blob_url, | 339 const GURL& blob_url, |
| 338 int64 offset) { | 340 int64 offset) { |
| 339 #ifndef NDEBUG | 341 #ifndef NDEBUG |
| 340 DCHECK(dispatcher_.get()); | |
| 341 DCHECK(kOperationNone == pending_operation_); | 342 DCHECK(kOperationNone == pending_operation_); |
| 342 pending_operation_ = kOperationWrite; | 343 pending_operation_ = kOperationWrite; |
| 343 #endif | 344 #endif |
| 344 if (!SetupSrcContextForWrite(path, true)) { | 345 if (!SetupSrcContextForWrite(path, true)) { |
| 345 delete this; | 346 delete this; |
| 346 return; | 347 return; |
| 347 } | 348 } |
| 348 DCHECK(blob_url.is_valid()); | 349 DCHECK(blob_url.is_valid()); |
| 349 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 350 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
| 350 blob_request_.reset( | 351 blob_request_.reset( |
| 351 new net::URLRequest(blob_url, file_writer_delegate_.get())); | 352 new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| 352 blob_request_->set_context(url_request_context); | 353 blob_request_->set_context(url_request_context); |
| 353 | 354 |
| 354 GetUsageAndQuotaThenCallback( | 355 GetUsageAndQuotaThenCallback( |
| 355 operation_context_.src_origin_url(), | 356 operation_context_.src_origin_url(), |
| 356 base::Bind(&FileSystemOperation::DelayedWriteForQuota, | 357 base::Bind(&FileSystemOperation::DelayedWriteForQuota, |
| 357 weak_factory_.GetWeakPtr())); | 358 base::Unretained(this))); |
| 358 } | 359 } |
| 359 | 360 |
| 360 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, | 361 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, |
| 361 int64 usage, int64 quota) { | 362 int64 usage, int64 quota) { |
| 362 operation_context_.set_allowed_bytes_growth(quota - usage); | 363 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 363 | 364 |
| 364 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 365 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 365 file_system_context(), | 366 file_system_context(), |
| 366 operation_context_.src_origin_url(), | 367 operation_context_.src_origin_url(), |
| 367 operation_context_.src_type())); | 368 operation_context_.src_type())); |
| 368 | 369 |
| 369 FileSystemFileUtilProxy::CreateOrOpen( | 370 int file_flags = base::PLATFORM_FILE_OPEN | |
| 370 operation_context_, | 371 base::PLATFORM_FILE_WRITE | |
| 372 base::PLATFORM_FILE_ASYNC; |
| 373 |
| 374 base::FileUtilProxy::RelayCreateOrOpen( |
| 371 proxy_, | 375 proxy_, |
| 372 src_virtual_path_, | 376 base::Bind(&FileSystemFileUtil::CreateOrOpen, |
| 373 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 377 base::Unretained(operation_context_.src_file_util()), |
| 374 base::PLATFORM_FILE_ASYNC, | 378 &operation_context_, |
| 379 src_virtual_path_, file_flags), |
| 380 base::Bind(&FileSystemFileUtil::Close, |
| 381 base::Unretained(operation_context_.src_file_util()), |
| 382 &operation_context_), |
| 375 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, | 383 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, |
| 376 weak_factory_.GetWeakPtr())); | 384 base::Unretained(this))); |
| 377 } | 385 } |
| 378 | 386 |
| 379 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 387 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
| 380 #ifndef NDEBUG | 388 #ifndef NDEBUG |
| 381 DCHECK(dispatcher_.get()); | |
| 382 DCHECK(kOperationNone == pending_operation_); | 389 DCHECK(kOperationNone == pending_operation_); |
| 383 pending_operation_ = kOperationTruncate; | 390 pending_operation_ = kOperationTruncate; |
| 384 #endif | 391 #endif |
| 385 if (!SetupSrcContextForWrite(path, false)) { | 392 if (!SetupSrcContextForWrite(path, false)) { |
| 386 delete this; | 393 delete this; |
| 387 return; | 394 return; |
| 388 } | 395 } |
| 389 length_ = length; | |
| 390 | |
| 391 GetUsageAndQuotaThenCallback( | 396 GetUsageAndQuotaThenCallback( |
| 392 operation_context_.src_origin_url(), | 397 operation_context_.src_origin_url(), |
| 393 base::Bind(&FileSystemOperation::DelayedTruncateForQuota, | 398 base::Bind(&FileSystemOperation::DelayedTruncateForQuota, |
| 394 weak_factory_.GetWeakPtr())); | 399 base::Unretained(this), length)); |
| 395 } | 400 } |
| 396 | 401 |
| 397 void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, | 402 void FileSystemOperation::DelayedTruncateForQuota(int64 length, |
| 403 quota::QuotaStatusCode status, |
| 398 int64 usage, int64 quota) { | 404 int64 usage, int64 quota) { |
| 399 operation_context_.set_allowed_bytes_growth(quota - usage); | 405 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 400 | 406 |
| 401 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 407 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 402 file_system_context(), | 408 file_system_context(), |
| 403 operation_context_.src_origin_url(), | 409 operation_context_.src_origin_url(), |
| 404 operation_context_.src_type())); | 410 operation_context_.src_type())); |
| 405 | 411 |
| 406 FileSystemFileUtilProxy::Truncate( | 412 base::FileUtilProxy::RelayFileTask( |
| 407 operation_context_, proxy_, src_virtual_path_, length_, | 413 proxy_, FROM_HERE, |
| 414 base::Bind(&FileSystemFileUtil::Truncate, |
| 415 base::Unretained(operation_context_.src_file_util()), |
| 416 &operation_context_, |
| 417 src_virtual_path_, length), |
| 408 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 418 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
| 409 weak_factory_.GetWeakPtr())); | 419 base::Owned(this))); |
| 410 } | 420 } |
| 411 | 421 |
| 412 void FileSystemOperation::TouchFile(const GURL& path, | 422 void FileSystemOperation::TouchFile(const GURL& path, |
| 413 const base::Time& last_access_time, | 423 const base::Time& last_access_time, |
| 414 const base::Time& last_modified_time) { | 424 const base::Time& last_modified_time) { |
| 415 #ifndef NDEBUG | 425 #ifndef NDEBUG |
| 416 DCHECK(dispatcher_.get()); | |
| 417 DCHECK(kOperationNone == pending_operation_); | 426 DCHECK(kOperationNone == pending_operation_); |
| 418 pending_operation_ = kOperationTouchFile; | 427 pending_operation_ = kOperationTouchFile; |
| 419 #endif | 428 #endif |
| 420 if (!SetupSrcContextForWrite(path, true)) { | 429 if (!SetupSrcContextForWrite(path, true)) { |
| 421 delete this; | 430 delete this; |
| 422 return; | 431 return; |
| 423 } | 432 } |
| 424 | 433 |
| 425 FileSystemFileUtilProxy::Touch( | 434 base::FileUtilProxy::RelayFileTask( |
| 426 operation_context_, proxy_, src_virtual_path_, | 435 proxy_, FROM_HERE, |
| 427 last_access_time, last_modified_time, | 436 base::Bind(&FileSystemFileUtil::Touch, |
| 428 base::Bind(&FileSystemOperation::DidTouchFile, | 437 base::Unretained(operation_context_.src_file_util()), |
| 429 weak_factory_.GetWeakPtr())); | 438 &operation_context_, |
| 439 src_virtual_path_, last_access_time, last_modified_time), |
| 440 base::Bind(&FileSystemOperation::DidTouchFile, base::Owned(this))); |
| 430 } | 441 } |
| 431 | 442 |
| 432 void FileSystemOperation::OpenFile(const GURL& path, | 443 void FileSystemOperation::OpenFile(const GURL& path, |
| 433 int file_flags, | 444 int file_flags, |
| 434 base::ProcessHandle peer_handle) { | 445 base::ProcessHandle peer_handle) { |
| 435 #ifndef NDEBUG | 446 #ifndef NDEBUG |
| 436 DCHECK(dispatcher_.get()); | |
| 437 DCHECK(kOperationNone == pending_operation_); | 447 DCHECK(kOperationNone == pending_operation_); |
| 438 pending_operation_ = kOperationOpenFile; | 448 pending_operation_ = kOperationOpenFile; |
| 439 #endif | 449 #endif |
| 440 peer_handle_ = peer_handle; | 450 peer_handle_ = peer_handle; |
| 441 | 451 |
| 442 if (file_flags & ( | 452 if (file_flags & ( |
| 443 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 453 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 444 base::PLATFORM_FILE_HIDDEN))) { | 454 base::PLATFORM_FILE_HIDDEN))) { |
| 445 delete this; | 455 delete this; |
| 446 return; | 456 return; |
| 447 } | 457 } |
| 448 if (file_flags & | 458 if (file_flags & |
| 449 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 459 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 450 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 460 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 451 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 461 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 452 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 462 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 453 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 463 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 454 if (!SetupSrcContextForWrite(path, true)) { | 464 if (!SetupSrcContextForWrite(path, true)) { |
| 455 delete this; | 465 delete this; |
| 456 return; | 466 return; |
| 457 } | 467 } |
| 458 } else { | 468 } else { |
| 459 if (!SetupSrcContextForRead(path)) { | 469 if (!SetupSrcContextForRead(path)) { |
| 460 delete this; | 470 delete this; |
| 461 return; | 471 return; |
| 462 } | 472 } |
| 463 } | 473 } |
| 464 file_flags_ = file_flags; | |
| 465 | |
| 466 GetUsageAndQuotaThenCallback( | 474 GetUsageAndQuotaThenCallback( |
| 467 operation_context_.src_origin_url(), | 475 operation_context_.src_origin_url(), |
| 468 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, | 476 base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, |
| 469 weak_factory_.GetWeakPtr())); | 477 base::Unretained(this), file_flags)); |
| 470 } | 478 } |
| 471 | 479 |
| 472 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, | 480 void FileSystemOperation::DelayedOpenFileForQuota(int file_flags, |
| 481 quota::QuotaStatusCode status, |
| 473 int64 usage, int64 quota) { | 482 int64 usage, int64 quota) { |
| 474 operation_context_.set_allowed_bytes_growth(quota - usage); | 483 operation_context_.set_allowed_bytes_growth(quota - usage); |
| 475 | 484 |
| 476 quota_util_helper_.reset(new ScopedQuotaUtilHelper( | 485 quota_util_helper_.reset(new ScopedQuotaUtilHelper( |
| 477 file_system_context(), | 486 file_system_context(), |
| 478 operation_context_.src_origin_url(), | 487 operation_context_.src_origin_url(), |
| 479 operation_context_.src_type())); | 488 operation_context_.src_type())); |
| 480 | 489 |
| 481 FileSystemFileUtilProxy::CreateOrOpen( | 490 base::FileUtilProxy::RelayCreateOrOpen( |
| 482 operation_context_, proxy_, src_virtual_path_, file_flags_, | 491 proxy_, |
| 483 base::Bind(&FileSystemOperation::DidOpenFile, | 492 base::Bind(&FileSystemFileUtil::CreateOrOpen, |
| 484 weak_factory_.GetWeakPtr())); | 493 base::Unretained(operation_context_.src_file_util()), |
| 494 &operation_context_, |
| 495 src_virtual_path_, file_flags), |
| 496 base::Bind(&FileSystemFileUtil::Close, |
| 497 base::Unretained(operation_context_.src_file_util()), |
| 498 &operation_context_), |
| 499 base::Bind(&FileSystemOperation::DidOpenFile, base::Owned(this))); |
| 485 } | 500 } |
| 486 | 501 |
| 487 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, | 502 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, |
| 488 FilePath* platform_path) { | 503 FilePath* platform_path) { |
| 489 #ifndef NDEBUG | 504 #ifndef NDEBUG |
| 490 DCHECK(kOperationNone == pending_operation_); | 505 DCHECK(kOperationNone == pending_operation_); |
| 491 pending_operation_ = kOperationGetLocalPath; | 506 pending_operation_ = kOperationGetLocalPath; |
| 492 #endif | 507 #endif |
| 493 if (!SetupSrcContextForRead(path)) { | 508 if (!SetupSrcContextForRead(path)) { |
| 494 delete this; | 509 delete this; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 511 #endif | 526 #endif |
| 512 // Writes are done without proxying through FileUtilProxy after the initial | 527 // Writes are done without proxying through FileUtilProxy after the initial |
| 513 // opening of the PlatformFile. All state changes are done on this thread, | 528 // opening of the PlatformFile. All state changes are done on this thread, |
| 514 // so we're guaranteed to be able to shut down atomically. We do need to | 529 // so we're guaranteed to be able to shut down atomically. We do need to |
| 515 // check that the file has been opened [which means the blob_request_ has | 530 // check that the file has been opened [which means the blob_request_ has |
| 516 // been created], so we know how much we need to do. | 531 // been created], so we know how much we need to do. |
| 517 if (blob_request_.get()) | 532 if (blob_request_.get()) |
| 518 // This halts any calls to file_writer_delegate_ from blob_request_. | 533 // This halts any calls to file_writer_delegate_ from blob_request_. |
| 519 blob_request_->Cancel(); | 534 blob_request_->Cancel(); |
| 520 | 535 |
| 521 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 536 if (dispatcher_.get()) |
| 537 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); |
| 522 cancel_operation->dispatcher_->DidSucceed(); | 538 cancel_operation->dispatcher_->DidSucceed(); |
| 523 delete this; | 539 dispatcher_.reset(); |
| 524 } else { | 540 } else { |
| 525 #ifndef NDEBUG | 541 #ifndef NDEBUG |
| 526 DCHECK(kOperationTruncate == pending_operation_); | 542 DCHECK(kOperationTruncate == pending_operation_); |
| 527 #endif | 543 #endif |
| 528 // We're cancelling a truncate operation, but we can't actually stop it | 544 // We're cancelling a truncate operation, but we can't actually stop it |
| 529 // since it's been proxied to another thread. We need to save the | 545 // since it's been proxied to another thread. We need to save the |
| 530 // cancel_operation so that when the truncate returns, it can see that it's | 546 // cancel_operation so that when the truncate returns, it can see that it's |
| 531 // been cancelled, report it, and report that the cancel has succeeded. | 547 // been cancelled, report it, and report that the cancel has succeeded. |
| 532 DCHECK(!cancel_operation_.get()); | 548 DCHECK(!cancel_operation_.get()); |
| 533 cancel_operation_.swap(cancel_operation); | 549 cancel_operation_.swap(cancel_operation); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 554 FileSystemTypeToQuotaStorageType( | 570 FileSystemTypeToQuotaStorageType( |
| 555 operation_context_.src_type()), | 571 operation_context_.src_type()), |
| 556 callback); | 572 callback); |
| 557 } | 573 } |
| 558 | 574 |
| 559 void FileSystemOperation::DidGetRootPath( | 575 void FileSystemOperation::DidGetRootPath( |
| 560 bool success, | 576 bool success, |
| 561 const FilePath& path, const std::string& name) { | 577 const FilePath& path, const std::string& name) { |
| 562 DCHECK(success || path.empty()); | 578 DCHECK(success || path.empty()); |
| 563 GURL result; | 579 GURL result; |
| 580 if (!dispatcher_.get()) |
| 581 return; |
| 564 // We ignore the path, and return a URL instead. The point was just to verify | 582 // We ignore the path, and return a URL instead. The point was just to verify |
| 565 // that we could create/find the path. | 583 // that we could create/find the path. |
| 566 if (success) { | 584 if (success) { |
| 567 result = GetFileSystemRootURI( | 585 result = GetFileSystemRootURI( |
| 568 operation_context_.src_origin_url(), | 586 operation_context_.src_origin_url(), |
| 569 operation_context_.src_type()); | 587 operation_context_.src_type()); |
| 570 } | 588 } |
| 571 dispatcher_->DidOpenFileSystem(name, result); | 589 dispatcher_->DidOpenFileSystem(name, result); |
| 572 delete this; | |
| 573 } | 590 } |
| 574 | 591 |
| 575 void FileSystemOperation::DidEnsureFileExistsExclusive( | 592 void FileSystemOperation::DidEnsureFileExistsExclusive( |
| 576 base::PlatformFileError rv, bool created) { | 593 base::PlatformFileError rv, bool created) { |
| 577 if (rv == base::PLATFORM_FILE_OK && !created) { | 594 if (rv == base::PLATFORM_FILE_OK && !created) { |
| 578 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); | 595 if (dispatcher_.get()) |
| 579 delete this; | 596 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); |
| 580 } else { | 597 } else { |
| 581 DidFinishFileOperation(rv); | 598 DidFinishFileOperation(rv); |
| 582 } | 599 } |
| 583 } | 600 } |
| 584 | 601 |
| 585 void FileSystemOperation::DidEnsureFileExistsNonExclusive( | 602 void FileSystemOperation::DidEnsureFileExistsNonExclusive( |
| 586 base::PlatformFileError rv, bool /* created */) { | 603 base::PlatformFileError rv, bool /* created */) { |
| 587 DidFinishFileOperation(rv); | 604 DidFinishFileOperation(rv); |
| 588 } | 605 } |
| 589 | 606 |
| 590 void FileSystemOperation::DidFinishFileOperation( | 607 void FileSystemOperation::DidFinishFileOperation( |
| 591 base::PlatformFileError rv) { | 608 base::PlatformFileError rv) { |
| 592 if (cancel_operation_.get()) { | 609 if (cancel_operation_.get()) { |
| 593 #ifndef NDEBUG | 610 #ifndef NDEBUG |
| 594 DCHECK(kOperationTruncate == pending_operation_); | 611 DCHECK(kOperationTruncate == pending_operation_); |
| 595 #endif | 612 #endif |
| 596 | 613 |
| 597 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 614 if (dispatcher_.get()) |
| 615 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); |
| 598 cancel_operation_->dispatcher_->DidSucceed(); | 616 cancel_operation_->dispatcher_->DidSucceed(); |
| 599 } else if (rv == base::PLATFORM_FILE_OK) { | 617 } else if (dispatcher_.get()) { |
| 600 dispatcher_->DidSucceed(); | 618 if (rv == base::PLATFORM_FILE_OK) |
| 601 } else { | 619 dispatcher_->DidSucceed(); |
| 602 dispatcher_->DidFail(rv); | 620 else |
| 621 dispatcher_->DidFail(rv); |
| 603 } | 622 } |
| 604 delete this; | |
| 605 } | 623 } |
| 606 | 624 |
| 607 void FileSystemOperation::DidDirectoryExists( | 625 void FileSystemOperation::DidDirectoryExists( |
| 608 base::PlatformFileError rv, | 626 base::PlatformFileError rv, |
| 609 const base::PlatformFileInfo& file_info, | 627 const base::PlatformFileInfo& file_info, |
| 610 const FilePath& unused) { | 628 const FilePath& unused) { |
| 629 if (!dispatcher_.get()) |
| 630 return; |
| 611 if (rv == base::PLATFORM_FILE_OK) { | 631 if (rv == base::PLATFORM_FILE_OK) { |
| 612 if (file_info.is_directory) | 632 if (file_info.is_directory) |
| 613 dispatcher_->DidSucceed(); | 633 dispatcher_->DidSucceed(); |
| 614 else | 634 else |
| 615 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY); | 635 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY); |
| 616 } else { | 636 } else { |
| 617 dispatcher_->DidFail(rv); | 637 dispatcher_->DidFail(rv); |
| 618 } | 638 } |
| 619 delete this; | |
| 620 } | 639 } |
| 621 | 640 |
| 622 void FileSystemOperation::DidFileExists( | 641 void FileSystemOperation::DidFileExists( |
| 623 base::PlatformFileError rv, | 642 base::PlatformFileError rv, |
| 624 const base::PlatformFileInfo& file_info, | 643 const base::PlatformFileInfo& file_info, |
| 625 const FilePath& unused) { | 644 const FilePath& unused) { |
| 645 if (!dispatcher_.get()) |
| 646 return; |
| 626 if (rv == base::PLATFORM_FILE_OK) { | 647 if (rv == base::PLATFORM_FILE_OK) { |
| 627 if (file_info.is_directory) | 648 if (file_info.is_directory) |
| 628 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); | 649 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); |
| 629 else | 650 else |
| 630 dispatcher_->DidSucceed(); | 651 dispatcher_->DidSucceed(); |
| 631 } else { | 652 } else { |
| 632 dispatcher_->DidFail(rv); | 653 dispatcher_->DidFail(rv); |
| 633 } | 654 } |
| 634 delete this; | |
| 635 } | 655 } |
| 636 | 656 |
| 637 void FileSystemOperation::DidGetMetadata( | 657 void FileSystemOperation::DidGetMetadata( |
| 638 base::PlatformFileError rv, | 658 base::PlatformFileError rv, |
| 639 const base::PlatformFileInfo& file_info, | 659 const base::PlatformFileInfo& file_info, |
| 640 const FilePath& platform_path) { | 660 const FilePath& platform_path) { |
| 661 if (!dispatcher_.get()) |
| 662 return; |
| 641 if (rv == base::PLATFORM_FILE_OK) | 663 if (rv == base::PLATFORM_FILE_OK) |
| 642 dispatcher_->DidReadMetadata(file_info, platform_path); | 664 dispatcher_->DidReadMetadata(file_info, platform_path); |
| 643 else | 665 else |
| 644 dispatcher_->DidFail(rv); | 666 dispatcher_->DidFail(rv); |
| 645 delete this; | |
| 646 } | 667 } |
| 647 | 668 |
| 648 void FileSystemOperation::DidReadDirectory( | 669 void FileSystemOperation::DidReadDirectory( |
| 649 base::PlatformFileError rv, | 670 base::PlatformFileError rv, |
| 650 const std::vector<base::FileUtilProxy::Entry>& entries) { | 671 const std::vector<base::FileUtilProxy::Entry>& entries) { |
| 672 if (!dispatcher_.get()) |
| 673 return; |
| 651 | 674 |
| 652 if (rv == base::PLATFORM_FILE_OK) | 675 if (rv == base::PLATFORM_FILE_OK) |
| 653 dispatcher_->DidReadDirectory(entries, false /* has_more */); | 676 dispatcher_->DidReadDirectory(entries, false /* has_more */); |
| 654 else | 677 else |
| 655 dispatcher_->DidFail(rv); | 678 dispatcher_->DidFail(rv); |
| 656 delete this; | |
| 657 } | 679 } |
| 658 | 680 |
| 659 void FileSystemOperation::DidWrite( | 681 void FileSystemOperation::DidWrite( |
| 660 base::PlatformFileError rv, | 682 base::PlatformFileError rv, |
| 661 int64 bytes, | 683 int64 bytes, |
| 662 bool complete) { | 684 bool complete) { |
| 685 if (!dispatcher_.get()) { |
| 686 delete this; |
| 687 return; |
| 688 } |
| 663 if (rv == base::PLATFORM_FILE_OK) | 689 if (rv == base::PLATFORM_FILE_OK) |
| 664 dispatcher_->DidWrite(bytes, complete); | 690 dispatcher_->DidWrite(bytes, complete); |
| 665 else | 691 else |
| 666 dispatcher_->DidFail(rv); | 692 dispatcher_->DidFail(rv); |
| 667 if (complete || rv != base::PLATFORM_FILE_OK) | 693 if (complete || rv != base::PLATFORM_FILE_OK) |
| 668 delete this; | 694 delete this; |
| 669 } | 695 } |
| 670 | 696 |
| 671 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { | 697 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { |
| 698 if (!dispatcher_.get()) |
| 699 return; |
| 672 if (rv == base::PLATFORM_FILE_OK) | 700 if (rv == base::PLATFORM_FILE_OK) |
| 673 dispatcher_->DidSucceed(); | 701 dispatcher_->DidSucceed(); |
| 674 else | 702 else |
| 675 dispatcher_->DidFail(rv); | 703 dispatcher_->DidFail(rv); |
| 676 delete this; | |
| 677 } | 704 } |
| 678 | 705 |
| 679 void FileSystemOperation::DidOpenFile( | 706 void FileSystemOperation::DidOpenFile( |
| 680 base::PlatformFileError rv, | 707 base::PlatformFileError rv, |
| 681 base::PassPlatformFile file, | 708 base::PassPlatformFile file, |
| 682 bool unused) { | 709 bool unused) { |
| 710 if (!dispatcher_.get()) |
| 711 return; |
| 683 if (rv == base::PLATFORM_FILE_OK) | 712 if (rv == base::PLATFORM_FILE_OK) |
| 684 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); | 713 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); |
| 685 else | 714 else |
| 686 dispatcher_->DidFail(rv); | 715 dispatcher_->DidFail(rv); |
| 687 delete this; | |
| 688 } | 716 } |
| 689 | 717 |
| 690 void FileSystemOperation::OnFileOpenedForWrite( | 718 void FileSystemOperation::OnFileOpenedForWrite( |
| 691 base::PlatformFileError rv, | 719 base::PlatformFileError rv, |
| 692 base::PassPlatformFile file, | 720 base::PassPlatformFile file, |
| 693 bool created) { | 721 bool created) { |
| 694 if (base::PLATFORM_FILE_OK != rv) { | 722 if (base::PLATFORM_FILE_OK != rv || !dispatcher_.get()) { |
| 695 dispatcher_->DidFail(rv); | 723 if (dispatcher_.get()) |
| 724 dispatcher_->DidFail(rv); |
| 696 delete this; | 725 delete this; |
| 697 return; | 726 return; |
| 698 } | 727 } |
| 699 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); | 728 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); |
| 700 } | 729 } |
| 701 | 730 |
| 702 bool FileSystemOperation::VerifyFileSystemPathForRead( | 731 bool FileSystemOperation::VerifyFileSystemPathForRead( |
| 703 const GURL& path, GURL* origin_url, FileSystemType* type, | 732 const GURL& path, GURL* origin_url, FileSystemType* type, |
| 704 FilePath* virtual_path, FileSystemFileUtil** file_util) { | 733 FilePath* virtual_path, FileSystemFileUtil** file_util) { |
| 705 | 734 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 bool result = VerifyFileSystemPathForWrite( | 870 bool result = VerifyFileSystemPathForWrite( |
| 842 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); | 871 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); |
| 843 operation_context_.set_dest_origin_url(origin_url); | 872 operation_context_.set_dest_origin_url(origin_url); |
| 844 operation_context_.set_dest_type(type); | 873 operation_context_.set_dest_type(type); |
| 845 if (!operation_context_.dest_file_util()) | 874 if (!operation_context_.dest_file_util()) |
| 846 operation_context_.set_dest_file_util(file_util); | 875 operation_context_.set_dest_file_util(file_util); |
| 847 return result; | 876 return result; |
| 848 } | 877 } |
| 849 | 878 |
| 850 } // namespace fileapi | 879 } // namespace fileapi |
| OLD | NEW |