| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "webkit/browser/fileapi/async_file_util_adapter.h" | 5 #include "storage/browser/fileapi/async_file_util_adapter.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "webkit/browser/fileapi/file_system_context.h" | 13 #include "storage/browser/fileapi/file_system_context.h" |
| 14 #include "webkit/browser/fileapi/file_system_file_util.h" | 14 #include "storage/browser/fileapi/file_system_file_util.h" |
| 15 #include "webkit/browser/fileapi/file_system_operation_context.h" | 15 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 16 #include "webkit/browser/fileapi/file_system_url.h" | 16 #include "storage/browser/fileapi/file_system_url.h" |
| 17 #include "webkit/common/blob/shareable_file_reference.h" | 17 #include "storage/common/blob/shareable_file_reference.h" |
| 18 #include "webkit/common/fileapi/file_system_util.h" | 18 #include "storage/common/fileapi/file_system_util.h" |
| 19 | 19 |
| 20 using base::Bind; | 20 using base::Bind; |
| 21 using base::Callback; | 21 using base::Callback; |
| 22 using base::Owned; | 22 using base::Owned; |
| 23 using base::Unretained; | 23 using base::Unretained; |
| 24 using webkit_blob::ShareableFileReference; | 24 using storage::ShareableFileReference; |
| 25 | 25 |
| 26 namespace fileapi { | 26 namespace storage { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 class EnsureFileExistsHelper { | 30 class EnsureFileExistsHelper { |
| 31 public: | 31 public: |
| 32 EnsureFileExistsHelper() : error_(base::File::FILE_OK), created_(false) {} | 32 EnsureFileExistsHelper() : error_(base::File::FILE_OK), created_(false) {} |
| 33 | 33 |
| 34 void RunWork(FileSystemFileUtil* file_util, | 34 void RunWork(FileSystemFileUtil* file_util, |
| 35 FileSystemOperationContext* context, | 35 FileSystemOperationContext* context, |
| 36 const FileSystemURL& url) { | 36 const FileSystemURL& url) { |
| 37 error_ = file_util->EnsureFileExists(context, url, &created_); | 37 error_ = file_util->EnsureFileExists(context, url, &created_); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) { | 40 void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) { |
| 41 callback.Run(error_, created_); | 41 callback.Run(error_, created_); |
| 42 } | 42 } |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 base::File::Error error_; | 45 base::File::Error error_; |
| 46 bool created_; | 46 bool created_; |
| 47 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); | 47 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class GetFileInfoHelper { | 50 class GetFileInfoHelper { |
| 51 public: | 51 public: |
| 52 GetFileInfoHelper() | 52 GetFileInfoHelper() : error_(base::File::FILE_OK) {} |
| 53 : error_(base::File::FILE_OK) {} | |
| 54 | 53 |
| 55 void GetFileInfo(FileSystemFileUtil* file_util, | 54 void GetFileInfo(FileSystemFileUtil* file_util, |
| 56 FileSystemOperationContext* context, | 55 FileSystemOperationContext* context, |
| 57 const FileSystemURL& url) { | 56 const FileSystemURL& url) { |
| 58 error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_); | 57 error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_); |
| 59 } | 58 } |
| 60 | 59 |
| 61 void CreateSnapshotFile(FileSystemFileUtil* file_util, | 60 void CreateSnapshotFile(FileSystemFileUtil* file_util, |
| 62 FileSystemOperationContext* context, | 61 FileSystemOperationContext* context, |
| 63 const FileSystemURL& url) { | 62 const FileSystemURL& url) { |
| 64 scoped_file_ = file_util->CreateSnapshotFile( | 63 scoped_file_ = file_util->CreateSnapshotFile( |
| 65 context, url, &error_, &file_info_, &platform_path_); | 64 context, url, &error_, &file_info_, &platform_path_); |
| 66 } | 65 } |
| 67 | 66 |
| 68 void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) { | 67 void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) { |
| 69 callback.Run(error_, file_info_); | 68 callback.Run(error_, file_info_); |
| 70 } | 69 } |
| 71 | 70 |
| 72 void ReplySnapshotFile( | 71 void ReplySnapshotFile( |
| 73 const AsyncFileUtil::CreateSnapshotFileCallback& callback) { | 72 const AsyncFileUtil::CreateSnapshotFileCallback& callback) { |
| 74 callback.Run(error_, file_info_, platform_path_, | 73 callback.Run(error_, |
| 75 ShareableFileReference::GetOrCreate(scoped_file_.Pass())); | 74 file_info_, |
| 75 platform_path_, |
| 76 ShareableFileReference::GetOrCreate(scoped_file_.Pass())); |
| 76 } | 77 } |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 base::File::Error error_; | 80 base::File::Error error_; |
| 80 base::File::Info file_info_; | 81 base::File::Info file_info_; |
| 81 base::FilePath platform_path_; | 82 base::FilePath platform_path_; |
| 82 webkit_blob::ScopedFile scoped_file_; | 83 storage::ScopedFile scoped_file_; |
| 83 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); | 84 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 void ReadDirectoryHelper(FileSystemFileUtil* file_util, | 87 void ReadDirectoryHelper(FileSystemFileUtil* file_util, |
| 87 FileSystemOperationContext* context, | 88 FileSystemOperationContext* context, |
| 88 const FileSystemURL& url, | 89 const FileSystemURL& url, |
| 89 base::SingleThreadTaskRunner* origin_loop, | 90 base::SingleThreadTaskRunner* origin_loop, |
| 90 const AsyncFileUtil::ReadDirectoryCallback& callback) { | 91 const AsyncFileUtil::ReadDirectoryCallback& callback) { |
| 91 base::File::Info file_info; | 92 base::File::Info file_info; |
| 92 base::FilePath platform_path; | 93 base::FilePath platform_path; |
| 93 base::File::Error error = file_util->GetFileInfo( | 94 base::File::Error error = |
| 94 context, url, &file_info, &platform_path); | 95 file_util->GetFileInfo(context, url, &file_info, &platform_path); |
| 95 | 96 |
| 96 if (error == base::File::FILE_OK && !file_info.is_directory) | 97 if (error == base::File::FILE_OK && !file_info.is_directory) |
| 97 error = base::File::FILE_ERROR_NOT_A_DIRECTORY; | 98 error = base::File::FILE_ERROR_NOT_A_DIRECTORY; |
| 98 | 99 |
| 99 std::vector<DirectoryEntry> entries; | 100 std::vector<DirectoryEntry> entries; |
| 100 if (error != base::File::FILE_OK) { | 101 if (error != base::File::FILE_OK) { |
| 101 origin_loop->PostTask( | 102 origin_loop->PostTask( |
| 102 FROM_HERE, base::Bind(callback, error, entries, false /* has_more */)); | 103 FROM_HERE, base::Bind(callback, error, entries, false /* has_more */)); |
| 103 return; | 104 return; |
| 104 } | 105 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 while (!(current = file_enum->Next()).empty()) { | 116 while (!(current = file_enum->Next()).empty()) { |
| 116 DirectoryEntry entry; | 117 DirectoryEntry entry; |
| 117 entry.is_directory = file_enum->IsDirectory(); | 118 entry.is_directory = file_enum->IsDirectory(); |
| 118 entry.name = VirtualPath::BaseName(current).value(); | 119 entry.name = VirtualPath::BaseName(current).value(); |
| 119 entry.size = file_enum->Size(); | 120 entry.size = file_enum->Size(); |
| 120 entry.last_modified_time = file_enum->LastModifiedTime(); | 121 entry.last_modified_time = file_enum->LastModifiedTime(); |
| 121 entries.push_back(entry); | 122 entries.push_back(entry); |
| 122 | 123 |
| 123 if (entries.size() == kResultChunkSize) { | 124 if (entries.size() == kResultChunkSize) { |
| 124 origin_loop->PostTask( | 125 origin_loop->PostTask( |
| 125 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries, | 126 FROM_HERE, |
| 126 true /* has_more */)); | 127 base::Bind( |
| 128 callback, base::File::FILE_OK, entries, true /* has_more */)); |
| 127 entries.clear(); | 129 entries.clear(); |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 origin_loop->PostTask( | 132 origin_loop->PostTask( |
| 131 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries, | 133 FROM_HERE, |
| 132 false /* has_more */)); | 134 base::Bind(callback, base::File::FILE_OK, entries, false /* has_more */)); |
| 133 } | 135 } |
| 134 | 136 |
| 135 void RunCreateOrOpenCallback( | 137 void RunCreateOrOpenCallback( |
| 136 FileSystemOperationContext* context, | 138 FileSystemOperationContext* context, |
| 137 const AsyncFileUtil::CreateOrOpenCallback& callback, | 139 const AsyncFileUtil::CreateOrOpenCallback& callback, |
| 138 base::File file) { | 140 base::File file) { |
| 139 callback.Run(file.Pass(), base::Closure()); | 141 callback.Run(file.Pass(), base::Closure()); |
| 140 } | 142 } |
| 141 | 143 |
| 142 } // namespace | 144 } // namespace |
| 143 | 145 |
| 144 AsyncFileUtilAdapter::AsyncFileUtilAdapter( | 146 AsyncFileUtilAdapter::AsyncFileUtilAdapter(FileSystemFileUtil* sync_file_util) |
| 145 FileSystemFileUtil* sync_file_util) | |
| 146 : sync_file_util_(sync_file_util) { | 147 : sync_file_util_(sync_file_util) { |
| 147 DCHECK(sync_file_util_.get()); | 148 DCHECK(sync_file_util_.get()); |
| 148 } | 149 } |
| 149 | 150 |
| 150 AsyncFileUtilAdapter::~AsyncFileUtilAdapter() { | 151 AsyncFileUtilAdapter::~AsyncFileUtilAdapter() { |
| 151 } | 152 } |
| 152 | 153 |
| 153 void AsyncFileUtilAdapter::CreateOrOpen( | 154 void AsyncFileUtilAdapter::CreateOrOpen( |
| 154 scoped_ptr<FileSystemOperationContext> context, | 155 scoped_ptr<FileSystemOperationContext> context, |
| 155 const FileSystemURL& url, | 156 const FileSystemURL& url, |
| 156 int file_flags, | 157 int file_flags, |
| 157 const CreateOrOpenCallback& callback) { | 158 const CreateOrOpenCallback& callback) { |
| 158 FileSystemOperationContext* context_ptr = context.release(); | 159 FileSystemOperationContext* context_ptr = context.release(); |
| 159 base::PostTaskAndReplyWithResult( | 160 base::PostTaskAndReplyWithResult( |
| 160 context_ptr->task_runner(), | 161 context_ptr->task_runner(), |
| 161 FROM_HERE, | 162 FROM_HERE, |
| 162 Bind(&FileSystemFileUtil::CreateOrOpen, Unretained(sync_file_util_.get()), | 163 Bind(&FileSystemFileUtil::CreateOrOpen, |
| 163 context_ptr, url, file_flags), | 164 Unretained(sync_file_util_.get()), |
| 165 context_ptr, |
| 166 url, |
| 167 file_flags), |
| 164 Bind(&RunCreateOrOpenCallback, base::Owned(context_ptr), callback)); | 168 Bind(&RunCreateOrOpenCallback, base::Owned(context_ptr), callback)); |
| 165 } | 169 } |
| 166 | 170 |
| 167 void AsyncFileUtilAdapter::EnsureFileExists( | 171 void AsyncFileUtilAdapter::EnsureFileExists( |
| 168 scoped_ptr<FileSystemOperationContext> context, | 172 scoped_ptr<FileSystemOperationContext> context, |
| 169 const FileSystemURL& url, | 173 const FileSystemURL& url, |
| 170 const EnsureFileExistsCallback& callback) { | 174 const EnsureFileExistsCallback& callback) { |
| 171 EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; | 175 EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; |
| 172 FileSystemOperationContext* context_ptr = context.release(); | 176 FileSystemOperationContext* context_ptr = context.release(); |
| 173 const bool success = context_ptr->task_runner()->PostTaskAndReply( | 177 const bool success = context_ptr->task_runner()->PostTaskAndReply( |
| 174 FROM_HERE, | 178 FROM_HERE, |
| 175 Bind(&EnsureFileExistsHelper::RunWork, Unretained(helper), | 179 Bind(&EnsureFileExistsHelper::RunWork, |
| 176 sync_file_util_.get(), base::Owned(context_ptr), url), | 180 Unretained(helper), |
| 181 sync_file_util_.get(), |
| 182 base::Owned(context_ptr), |
| 183 url), |
| 177 Bind(&EnsureFileExistsHelper::Reply, Owned(helper), callback)); | 184 Bind(&EnsureFileExistsHelper::Reply, Owned(helper), callback)); |
| 178 DCHECK(success); | 185 DCHECK(success); |
| 179 } | 186 } |
| 180 | 187 |
| 181 void AsyncFileUtilAdapter::CreateDirectory( | 188 void AsyncFileUtilAdapter::CreateDirectory( |
| 182 scoped_ptr<FileSystemOperationContext> context, | 189 scoped_ptr<FileSystemOperationContext> context, |
| 183 const FileSystemURL& url, | 190 const FileSystemURL& url, |
| 184 bool exclusive, | 191 bool exclusive, |
| 185 bool recursive, | 192 bool recursive, |
| 186 const StatusCallback& callback) { | 193 const StatusCallback& callback) { |
| 187 FileSystemOperationContext* context_ptr = context.release(); | 194 FileSystemOperationContext* context_ptr = context.release(); |
| 188 const bool success = base::PostTaskAndReplyWithResult( | 195 const bool success = base::PostTaskAndReplyWithResult( |
| 189 context_ptr->task_runner(), FROM_HERE, | 196 context_ptr->task_runner(), |
| 197 FROM_HERE, |
| 190 Bind(&FileSystemFileUtil::CreateDirectory, | 198 Bind(&FileSystemFileUtil::CreateDirectory, |
| 191 Unretained(sync_file_util_.get()), | 199 Unretained(sync_file_util_.get()), |
| 192 base::Owned(context_ptr), url, exclusive, recursive), | 200 base::Owned(context_ptr), |
| 201 url, |
| 202 exclusive, |
| 203 recursive), |
| 193 callback); | 204 callback); |
| 194 DCHECK(success); | 205 DCHECK(success); |
| 195 } | 206 } |
| 196 | 207 |
| 197 void AsyncFileUtilAdapter::GetFileInfo( | 208 void AsyncFileUtilAdapter::GetFileInfo( |
| 198 scoped_ptr<FileSystemOperationContext> context, | 209 scoped_ptr<FileSystemOperationContext> context, |
| 199 const FileSystemURL& url, | 210 const FileSystemURL& url, |
| 200 const GetFileInfoCallback& callback) { | 211 const GetFileInfoCallback& callback) { |
| 201 FileSystemOperationContext* context_ptr = context.release(); | 212 FileSystemOperationContext* context_ptr = context.release(); |
| 202 GetFileInfoHelper* helper = new GetFileInfoHelper; | 213 GetFileInfoHelper* helper = new GetFileInfoHelper; |
| 203 const bool success = context_ptr->task_runner()->PostTaskAndReply( | 214 const bool success = context_ptr->task_runner()->PostTaskAndReply( |
| 204 FROM_HERE, | 215 FROM_HERE, |
| 205 Bind(&GetFileInfoHelper::GetFileInfo, Unretained(helper), | 216 Bind(&GetFileInfoHelper::GetFileInfo, |
| 206 sync_file_util_.get(), base::Owned(context_ptr), url), | 217 Unretained(helper), |
| 218 sync_file_util_.get(), |
| 219 base::Owned(context_ptr), |
| 220 url), |
| 207 Bind(&GetFileInfoHelper::ReplyFileInfo, Owned(helper), callback)); | 221 Bind(&GetFileInfoHelper::ReplyFileInfo, Owned(helper), callback)); |
| 208 DCHECK(success); | 222 DCHECK(success); |
| 209 } | 223 } |
| 210 | 224 |
| 211 void AsyncFileUtilAdapter::ReadDirectory( | 225 void AsyncFileUtilAdapter::ReadDirectory( |
| 212 scoped_ptr<FileSystemOperationContext> context, | 226 scoped_ptr<FileSystemOperationContext> context, |
| 213 const FileSystemURL& url, | 227 const FileSystemURL& url, |
| 214 const ReadDirectoryCallback& callback) { | 228 const ReadDirectoryCallback& callback) { |
| 215 FileSystemOperationContext* context_ptr = context.release(); | 229 FileSystemOperationContext* context_ptr = context.release(); |
| 216 const bool success = context_ptr->task_runner()->PostTask( | 230 const bool success = context_ptr->task_runner()->PostTask( |
| 217 FROM_HERE, | 231 FROM_HERE, |
| 218 Bind(&ReadDirectoryHelper, | 232 Bind(&ReadDirectoryHelper, |
| 219 sync_file_util_.get(), base::Owned(context_ptr), url, | 233 sync_file_util_.get(), |
| 220 base::ThreadTaskRunnerHandle::Get(), callback)); | 234 base::Owned(context_ptr), |
| 235 url, |
| 236 base::ThreadTaskRunnerHandle::Get(), |
| 237 callback)); |
| 221 DCHECK(success); | 238 DCHECK(success); |
| 222 } | 239 } |
| 223 | 240 |
| 224 void AsyncFileUtilAdapter::Touch( | 241 void AsyncFileUtilAdapter::Touch(scoped_ptr<FileSystemOperationContext> context, |
| 225 scoped_ptr<FileSystemOperationContext> context, | 242 const FileSystemURL& url, |
| 226 const FileSystemURL& url, | 243 const base::Time& last_access_time, |
| 227 const base::Time& last_access_time, | 244 const base::Time& last_modified_time, |
| 228 const base::Time& last_modified_time, | 245 const StatusCallback& callback) { |
| 229 const StatusCallback& callback) { | |
| 230 FileSystemOperationContext* context_ptr = context.release(); | 246 FileSystemOperationContext* context_ptr = context.release(); |
| 231 const bool success = base::PostTaskAndReplyWithResult( | 247 const bool success = |
| 232 context_ptr->task_runner(), FROM_HERE, | 248 base::PostTaskAndReplyWithResult(context_ptr->task_runner(), |
| 233 Bind(&FileSystemFileUtil::Touch, Unretained(sync_file_util_.get()), | 249 FROM_HERE, |
| 234 base::Owned(context_ptr), url, | 250 Bind(&FileSystemFileUtil::Touch, |
| 235 last_access_time, last_modified_time), | 251 Unretained(sync_file_util_.get()), |
| 236 callback); | 252 base::Owned(context_ptr), |
| 253 url, |
| 254 last_access_time, |
| 255 last_modified_time), |
| 256 callback); |
| 237 DCHECK(success); | 257 DCHECK(success); |
| 238 } | 258 } |
| 239 | 259 |
| 240 void AsyncFileUtilAdapter::Truncate( | 260 void AsyncFileUtilAdapter::Truncate( |
| 241 scoped_ptr<FileSystemOperationContext> context, | 261 scoped_ptr<FileSystemOperationContext> context, |
| 242 const FileSystemURL& url, | 262 const FileSystemURL& url, |
| 243 int64 length, | 263 int64 length, |
| 244 const StatusCallback& callback) { | 264 const StatusCallback& callback) { |
| 245 FileSystemOperationContext* context_ptr = context.release(); | 265 FileSystemOperationContext* context_ptr = context.release(); |
| 246 const bool success = base::PostTaskAndReplyWithResult( | 266 const bool success = |
| 247 context_ptr->task_runner(), FROM_HERE, | 267 base::PostTaskAndReplyWithResult(context_ptr->task_runner(), |
| 248 Bind(&FileSystemFileUtil::Truncate, Unretained(sync_file_util_.get()), | 268 FROM_HERE, |
| 249 base::Owned(context_ptr), url, length), | 269 Bind(&FileSystemFileUtil::Truncate, |
| 250 callback); | 270 Unretained(sync_file_util_.get()), |
| 271 base::Owned(context_ptr), |
| 272 url, |
| 273 length), |
| 274 callback); |
| 251 DCHECK(success); | 275 DCHECK(success); |
| 252 } | 276 } |
| 253 | 277 |
| 254 void AsyncFileUtilAdapter::CopyFileLocal( | 278 void AsyncFileUtilAdapter::CopyFileLocal( |
| 255 scoped_ptr<FileSystemOperationContext> context, | 279 scoped_ptr<FileSystemOperationContext> context, |
| 256 const FileSystemURL& src_url, | 280 const FileSystemURL& src_url, |
| 257 const FileSystemURL& dest_url, | 281 const FileSystemURL& dest_url, |
| 258 CopyOrMoveOption option, | 282 CopyOrMoveOption option, |
| 259 const CopyFileProgressCallback& progress_callback, | 283 const CopyFileProgressCallback& progress_callback, |
| 260 const StatusCallback& callback) { | 284 const StatusCallback& callback) { |
| 261 // TODO(hidehiko): Support progress_callback. | 285 // TODO(hidehiko): Support progress_callback. |
| 262 FileSystemOperationContext* context_ptr = context.release(); | 286 FileSystemOperationContext* context_ptr = context.release(); |
| 263 const bool success = base::PostTaskAndReplyWithResult( | 287 const bool success = |
| 264 context_ptr->task_runner(), FROM_HERE, | 288 base::PostTaskAndReplyWithResult(context_ptr->task_runner(), |
| 265 Bind(&FileSystemFileUtil::CopyOrMoveFile, | 289 FROM_HERE, |
| 266 Unretained(sync_file_util_.get()), base::Owned(context_ptr), | 290 Bind(&FileSystemFileUtil::CopyOrMoveFile, |
| 267 src_url, dest_url, option, true /* copy */), | 291 Unretained(sync_file_util_.get()), |
| 268 callback); | 292 base::Owned(context_ptr), |
| 293 src_url, |
| 294 dest_url, |
| 295 option, |
| 296 true /* copy */), |
| 297 callback); |
| 269 DCHECK(success); | 298 DCHECK(success); |
| 270 } | 299 } |
| 271 | 300 |
| 272 void AsyncFileUtilAdapter::MoveFileLocal( | 301 void AsyncFileUtilAdapter::MoveFileLocal( |
| 273 scoped_ptr<FileSystemOperationContext> context, | 302 scoped_ptr<FileSystemOperationContext> context, |
| 274 const FileSystemURL& src_url, | 303 const FileSystemURL& src_url, |
| 275 const FileSystemURL& dest_url, | 304 const FileSystemURL& dest_url, |
| 276 CopyOrMoveOption option, | 305 CopyOrMoveOption option, |
| 277 const StatusCallback& callback) { | 306 const StatusCallback& callback) { |
| 278 FileSystemOperationContext* context_ptr = context.release(); | 307 FileSystemOperationContext* context_ptr = context.release(); |
| 279 const bool success = base::PostTaskAndReplyWithResult( | 308 const bool success = |
| 280 context_ptr->task_runner(), FROM_HERE, | 309 base::PostTaskAndReplyWithResult(context_ptr->task_runner(), |
| 281 Bind(&FileSystemFileUtil::CopyOrMoveFile, | 310 FROM_HERE, |
| 282 Unretained(sync_file_util_.get()), base::Owned(context_ptr), | 311 Bind(&FileSystemFileUtil::CopyOrMoveFile, |
| 283 src_url, dest_url, option, false /* copy */), | 312 Unretained(sync_file_util_.get()), |
| 284 callback); | 313 base::Owned(context_ptr), |
| 314 src_url, |
| 315 dest_url, |
| 316 option, |
| 317 false /* copy */), |
| 318 callback); |
| 285 DCHECK(success); | 319 DCHECK(success); |
| 286 } | 320 } |
| 287 | 321 |
| 288 void AsyncFileUtilAdapter::CopyInForeignFile( | 322 void AsyncFileUtilAdapter::CopyInForeignFile( |
| 289 scoped_ptr<FileSystemOperationContext> context, | 323 scoped_ptr<FileSystemOperationContext> context, |
| 290 const base::FilePath& src_file_path, | 324 const base::FilePath& src_file_path, |
| 291 const FileSystemURL& dest_url, | 325 const FileSystemURL& dest_url, |
| 292 const StatusCallback& callback) { | 326 const StatusCallback& callback) { |
| 293 FileSystemOperationContext* context_ptr = context.release(); | 327 FileSystemOperationContext* context_ptr = context.release(); |
| 294 const bool success = base::PostTaskAndReplyWithResult( | 328 const bool success = base::PostTaskAndReplyWithResult( |
| 295 context_ptr->task_runner(), FROM_HERE, | 329 context_ptr->task_runner(), |
| 330 FROM_HERE, |
| 296 Bind(&FileSystemFileUtil::CopyInForeignFile, | 331 Bind(&FileSystemFileUtil::CopyInForeignFile, |
| 297 Unretained(sync_file_util_.get()), | 332 Unretained(sync_file_util_.get()), |
| 298 base::Owned(context_ptr), src_file_path, dest_url), | 333 base::Owned(context_ptr), |
| 334 src_file_path, |
| 335 dest_url), |
| 299 callback); | 336 callback); |
| 300 DCHECK(success); | 337 DCHECK(success); |
| 301 } | 338 } |
| 302 | 339 |
| 303 void AsyncFileUtilAdapter::DeleteFile( | 340 void AsyncFileUtilAdapter::DeleteFile( |
| 304 scoped_ptr<FileSystemOperationContext> context, | 341 scoped_ptr<FileSystemOperationContext> context, |
| 305 const FileSystemURL& url, | 342 const FileSystemURL& url, |
| 306 const StatusCallback& callback) { | 343 const StatusCallback& callback) { |
| 307 FileSystemOperationContext* context_ptr = context.release(); | 344 FileSystemOperationContext* context_ptr = context.release(); |
| 308 const bool success = base::PostTaskAndReplyWithResult( | 345 const bool success = |
| 309 context_ptr->task_runner(), FROM_HERE, | 346 base::PostTaskAndReplyWithResult(context_ptr->task_runner(), |
| 310 Bind(&FileSystemFileUtil::DeleteFile, | 347 FROM_HERE, |
| 311 Unretained(sync_file_util_.get()), | 348 Bind(&FileSystemFileUtil::DeleteFile, |
| 312 base::Owned(context_ptr), url), | 349 Unretained(sync_file_util_.get()), |
| 313 callback); | 350 base::Owned(context_ptr), |
| 351 url), |
| 352 callback); |
| 314 DCHECK(success); | 353 DCHECK(success); |
| 315 } | 354 } |
| 316 | 355 |
| 317 void AsyncFileUtilAdapter::DeleteDirectory( | 356 void AsyncFileUtilAdapter::DeleteDirectory( |
| 318 scoped_ptr<FileSystemOperationContext> context, | 357 scoped_ptr<FileSystemOperationContext> context, |
| 319 const FileSystemURL& url, | 358 const FileSystemURL& url, |
| 320 const StatusCallback& callback) { | 359 const StatusCallback& callback) { |
| 321 FileSystemOperationContext* context_ptr = context.release(); | 360 FileSystemOperationContext* context_ptr = context.release(); |
| 322 const bool success = base::PostTaskAndReplyWithResult( | 361 const bool success = base::PostTaskAndReplyWithResult( |
| 323 context_ptr->task_runner(), FROM_HERE, | 362 context_ptr->task_runner(), |
| 363 FROM_HERE, |
| 324 Bind(&FileSystemFileUtil::DeleteDirectory, | 364 Bind(&FileSystemFileUtil::DeleteDirectory, |
| 325 Unretained(sync_file_util_.get()), | 365 Unretained(sync_file_util_.get()), |
| 326 base::Owned(context_ptr), url), | 366 base::Owned(context_ptr), |
| 367 url), |
| 327 callback); | 368 callback); |
| 328 DCHECK(success); | 369 DCHECK(success); |
| 329 } | 370 } |
| 330 | 371 |
| 331 void AsyncFileUtilAdapter::DeleteRecursively( | 372 void AsyncFileUtilAdapter::DeleteRecursively( |
| 332 scoped_ptr<FileSystemOperationContext> context, | 373 scoped_ptr<FileSystemOperationContext> context, |
| 333 const FileSystemURL& url, | 374 const FileSystemURL& url, |
| 334 const StatusCallback& callback) { | 375 const StatusCallback& callback) { |
| 335 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 376 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 336 } | 377 } |
| 337 | 378 |
| 338 void AsyncFileUtilAdapter::CreateSnapshotFile( | 379 void AsyncFileUtilAdapter::CreateSnapshotFile( |
| 339 scoped_ptr<FileSystemOperationContext> context, | 380 scoped_ptr<FileSystemOperationContext> context, |
| 340 const FileSystemURL& url, | 381 const FileSystemURL& url, |
| 341 const CreateSnapshotFileCallback& callback) { | 382 const CreateSnapshotFileCallback& callback) { |
| 342 FileSystemOperationContext* context_ptr = context.release(); | 383 FileSystemOperationContext* context_ptr = context.release(); |
| 343 GetFileInfoHelper* helper = new GetFileInfoHelper; | 384 GetFileInfoHelper* helper = new GetFileInfoHelper; |
| 344 const bool success = context_ptr->task_runner()->PostTaskAndReply( | 385 const bool success = context_ptr->task_runner()->PostTaskAndReply( |
| 345 FROM_HERE, | 386 FROM_HERE, |
| 346 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), | 387 Bind(&GetFileInfoHelper::CreateSnapshotFile, |
| 347 sync_file_util_.get(), base::Owned(context_ptr), url), | 388 Unretained(helper), |
| 389 sync_file_util_.get(), |
| 390 base::Owned(context_ptr), |
| 391 url), |
| 348 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); | 392 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); |
| 349 DCHECK(success); | 393 DCHECK(success); |
| 350 } | 394 } |
| 351 | 395 |
| 352 } // namespace fileapi | 396 } // namespace storage |
| OLD | NEW |