| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/fileapi/file_system_operation_runner.h" | 5 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 void FileSystemOperationRunner::Shutdown() { | 46 void FileSystemOperationRunner::Shutdown() { |
| 47 operations_.Clear(); | 47 operations_.Clear(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 OperationID FileSystemOperationRunner::CreateFile( | 50 OperationID FileSystemOperationRunner::CreateFile( |
| 51 const FileSystemURL& url, | 51 const FileSystemURL& url, |
| 52 bool exclusive, | 52 bool exclusive, |
| 53 const StatusCallback& callback) { | 53 const StatusCallback& callback) { |
| 54 base::File::Error error = base::File::FILE_OK; | 54 base::File::Error error = base::File::FILE_OK; |
| 55 FileSystemOperation* operation = | 55 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 56 file_system_context_->CreateFileSystemOperation(url, &error); | 56 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 57 | 57 FileSystemOperation* operation_raw = operation.get(); |
| 58 BeginOperationScoper scope; | 58 BeginOperationScoper scope; |
| 59 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 59 OperationHandle handle = |
| 60 if (!operation) { | 60 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 61 if (!operation_raw) { |
| 61 DidFinish(handle, callback, error); | 62 DidFinish(handle, callback, error); |
| 62 return handle.id; | 63 return handle.id; |
| 63 } | 64 } |
| 64 PrepareForWrite(handle.id, url); | 65 PrepareForWrite(handle.id, url); |
| 65 operation->CreateFile( | 66 operation_raw->CreateFile( |
| 66 url, exclusive, | 67 url, exclusive, |
| 67 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 68 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 68 handle, callback)); | 69 handle, callback)); |
| 69 return handle.id; | 70 return handle.id; |
| 70 } | 71 } |
| 71 | 72 |
| 72 OperationID FileSystemOperationRunner::CreateDirectory( | 73 OperationID FileSystemOperationRunner::CreateDirectory( |
| 73 const FileSystemURL& url, | 74 const FileSystemURL& url, |
| 74 bool exclusive, | 75 bool exclusive, |
| 75 bool recursive, | 76 bool recursive, |
| 76 const StatusCallback& callback) { | 77 const StatusCallback& callback) { |
| 77 base::File::Error error = base::File::FILE_OK; | 78 base::File::Error error = base::File::FILE_OK; |
| 78 FileSystemOperation* operation = | 79 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 79 file_system_context_->CreateFileSystemOperation(url, &error); | 80 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 81 FileSystemOperation* operation_raw = operation.get(); |
| 80 BeginOperationScoper scope; | 82 BeginOperationScoper scope; |
| 81 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 83 OperationHandle handle = |
| 82 if (!operation) { | 84 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 85 if (!operation_raw) { |
| 83 DidFinish(handle, callback, error); | 86 DidFinish(handle, callback, error); |
| 84 return handle.id; | 87 return handle.id; |
| 85 } | 88 } |
| 86 PrepareForWrite(handle.id, url); | 89 PrepareForWrite(handle.id, url); |
| 87 operation->CreateDirectory( | 90 operation_raw->CreateDirectory( |
| 88 url, exclusive, recursive, | 91 url, exclusive, recursive, |
| 89 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 92 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 90 handle, callback)); | 93 handle, callback)); |
| 91 return handle.id; | 94 return handle.id; |
| 92 } | 95 } |
| 93 | 96 |
| 94 OperationID FileSystemOperationRunner::Copy( | 97 OperationID FileSystemOperationRunner::Copy( |
| 95 const FileSystemURL& src_url, | 98 const FileSystemURL& src_url, |
| 96 const FileSystemURL& dest_url, | 99 const FileSystemURL& dest_url, |
| 97 CopyOrMoveOption option, | 100 CopyOrMoveOption option, |
| 98 ErrorBehavior error_behavior, | 101 ErrorBehavior error_behavior, |
| 99 const CopyProgressCallback& progress_callback, | 102 const CopyProgressCallback& progress_callback, |
| 100 const StatusCallback& callback) { | 103 const StatusCallback& callback) { |
| 101 base::File::Error error = base::File::FILE_OK; | 104 base::File::Error error = base::File::FILE_OK; |
| 102 FileSystemOperation* operation = | 105 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 103 file_system_context_->CreateFileSystemOperation(dest_url, &error); | 106 file_system_context_->CreateFileSystemOperation(dest_url, &error)); |
| 107 FileSystemOperation* operation_raw = operation.get(); |
| 104 BeginOperationScoper scope; | 108 BeginOperationScoper scope; |
| 105 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 109 OperationHandle handle = |
| 106 if (!operation) { | 110 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 111 if (!operation_raw) { |
| 107 DidFinish(handle, callback, error); | 112 DidFinish(handle, callback, error); |
| 108 return handle.id; | 113 return handle.id; |
| 109 } | 114 } |
| 110 PrepareForWrite(handle.id, dest_url); | 115 PrepareForWrite(handle.id, dest_url); |
| 111 PrepareForRead(handle.id, src_url); | 116 PrepareForRead(handle.id, src_url); |
| 112 operation->Copy(src_url, dest_url, option, error_behavior, | 117 operation_raw->Copy(src_url, dest_url, option, error_behavior, |
| 113 progress_callback.is_null() | 118 progress_callback.is_null() |
| 114 ? CopyProgressCallback() | 119 ? CopyProgressCallback() |
| 115 : base::Bind(&FileSystemOperationRunner::OnCopyProgress, | 120 : base::Bind(&FileSystemOperationRunner::OnCopyProgress, |
| 116 AsWeakPtr(), handle, progress_callback), | 121 AsWeakPtr(), handle, progress_callback), |
| 117 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 122 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 118 handle, callback)); | 123 handle, callback)); |
| 119 return handle.id; | 124 return handle.id; |
| 120 } | 125 } |
| 121 | 126 |
| 122 OperationID FileSystemOperationRunner::Move( | 127 OperationID FileSystemOperationRunner::Move( |
| 123 const FileSystemURL& src_url, | 128 const FileSystemURL& src_url, |
| 124 const FileSystemURL& dest_url, | 129 const FileSystemURL& dest_url, |
| 125 CopyOrMoveOption option, | 130 CopyOrMoveOption option, |
| 126 const StatusCallback& callback) { | 131 const StatusCallback& callback) { |
| 127 base::File::Error error = base::File::FILE_OK; | 132 base::File::Error error = base::File::FILE_OK; |
| 128 FileSystemOperation* operation = | 133 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 129 file_system_context_->CreateFileSystemOperation(dest_url, &error); | 134 file_system_context_->CreateFileSystemOperation(dest_url, &error)); |
| 135 FileSystemOperation* operation_raw = operation.get(); |
| 130 BeginOperationScoper scope; | 136 BeginOperationScoper scope; |
| 131 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 137 OperationHandle handle = |
| 132 if (!operation) { | 138 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 139 if (!operation_raw) { |
| 133 DidFinish(handle, callback, error); | 140 DidFinish(handle, callback, error); |
| 134 return handle.id; | 141 return handle.id; |
| 135 } | 142 } |
| 136 PrepareForWrite(handle.id, dest_url); | 143 PrepareForWrite(handle.id, dest_url); |
| 137 PrepareForWrite(handle.id, src_url); | 144 PrepareForWrite(handle.id, src_url); |
| 138 operation->Move( | 145 operation_raw->Move( |
| 139 src_url, dest_url, option, | 146 src_url, dest_url, option, |
| 140 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 147 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 141 handle, callback)); | 148 handle, callback)); |
| 142 return handle.id; | 149 return handle.id; |
| 143 } | 150 } |
| 144 | 151 |
| 145 OperationID FileSystemOperationRunner::DirectoryExists( | 152 OperationID FileSystemOperationRunner::DirectoryExists( |
| 146 const FileSystemURL& url, | 153 const FileSystemURL& url, |
| 147 const StatusCallback& callback) { | 154 const StatusCallback& callback) { |
| 148 base::File::Error error = base::File::FILE_OK; | 155 base::File::Error error = base::File::FILE_OK; |
| 149 FileSystemOperation* operation = | 156 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 150 file_system_context_->CreateFileSystemOperation(url, &error); | 157 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 158 FileSystemOperation* operation_raw = operation.get(); |
| 151 BeginOperationScoper scope; | 159 BeginOperationScoper scope; |
| 152 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 160 OperationHandle handle = |
| 153 if (!operation) { | 161 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 162 if (!operation_raw) { |
| 154 DidFinish(handle, callback, error); | 163 DidFinish(handle, callback, error); |
| 155 return handle.id; | 164 return handle.id; |
| 156 } | 165 } |
| 157 PrepareForRead(handle.id, url); | 166 PrepareForRead(handle.id, url); |
| 158 operation->DirectoryExists( | 167 operation_raw->DirectoryExists( |
| 159 url, | 168 url, |
| 160 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 169 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 161 handle, callback)); | 170 handle, callback)); |
| 162 return handle.id; | 171 return handle.id; |
| 163 } | 172 } |
| 164 | 173 |
| 165 OperationID FileSystemOperationRunner::FileExists( | 174 OperationID FileSystemOperationRunner::FileExists( |
| 166 const FileSystemURL& url, | 175 const FileSystemURL& url, |
| 167 const StatusCallback& callback) { | 176 const StatusCallback& callback) { |
| 168 base::File::Error error = base::File::FILE_OK; | 177 base::File::Error error = base::File::FILE_OK; |
| 169 FileSystemOperation* operation = | 178 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 170 file_system_context_->CreateFileSystemOperation(url, &error); | 179 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 180 FileSystemOperation* operation_raw = operation.get(); |
| 171 BeginOperationScoper scope; | 181 BeginOperationScoper scope; |
| 172 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 182 OperationHandle handle = |
| 173 if (!operation) { | 183 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 184 if (!operation_raw) { |
| 174 DidFinish(handle, callback, error); | 185 DidFinish(handle, callback, error); |
| 175 return handle.id; | 186 return handle.id; |
| 176 } | 187 } |
| 177 PrepareForRead(handle.id, url); | 188 PrepareForRead(handle.id, url); |
| 178 operation->FileExists( | 189 operation_raw->FileExists( |
| 179 url, | 190 url, |
| 180 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 191 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 181 handle, callback)); | 192 handle, callback)); |
| 182 return handle.id; | 193 return handle.id; |
| 183 } | 194 } |
| 184 | 195 |
| 185 OperationID FileSystemOperationRunner::GetMetadata( | 196 OperationID FileSystemOperationRunner::GetMetadata( |
| 186 const FileSystemURL& url, | 197 const FileSystemURL& url, |
| 187 int fields, | 198 int fields, |
| 188 const GetMetadataCallback& callback) { | 199 const GetMetadataCallback& callback) { |
| 189 base::File::Error error = base::File::FILE_OK; | 200 base::File::Error error = base::File::FILE_OK; |
| 190 FileSystemOperation* operation = | 201 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 191 file_system_context_->CreateFileSystemOperation(url, &error); | 202 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 203 FileSystemOperation* operation_raw = operation.get(); |
| 192 BeginOperationScoper scope; | 204 BeginOperationScoper scope; |
| 193 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 205 OperationHandle handle = |
| 194 if (!operation) { | 206 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 207 if (!operation_raw) { |
| 195 DidGetMetadata(handle, callback, error, base::File::Info()); | 208 DidGetMetadata(handle, callback, error, base::File::Info()); |
| 196 return handle.id; | 209 return handle.id; |
| 197 } | 210 } |
| 198 PrepareForRead(handle.id, url); | 211 PrepareForRead(handle.id, url); |
| 199 operation->GetMetadata(url, fields, | 212 operation_raw->GetMetadata(url, fields, |
| 200 base::Bind(&FileSystemOperationRunner::DidGetMetadata, | 213 base::Bind(&FileSystemOperationRunner::DidGetMetadata, |
| 201 AsWeakPtr(), handle, callback)); | 214 AsWeakPtr(), handle, callback)); |
| 202 return handle.id; | 215 return handle.id; |
| 203 } | 216 } |
| 204 | 217 |
| 205 OperationID FileSystemOperationRunner::ReadDirectory( | 218 OperationID FileSystemOperationRunner::ReadDirectory( |
| 206 const FileSystemURL& url, | 219 const FileSystemURL& url, |
| 207 const ReadDirectoryCallback& callback) { | 220 const ReadDirectoryCallback& callback) { |
| 208 base::File::Error error = base::File::FILE_OK; | 221 base::File::Error error = base::File::FILE_OK; |
| 209 FileSystemOperation* operation = | 222 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 210 file_system_context_->CreateFileSystemOperation(url, &error); | 223 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 224 FileSystemOperation* operation_raw = operation.get(); |
| 211 BeginOperationScoper scope; | 225 BeginOperationScoper scope; |
| 212 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 226 OperationHandle handle = |
| 213 if (!operation) { | 227 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 228 if (!operation_raw) { |
| 214 DidReadDirectory(handle, callback, error, std::vector<DirectoryEntry>(), | 229 DidReadDirectory(handle, callback, error, std::vector<DirectoryEntry>(), |
| 215 false); | 230 false); |
| 216 return handle.id; | 231 return handle.id; |
| 217 } | 232 } |
| 218 PrepareForRead(handle.id, url); | 233 PrepareForRead(handle.id, url); |
| 219 operation->ReadDirectory( | 234 operation_raw->ReadDirectory( |
| 220 url, | 235 url, |
| 221 base::Bind(&FileSystemOperationRunner::DidReadDirectory, AsWeakPtr(), | 236 base::Bind(&FileSystemOperationRunner::DidReadDirectory, AsWeakPtr(), |
| 222 handle, callback)); | 237 handle, callback)); |
| 223 return handle.id; | 238 return handle.id; |
| 224 } | 239 } |
| 225 | 240 |
| 226 OperationID FileSystemOperationRunner::Remove( | 241 OperationID FileSystemOperationRunner::Remove( |
| 227 const FileSystemURL& url, bool recursive, | 242 const FileSystemURL& url, bool recursive, |
| 228 const StatusCallback& callback) { | 243 const StatusCallback& callback) { |
| 229 base::File::Error error = base::File::FILE_OK; | 244 base::File::Error error = base::File::FILE_OK; |
| 230 FileSystemOperation* operation = | 245 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 231 file_system_context_->CreateFileSystemOperation(url, &error); | 246 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 247 FileSystemOperation* operation_raw = operation.get(); |
| 232 BeginOperationScoper scope; | 248 BeginOperationScoper scope; |
| 233 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 249 OperationHandle handle = |
| 234 if (!operation) { | 250 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 251 if (!operation_raw) { |
| 235 DidFinish(handle, callback, error); | 252 DidFinish(handle, callback, error); |
| 236 return handle.id; | 253 return handle.id; |
| 237 } | 254 } |
| 238 PrepareForWrite(handle.id, url); | 255 PrepareForWrite(handle.id, url); |
| 239 operation->Remove( | 256 operation_raw->Remove( |
| 240 url, recursive, | 257 url, recursive, |
| 241 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 258 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 242 handle, callback)); | 259 handle, callback)); |
| 243 return handle.id; | 260 return handle.id; |
| 244 } | 261 } |
| 245 | 262 |
| 246 OperationID FileSystemOperationRunner::Write( | 263 OperationID FileSystemOperationRunner::Write( |
| 247 const net::URLRequestContext* url_request_context, | 264 const net::URLRequestContext* url_request_context, |
| 248 const FileSystemURL& url, | 265 const FileSystemURL& url, |
| 249 std::unique_ptr<storage::BlobDataHandle> blob, | 266 std::unique_ptr<storage::BlobDataHandle> blob, |
| 250 int64_t offset, | 267 int64_t offset, |
| 251 const WriteCallback& callback) { | 268 const WriteCallback& callback) { |
| 252 base::File::Error error = base::File::FILE_OK; | 269 base::File::Error error = base::File::FILE_OK; |
| 253 FileSystemOperation* operation = | 270 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 254 file_system_context_->CreateFileSystemOperation(url, &error); | 271 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 255 | 272 FileSystemOperation* operation_raw = operation.get(); |
| 256 BeginOperationScoper scope; | 273 BeginOperationScoper scope; |
| 257 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 274 OperationHandle handle = |
| 258 if (!operation) { | 275 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 276 if (!operation_raw) { |
| 259 DidWrite(handle, callback, error, 0, true); | 277 DidWrite(handle, callback, error, 0, true); |
| 260 return handle.id; | 278 return handle.id; |
| 261 } | 279 } |
| 262 | 280 |
| 263 std::unique_ptr<FileStreamWriter> writer( | 281 std::unique_ptr<FileStreamWriter> writer( |
| 264 file_system_context_->CreateFileStreamWriter(url, offset)); | 282 file_system_context_->CreateFileStreamWriter(url, offset)); |
| 265 if (!writer) { | 283 if (!writer) { |
| 266 // Write is not supported. | 284 // Write is not supported. |
| 267 DidWrite(handle, callback, base::File::FILE_ERROR_SECURITY, 0, true); | 285 DidWrite(handle, callback, base::File::FILE_ERROR_SECURITY, 0, true); |
| 268 return handle.id; | 286 return handle.id; |
| 269 } | 287 } |
| 270 | 288 |
| 271 std::unique_ptr<FileWriterDelegate> writer_delegate(new FileWriterDelegate( | 289 std::unique_ptr<FileWriterDelegate> writer_delegate(new FileWriterDelegate( |
| 272 std::move(writer), url.mount_option().flush_policy())); | 290 std::move(writer), url.mount_option().flush_policy())); |
| 273 | 291 |
| 274 std::unique_ptr<net::URLRequest> blob_request( | 292 std::unique_ptr<net::URLRequest> blob_request( |
| 275 storage::BlobProtocolHandler::CreateBlobRequest( | 293 storage::BlobProtocolHandler::CreateBlobRequest( |
| 276 std::move(blob), url_request_context, writer_delegate.get())); | 294 std::move(blob), url_request_context, writer_delegate.get())); |
| 277 | 295 |
| 278 PrepareForWrite(handle.id, url); | 296 PrepareForWrite(handle.id, url); |
| 279 operation->Write(url, std::move(writer_delegate), std::move(blob_request), | 297 operation_raw->Write(url, std::move(writer_delegate), std::move(blob_request), |
| 280 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), | 298 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), |
| 281 handle, callback)); | 299 handle, callback)); |
| 282 return handle.id; | 300 return handle.id; |
| 283 } | 301 } |
| 284 | 302 |
| 285 OperationID FileSystemOperationRunner::Truncate( | 303 OperationID FileSystemOperationRunner::Truncate( |
| 286 const FileSystemURL& url, | 304 const FileSystemURL& url, |
| 287 int64_t length, | 305 int64_t length, |
| 288 const StatusCallback& callback) { | 306 const StatusCallback& callback) { |
| 289 base::File::Error error = base::File::FILE_OK; | 307 base::File::Error error = base::File::FILE_OK; |
| 290 FileSystemOperation* operation = | 308 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 291 file_system_context_->CreateFileSystemOperation(url, &error); | 309 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 310 FileSystemOperation* operation_raw = operation.get(); |
| 292 BeginOperationScoper scope; | 311 BeginOperationScoper scope; |
| 293 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 312 OperationHandle handle = |
| 294 if (!operation) { | 313 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 314 if (!operation_raw) { |
| 295 DidFinish(handle, callback, error); | 315 DidFinish(handle, callback, error); |
| 296 return handle.id; | 316 return handle.id; |
| 297 } | 317 } |
| 298 PrepareForWrite(handle.id, url); | 318 PrepareForWrite(handle.id, url); |
| 299 operation->Truncate( | 319 operation_raw->Truncate( |
| 300 url, length, | 320 url, length, |
| 301 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 321 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 302 handle, callback)); | 322 handle, callback)); |
| 303 return handle.id; | 323 return handle.id; |
| 304 } | 324 } |
| 305 | 325 |
| 306 void FileSystemOperationRunner::Cancel( | 326 void FileSystemOperationRunner::Cancel( |
| 307 OperationID id, | 327 OperationID id, |
| 308 const StatusCallback& callback) { | 328 const StatusCallback& callback) { |
| 309 if (base::ContainsKey(finished_operations_, id)) { | 329 if (base::ContainsKey(finished_operations_, id)) { |
| 310 DCHECK(!base::ContainsKey(stray_cancel_callbacks_, id)); | 330 DCHECK(!base::ContainsKey(stray_cancel_callbacks_, id)); |
| 311 stray_cancel_callbacks_[id] = callback; | 331 stray_cancel_callbacks_[id] = callback; |
| 312 return; | 332 return; |
| 313 } | 333 } |
| 314 FileSystemOperation* operation = operations_.Lookup(id); | 334 FileSystemOperation* operation = operations_.Lookup(id); |
| 315 if (!operation) { | 335 if (!operation) { |
| 316 // There is no operation with |id|. | 336 // There is no operation with |id|. |
| 317 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 337 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 318 return; | 338 return; |
| 319 } | 339 } |
| 320 operation->Cancel(callback); | 340 operation->Cancel(callback); |
| 321 } | 341 } |
| 322 | 342 |
| 323 OperationID FileSystemOperationRunner::TouchFile( | 343 OperationID FileSystemOperationRunner::TouchFile( |
| 324 const FileSystemURL& url, | 344 const FileSystemURL& url, |
| 325 const base::Time& last_access_time, | 345 const base::Time& last_access_time, |
| 326 const base::Time& last_modified_time, | 346 const base::Time& last_modified_time, |
| 327 const StatusCallback& callback) { | 347 const StatusCallback& callback) { |
| 328 base::File::Error error = base::File::FILE_OK; | 348 base::File::Error error = base::File::FILE_OK; |
| 329 FileSystemOperation* operation = | 349 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 330 file_system_context_->CreateFileSystemOperation(url, &error); | 350 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 351 FileSystemOperation* operation_raw = operation.get(); |
| 331 BeginOperationScoper scope; | 352 BeginOperationScoper scope; |
| 332 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 353 OperationHandle handle = |
| 333 if (!operation) { | 354 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 355 if (!operation_raw) { |
| 334 DidFinish(handle, callback, error); | 356 DidFinish(handle, callback, error); |
| 335 return handle.id; | 357 return handle.id; |
| 336 } | 358 } |
| 337 PrepareForWrite(handle.id, url); | 359 PrepareForWrite(handle.id, url); |
| 338 operation->TouchFile( | 360 operation_raw->TouchFile( |
| 339 url, last_access_time, last_modified_time, | 361 url, last_access_time, last_modified_time, |
| 340 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 362 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 341 handle, callback)); | 363 handle, callback)); |
| 342 return handle.id; | 364 return handle.id; |
| 343 } | 365 } |
| 344 | 366 |
| 345 OperationID FileSystemOperationRunner::OpenFile( | 367 OperationID FileSystemOperationRunner::OpenFile( |
| 346 const FileSystemURL& url, | 368 const FileSystemURL& url, |
| 347 int file_flags, | 369 int file_flags, |
| 348 const OpenFileCallback& callback) { | 370 const OpenFileCallback& callback) { |
| 349 base::File::Error error = base::File::FILE_OK; | 371 base::File::Error error = base::File::FILE_OK; |
| 350 FileSystemOperation* operation = | 372 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 351 file_system_context_->CreateFileSystemOperation(url, &error); | 373 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 374 FileSystemOperation* operation_raw = operation.get(); |
| 352 BeginOperationScoper scope; | 375 BeginOperationScoper scope; |
| 353 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 376 OperationHandle handle = |
| 354 if (!operation) { | 377 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 378 if (!operation_raw) { |
| 355 DidOpenFile(handle, callback, base::File(error), base::Closure()); | 379 DidOpenFile(handle, callback, base::File(error), base::Closure()); |
| 356 return handle.id; | 380 return handle.id; |
| 357 } | 381 } |
| 358 if (file_flags & | 382 if (file_flags & |
| 359 (base::File::FLAG_CREATE | base::File::FLAG_OPEN_ALWAYS | | 383 (base::File::FLAG_CREATE | base::File::FLAG_OPEN_ALWAYS | |
| 360 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED | | 384 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED | |
| 361 base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE | | 385 base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE | |
| 362 base::File::FLAG_DELETE_ON_CLOSE | | 386 base::File::FLAG_DELETE_ON_CLOSE | |
| 363 base::File::FLAG_WRITE_ATTRIBUTES)) { | 387 base::File::FLAG_WRITE_ATTRIBUTES)) { |
| 364 PrepareForWrite(handle.id, url); | 388 PrepareForWrite(handle.id, url); |
| 365 } else { | 389 } else { |
| 366 PrepareForRead(handle.id, url); | 390 PrepareForRead(handle.id, url); |
| 367 } | 391 } |
| 368 operation->OpenFile( | 392 operation_raw->OpenFile( |
| 369 url, file_flags, | 393 url, file_flags, |
| 370 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), | 394 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), |
| 371 handle, callback)); | 395 handle, callback)); |
| 372 return handle.id; | 396 return handle.id; |
| 373 } | 397 } |
| 374 | 398 |
| 375 OperationID FileSystemOperationRunner::CreateSnapshotFile( | 399 OperationID FileSystemOperationRunner::CreateSnapshotFile( |
| 376 const FileSystemURL& url, | 400 const FileSystemURL& url, |
| 377 const SnapshotFileCallback& callback) { | 401 const SnapshotFileCallback& callback) { |
| 378 base::File::Error error = base::File::FILE_OK; | 402 base::File::Error error = base::File::FILE_OK; |
| 379 FileSystemOperation* operation = | 403 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 380 file_system_context_->CreateFileSystemOperation(url, &error); | 404 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 405 FileSystemOperation* operation_raw = operation.get(); |
| 381 BeginOperationScoper scope; | 406 BeginOperationScoper scope; |
| 382 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 407 OperationHandle handle = |
| 383 if (!operation) { | 408 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 409 if (!operation_raw) { |
| 384 DidCreateSnapshot(handle, callback, error, base::File::Info(), | 410 DidCreateSnapshot(handle, callback, error, base::File::Info(), |
| 385 base::FilePath(), NULL); | 411 base::FilePath(), NULL); |
| 386 return handle.id; | 412 return handle.id; |
| 387 } | 413 } |
| 388 PrepareForRead(handle.id, url); | 414 PrepareForRead(handle.id, url); |
| 389 operation->CreateSnapshotFile( | 415 operation_raw->CreateSnapshotFile( |
| 390 url, | 416 url, |
| 391 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(), | 417 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(), |
| 392 handle, callback)); | 418 handle, callback)); |
| 393 return handle.id; | 419 return handle.id; |
| 394 } | 420 } |
| 395 | 421 |
| 396 OperationID FileSystemOperationRunner::CopyInForeignFile( | 422 OperationID FileSystemOperationRunner::CopyInForeignFile( |
| 397 const base::FilePath& src_local_disk_path, | 423 const base::FilePath& src_local_disk_path, |
| 398 const FileSystemURL& dest_url, | 424 const FileSystemURL& dest_url, |
| 399 const StatusCallback& callback) { | 425 const StatusCallback& callback) { |
| 400 base::File::Error error = base::File::FILE_OK; | 426 base::File::Error error = base::File::FILE_OK; |
| 401 FileSystemOperation* operation = | 427 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 402 file_system_context_->CreateFileSystemOperation(dest_url, &error); | 428 file_system_context_->CreateFileSystemOperation(dest_url, &error)); |
| 429 FileSystemOperation* operation_raw = operation.get(); |
| 403 BeginOperationScoper scope; | 430 BeginOperationScoper scope; |
| 404 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 431 OperationHandle handle = |
| 405 if (!operation) { | 432 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 433 if (!operation_raw) { |
| 406 DidFinish(handle, callback, error); | 434 DidFinish(handle, callback, error); |
| 407 return handle.id; | 435 return handle.id; |
| 408 } | 436 } |
| 409 PrepareForWrite(handle.id, dest_url); | 437 PrepareForWrite(handle.id, dest_url); |
| 410 operation->CopyInForeignFile( | 438 operation_raw->CopyInForeignFile( |
| 411 src_local_disk_path, dest_url, | 439 src_local_disk_path, dest_url, |
| 412 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 440 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 413 handle, callback)); | 441 handle, callback)); |
| 414 return handle.id; | 442 return handle.id; |
| 415 } | 443 } |
| 416 | 444 |
| 417 OperationID FileSystemOperationRunner::RemoveFile( | 445 OperationID FileSystemOperationRunner::RemoveFile( |
| 418 const FileSystemURL& url, | 446 const FileSystemURL& url, |
| 419 const StatusCallback& callback) { | 447 const StatusCallback& callback) { |
| 420 base::File::Error error = base::File::FILE_OK; | 448 base::File::Error error = base::File::FILE_OK; |
| 421 FileSystemOperation* operation = | 449 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 422 file_system_context_->CreateFileSystemOperation(url, &error); | 450 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 451 FileSystemOperation* operation_raw = operation.get(); |
| 423 BeginOperationScoper scope; | 452 BeginOperationScoper scope; |
| 424 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 453 OperationHandle handle = |
| 425 if (!operation) { | 454 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 455 if (!operation_raw) { |
| 426 DidFinish(handle, callback, error); | 456 DidFinish(handle, callback, error); |
| 427 return handle.id; | 457 return handle.id; |
| 428 } | 458 } |
| 429 PrepareForWrite(handle.id, url); | 459 PrepareForWrite(handle.id, url); |
| 430 operation->RemoveFile( | 460 operation_raw->RemoveFile( |
| 431 url, | 461 url, |
| 432 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 462 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 433 handle, callback)); | 463 handle, callback)); |
| 434 return handle.id; | 464 return handle.id; |
| 435 } | 465 } |
| 436 | 466 |
| 437 OperationID FileSystemOperationRunner::RemoveDirectory( | 467 OperationID FileSystemOperationRunner::RemoveDirectory( |
| 438 const FileSystemURL& url, | 468 const FileSystemURL& url, |
| 439 const StatusCallback& callback) { | 469 const StatusCallback& callback) { |
| 440 base::File::Error error = base::File::FILE_OK; | 470 base::File::Error error = base::File::FILE_OK; |
| 441 FileSystemOperation* operation = | 471 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 442 file_system_context_->CreateFileSystemOperation(url, &error); | 472 file_system_context_->CreateFileSystemOperation(url, &error)); |
| 473 FileSystemOperation* operation_raw = operation.get(); |
| 443 BeginOperationScoper scope; | 474 BeginOperationScoper scope; |
| 444 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 475 OperationHandle handle = |
| 445 if (!operation) { | 476 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 477 if (!operation_raw) { |
| 446 DidFinish(handle, callback, error); | 478 DidFinish(handle, callback, error); |
| 447 return handle.id; | 479 return handle.id; |
| 448 } | 480 } |
| 449 PrepareForWrite(handle.id, url); | 481 PrepareForWrite(handle.id, url); |
| 450 operation->RemoveDirectory( | 482 operation_raw->RemoveDirectory( |
| 451 url, | 483 url, |
| 452 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 484 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 453 handle, callback)); | 485 handle, callback)); |
| 454 return handle.id; | 486 return handle.id; |
| 455 } | 487 } |
| 456 | 488 |
| 457 OperationID FileSystemOperationRunner::CopyFileLocal( | 489 OperationID FileSystemOperationRunner::CopyFileLocal( |
| 458 const FileSystemURL& src_url, | 490 const FileSystemURL& src_url, |
| 459 const FileSystemURL& dest_url, | 491 const FileSystemURL& dest_url, |
| 460 CopyOrMoveOption option, | 492 CopyOrMoveOption option, |
| 461 const CopyFileProgressCallback& progress_callback, | 493 const CopyFileProgressCallback& progress_callback, |
| 462 const StatusCallback& callback) { | 494 const StatusCallback& callback) { |
| 463 base::File::Error error = base::File::FILE_OK; | 495 base::File::Error error = base::File::FILE_OK; |
| 464 FileSystemOperation* operation = | 496 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 465 file_system_context_->CreateFileSystemOperation(src_url, &error); | 497 file_system_context_->CreateFileSystemOperation(src_url, &error)); |
| 498 FileSystemOperation* operation_raw = operation.get(); |
| 466 BeginOperationScoper scope; | 499 BeginOperationScoper scope; |
| 467 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 500 OperationHandle handle = |
| 468 if (!operation) { | 501 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 502 if (!operation_raw) { |
| 469 DidFinish(handle, callback, error); | 503 DidFinish(handle, callback, error); |
| 470 return handle.id; | 504 return handle.id; |
| 471 } | 505 } |
| 472 PrepareForRead(handle.id, src_url); | 506 PrepareForRead(handle.id, src_url); |
| 473 PrepareForWrite(handle.id, dest_url); | 507 PrepareForWrite(handle.id, dest_url); |
| 474 operation->CopyFileLocal( | 508 operation_raw->CopyFileLocal( |
| 475 src_url, dest_url, option, progress_callback, | 509 src_url, dest_url, option, progress_callback, |
| 476 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 510 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 477 handle, callback)); | 511 handle, callback)); |
| 478 return handle.id; | 512 return handle.id; |
| 479 } | 513 } |
| 480 | 514 |
| 481 OperationID FileSystemOperationRunner::MoveFileLocal( | 515 OperationID FileSystemOperationRunner::MoveFileLocal( |
| 482 const FileSystemURL& src_url, | 516 const FileSystemURL& src_url, |
| 483 const FileSystemURL& dest_url, | 517 const FileSystemURL& dest_url, |
| 484 CopyOrMoveOption option, | 518 CopyOrMoveOption option, |
| 485 const StatusCallback& callback) { | 519 const StatusCallback& callback) { |
| 486 base::File::Error error = base::File::FILE_OK; | 520 base::File::Error error = base::File::FILE_OK; |
| 487 FileSystemOperation* operation = | 521 std::unique_ptr<FileSystemOperation> operation = base::WrapUnique( |
| 488 file_system_context_->CreateFileSystemOperation(src_url, &error); | 522 file_system_context_->CreateFileSystemOperation(src_url, &error)); |
| 523 FileSystemOperation* operation_raw = operation.get(); |
| 489 BeginOperationScoper scope; | 524 BeginOperationScoper scope; |
| 490 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 525 OperationHandle handle = |
| 491 if (!operation) { | 526 BeginOperation(std::move(operation), scope.AsWeakPtr()); |
| 527 if (!operation_raw) { |
| 492 DidFinish(handle, callback, error); | 528 DidFinish(handle, callback, error); |
| 493 return handle.id; | 529 return handle.id; |
| 494 } | 530 } |
| 495 PrepareForWrite(handle.id, src_url); | 531 PrepareForWrite(handle.id, src_url); |
| 496 PrepareForWrite(handle.id, dest_url); | 532 PrepareForWrite(handle.id, dest_url); |
| 497 operation->MoveFileLocal( | 533 operation_raw->MoveFileLocal( |
| 498 src_url, dest_url, option, | 534 src_url, dest_url, option, |
| 499 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 535 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 500 handle, callback)); | 536 handle, callback)); |
| 501 return handle.id; | 537 return handle.id; |
| 502 } | 538 } |
| 503 | 539 |
| 504 base::File::Error FileSystemOperationRunner::SyncGetPlatformPath( | 540 base::File::Error FileSystemOperationRunner::SyncGetPlatformPath( |
| 505 const FileSystemURL& url, | 541 const FileSystemURL& url, |
| 506 base::FilePath* platform_path) { | 542 base::FilePath* platform_path) { |
| 507 base::File::Error error = base::File::FILE_OK; | 543 base::File::Error error = base::File::FILE_OK; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 void FileSystemOperationRunner::PrepareForRead(OperationID id, | 684 void FileSystemOperationRunner::PrepareForRead(OperationID id, |
| 649 const FileSystemURL& url) { | 685 const FileSystemURL& url) { |
| 650 if (file_system_context_->GetAccessObservers(url.type())) { | 686 if (file_system_context_->GetAccessObservers(url.type())) { |
| 651 file_system_context_->GetAccessObservers(url.type())->Notify( | 687 file_system_context_->GetAccessObservers(url.type())->Notify( |
| 652 &FileAccessObserver::OnAccess, std::make_tuple(url)); | 688 &FileAccessObserver::OnAccess, std::make_tuple(url)); |
| 653 } | 689 } |
| 654 } | 690 } |
| 655 | 691 |
| 656 FileSystemOperationRunner::OperationHandle | 692 FileSystemOperationRunner::OperationHandle |
| 657 FileSystemOperationRunner::BeginOperation( | 693 FileSystemOperationRunner::BeginOperation( |
| 658 FileSystemOperation* operation, | 694 std::unique_ptr<FileSystemOperation> operation, |
| 659 base::WeakPtr<BeginOperationScoper> scope) { | 695 base::WeakPtr<BeginOperationScoper> scope) { |
| 660 OperationHandle handle; | 696 OperationHandle handle; |
| 661 handle.id = operations_.Add(operation); | 697 handle.id = operations_.Add(std::move(operation)); |
| 662 handle.scope = scope; | 698 handle.scope = scope; |
| 663 return handle; | 699 return handle; |
| 664 } | 700 } |
| 665 | 701 |
| 666 void FileSystemOperationRunner::FinishOperation(OperationID id) { | 702 void FileSystemOperationRunner::FinishOperation(OperationID id) { |
| 667 OperationToURLSet::iterator found = write_target_urls_.find(id); | 703 OperationToURLSet::iterator found = write_target_urls_.find(id); |
| 668 if (found != write_target_urls_.end()) { | 704 if (found != write_target_urls_.end()) { |
| 669 const FileSystemURLSet& urls = found->second; | 705 const FileSystemURLSet& urls = found->second; |
| 670 for (FileSystemURLSet::const_iterator iter = urls.begin(); | 706 for (FileSystemURLSet::const_iterator iter = urls.begin(); |
| 671 iter != urls.end(); ++iter) { | 707 iter != urls.end(); ++iter) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 688 stray_cancel_callbacks_.find(id); | 724 stray_cancel_callbacks_.find(id); |
| 689 if (found_cancel != stray_cancel_callbacks_.end()) { | 725 if (found_cancel != stray_cancel_callbacks_.end()) { |
| 690 // This cancel has been requested after the operation has finished, | 726 // This cancel has been requested after the operation has finished, |
| 691 // so report that we failed to stop it. | 727 // so report that we failed to stop it. |
| 692 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 728 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 693 stray_cancel_callbacks_.erase(found_cancel); | 729 stray_cancel_callbacks_.erase(found_cancel); |
| 694 } | 730 } |
| 695 } | 731 } |
| 696 | 732 |
| 697 } // namespace storage | 733 } // namespace storage |
| OLD | NEW |