| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "storage/browser/blob/shareable_file_reference.h" | 15 #include "storage/browser/blob/shareable_file_reference.h" |
| 15 #include "storage/browser/fileapi/file_system_operation_context.h" | 16 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 16 #include "storage/browser/fileapi/file_system_url.h" | 17 #include "storage/browser/fileapi/file_system_url.h" |
| 17 | 18 |
| 18 using content::BrowserThread; | 19 using content::BrowserThread; |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 namespace file_system_provider { | 22 namespace file_system_provider { |
| 22 namespace internal { | 23 namespace internal { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Executes GetFileInfo on the UI thread. | 26 // Executes GetFileInfo on the UI thread. |
| 26 void GetFileInfoOnUIThread( | 27 void GetFileInfoOnUIThread( |
| 27 scoped_ptr<storage::FileSystemOperationContext> context, | 28 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 28 const storage::FileSystemURL& url, | 29 const storage::FileSystemURL& url, |
| 29 int fields, | 30 int fields, |
| 30 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { | 31 const ProvidedFileSystemInterface::GetMetadataCallback& callback) { |
| 31 util::FileSystemURLParser parser(url); | 32 util::FileSystemURLParser parser(url); |
| 32 if (!parser.Parse()) { | 33 if (!parser.Parse()) { |
| 33 callback.Run(make_scoped_ptr<EntryMetadata>(NULL), | 34 callback.Run(base::WrapUnique<EntryMetadata>(NULL), |
| 34 base::File::FILE_ERROR_INVALID_OPERATION); | 35 base::File::FILE_ERROR_INVALID_OPERATION); |
| 35 return; | 36 return; |
| 36 } | 37 } |
| 37 | 38 |
| 38 int fsp_fields = 0; | 39 int fsp_fields = 0; |
| 39 if (fields & storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY) | 40 if (fields & storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY) |
| 40 fsp_fields |= ProvidedFileSystemInterface::METADATA_FIELD_IS_DIRECTORY; | 41 fsp_fields |= ProvidedFileSystemInterface::METADATA_FIELD_IS_DIRECTORY; |
| 41 if (fields & storage::FileSystemOperation::GET_METADATA_FIELD_SIZE) | 42 if (fields & storage::FileSystemOperation::GET_METADATA_FIELD_SIZE) |
| 42 fsp_fields |= ProvidedFileSystemInterface::METADATA_FIELD_SIZE; | 43 fsp_fields |= ProvidedFileSystemInterface::METADATA_FIELD_SIZE; |
| 43 if (fields & storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED) | 44 if (fields & storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED) |
| 44 fsp_fields |= ProvidedFileSystemInterface::METADATA_FIELD_MODIFICATION_TIME; | 45 fsp_fields |= ProvidedFileSystemInterface::METADATA_FIELD_MODIFICATION_TIME; |
| 45 | 46 |
| 46 parser.file_system()->GetMetadata(parser.file_path(), fsp_fields, callback); | 47 parser.file_system()->GetMetadata(parser.file_path(), fsp_fields, callback); |
| 47 } | 48 } |
| 48 | 49 |
| 49 // Routes the response of GetFileInfo back to the IO thread with a type | 50 // Routes the response of GetFileInfo back to the IO thread with a type |
| 50 // conversion. | 51 // conversion. |
| 51 void OnGetFileInfo(int fields, | 52 void OnGetFileInfo(int fields, |
| 52 const storage::AsyncFileUtil::GetFileInfoCallback& callback, | 53 const storage::AsyncFileUtil::GetFileInfoCallback& callback, |
| 53 scoped_ptr<EntryMetadata> metadata, | 54 std::unique_ptr<EntryMetadata> metadata, |
| 54 base::File::Error result) { | 55 base::File::Error result) { |
| 55 if (result != base::File::FILE_OK) { | 56 if (result != base::File::FILE_OK) { |
| 56 BrowserThread::PostTask(BrowserThread::IO, | 57 BrowserThread::PostTask(BrowserThread::IO, |
| 57 FROM_HERE, | 58 FROM_HERE, |
| 58 base::Bind(callback, result, base::File::Info())); | 59 base::Bind(callback, result, base::File::Info())); |
| 59 return; | 60 return; |
| 60 } | 61 } |
| 61 | 62 |
| 62 DCHECK(metadata.get()); | 63 DCHECK(metadata.get()); |
| 63 base::File::Info file_info; | 64 base::File::Info file_info; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 77 | 78 |
| 78 file_info.is_symbolic_link = false; // Not supported. | 79 file_info.is_symbolic_link = false; // Not supported. |
| 79 | 80 |
| 80 BrowserThread::PostTask(BrowserThread::IO, | 81 BrowserThread::PostTask(BrowserThread::IO, |
| 81 FROM_HERE, | 82 FROM_HERE, |
| 82 base::Bind(callback, base::File::FILE_OK, file_info)); | 83 base::Bind(callback, base::File::FILE_OK, file_info)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Executes ReadDirectory on the UI thread. | 86 // Executes ReadDirectory on the UI thread. |
| 86 void ReadDirectoryOnUIThread( | 87 void ReadDirectoryOnUIThread( |
| 87 scoped_ptr<storage::FileSystemOperationContext> context, | 88 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 88 const storage::FileSystemURL& url, | 89 const storage::FileSystemURL& url, |
| 89 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { | 90 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { |
| 90 util::FileSystemURLParser parser(url); | 91 util::FileSystemURLParser parser(url); |
| 91 if (!parser.Parse()) { | 92 if (!parser.Parse()) { |
| 92 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 93 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
| 93 storage::AsyncFileUtil::EntryList(), | 94 storage::AsyncFileUtil::EntryList(), |
| 94 false /* has_more */); | 95 false /* has_more */); |
| 95 return; | 96 return; |
| 96 } | 97 } |
| 97 | 98 |
| 98 parser.file_system()->ReadDirectory(parser.file_path(), callback); | 99 parser.file_system()->ReadDirectory(parser.file_path(), callback); |
| 99 } | 100 } |
| 100 | 101 |
| 101 // Routes the response of ReadDirectory back to the IO thread. | 102 // Routes the response of ReadDirectory back to the IO thread. |
| 102 void OnReadDirectory( | 103 void OnReadDirectory( |
| 103 const storage::AsyncFileUtil::ReadDirectoryCallback& callback, | 104 const storage::AsyncFileUtil::ReadDirectoryCallback& callback, |
| 104 base::File::Error result, | 105 base::File::Error result, |
| 105 const storage::AsyncFileUtil::EntryList& entry_list, | 106 const storage::AsyncFileUtil::EntryList& entry_list, |
| 106 bool has_more) { | 107 bool has_more) { |
| 107 BrowserThread::PostTask(BrowserThread::IO, | 108 BrowserThread::PostTask(BrowserThread::IO, |
| 108 FROM_HERE, | 109 FROM_HERE, |
| 109 base::Bind(callback, result, entry_list, has_more)); | 110 base::Bind(callback, result, entry_list, has_more)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 // Executes CreateDirectory on the UI thread. | 113 // Executes CreateDirectory on the UI thread. |
| 113 void CreateDirectoryOnUIThread( | 114 void CreateDirectoryOnUIThread( |
| 114 scoped_ptr<storage::FileSystemOperationContext> context, | 115 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 115 const storage::FileSystemURL& url, | 116 const storage::FileSystemURL& url, |
| 116 bool exclusive, | 117 bool exclusive, |
| 117 bool recursive, | 118 bool recursive, |
| 118 const storage::AsyncFileUtil::StatusCallback& callback) { | 119 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 119 util::FileSystemURLParser parser(url); | 120 util::FileSystemURLParser parser(url); |
| 120 if (!parser.Parse()) { | 121 if (!parser.Parse()) { |
| 121 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 122 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 122 return; | 123 return; |
| 123 } | 124 } |
| 124 | 125 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 (result == base::File::FILE_ERROR_EXISTS && !exclusive) | 137 (result == base::File::FILE_ERROR_EXISTS && !exclusive) |
| 137 ? base::File::FILE_OK | 138 ? base::File::FILE_OK |
| 138 : result; | 139 : result; |
| 139 | 140 |
| 140 BrowserThread::PostTask( | 141 BrowserThread::PostTask( |
| 141 BrowserThread::IO, FROM_HERE, base::Bind(callback, error)); | 142 BrowserThread::IO, FROM_HERE, base::Bind(callback, error)); |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Executes DeleteEntry on the UI thread. | 145 // Executes DeleteEntry on the UI thread. |
| 145 void DeleteEntryOnUIThread( | 146 void DeleteEntryOnUIThread( |
| 146 scoped_ptr<storage::FileSystemOperationContext> context, | 147 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 147 const storage::FileSystemURL& url, | 148 const storage::FileSystemURL& url, |
| 148 bool recursive, | 149 bool recursive, |
| 149 const storage::AsyncFileUtil::StatusCallback& callback) { | 150 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 150 util::FileSystemURLParser parser(url); | 151 util::FileSystemURLParser parser(url); |
| 151 if (!parser.Parse()) { | 152 if (!parser.Parse()) { |
| 152 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 153 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 153 return; | 154 return; |
| 154 } | 155 } |
| 155 | 156 |
| 156 parser.file_system()->DeleteEntry(parser.file_path(), recursive, callback); | 157 parser.file_system()->DeleteEntry(parser.file_path(), recursive, callback); |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Routes the response of DeleteEntry back to the IO thread. | 160 // Routes the response of DeleteEntry back to the IO thread. |
| 160 void OnDeleteEntry(const storage::AsyncFileUtil::StatusCallback& callback, | 161 void OnDeleteEntry(const storage::AsyncFileUtil::StatusCallback& callback, |
| 161 base::File::Error result) { | 162 base::File::Error result) { |
| 162 BrowserThread::PostTask( | 163 BrowserThread::PostTask( |
| 163 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 164 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Executes CreateFile on the UI thread. | 167 // Executes CreateFile on the UI thread. |
| 167 void CreateFileOnUIThread( | 168 void CreateFileOnUIThread( |
| 168 scoped_ptr<storage::FileSystemOperationContext> context, | 169 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 169 const storage::FileSystemURL& url, | 170 const storage::FileSystemURL& url, |
| 170 const storage::AsyncFileUtil::StatusCallback& callback) { | 171 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 171 util::FileSystemURLParser parser(url); | 172 util::FileSystemURLParser parser(url); |
| 172 if (!parser.Parse()) { | 173 if (!parser.Parse()) { |
| 173 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 174 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 174 return; | 175 return; |
| 175 } | 176 } |
| 176 | 177 |
| 177 parser.file_system()->CreateFile(parser.file_path(), callback); | 178 parser.file_system()->CreateFile(parser.file_path(), callback); |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Routes the response of CreateFile to a callback of EnsureFileExists() on the | 181 // Routes the response of CreateFile to a callback of EnsureFileExists() on the |
| 181 // IO thread. | 182 // IO thread. |
| 182 void OnCreateFileForEnsureFileExists( | 183 void OnCreateFileForEnsureFileExists( |
| 183 const storage::AsyncFileUtil::EnsureFileExistsCallback& callback, | 184 const storage::AsyncFileUtil::EnsureFileExistsCallback& callback, |
| 184 base::File::Error result) { | 185 base::File::Error result) { |
| 185 const bool created = result == base::File::FILE_OK; | 186 const bool created = result == base::File::FILE_OK; |
| 186 | 187 |
| 187 // If the file already existed, then return success anyway, since it is not | 188 // If the file already existed, then return success anyway, since it is not |
| 188 // an error. | 189 // an error. |
| 189 const base::File::Error error = | 190 const base::File::Error error = |
| 190 result == base::File::FILE_ERROR_EXISTS ? base::File::FILE_OK : result; | 191 result == base::File::FILE_ERROR_EXISTS ? base::File::FILE_OK : result; |
| 191 | 192 |
| 192 BrowserThread::PostTask( | 193 BrowserThread::PostTask( |
| 193 BrowserThread::IO, FROM_HERE, base::Bind(callback, error, created)); | 194 BrowserThread::IO, FROM_HERE, base::Bind(callback, error, created)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Executes CopyEntry on the UI thread. | 197 // Executes CopyEntry on the UI thread. |
| 197 void CopyEntryOnUIThread( | 198 void CopyEntryOnUIThread( |
| 198 scoped_ptr<storage::FileSystemOperationContext> context, | 199 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 199 const storage::FileSystemURL& source_url, | 200 const storage::FileSystemURL& source_url, |
| 200 const storage::FileSystemURL& target_url, | 201 const storage::FileSystemURL& target_url, |
| 201 const storage::AsyncFileUtil::StatusCallback& callback) { | 202 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 202 util::FileSystemURLParser source_parser(source_url); | 203 util::FileSystemURLParser source_parser(source_url); |
| 203 util::FileSystemURLParser target_parser(target_url); | 204 util::FileSystemURLParser target_parser(target_url); |
| 204 | 205 |
| 205 if (!source_parser.Parse() || !target_parser.Parse() || | 206 if (!source_parser.Parse() || !target_parser.Parse() || |
| 206 source_parser.file_system() != target_parser.file_system()) { | 207 source_parser.file_system() != target_parser.file_system()) { |
| 207 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 208 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 208 return; | 209 return; |
| 209 } | 210 } |
| 210 | 211 |
| 211 target_parser.file_system()->CopyEntry( | 212 target_parser.file_system()->CopyEntry( |
| 212 source_parser.file_path(), target_parser.file_path(), callback); | 213 source_parser.file_path(), target_parser.file_path(), callback); |
| 213 } | 214 } |
| 214 | 215 |
| 215 // Routes the response of CopyEntry to a callback of CopyLocalFile() on the | 216 // Routes the response of CopyEntry to a callback of CopyLocalFile() on the |
| 216 // IO thread. | 217 // IO thread. |
| 217 void OnCopyEntry(const storage::AsyncFileUtil::StatusCallback& callback, | 218 void OnCopyEntry(const storage::AsyncFileUtil::StatusCallback& callback, |
| 218 base::File::Error result) { | 219 base::File::Error result) { |
| 219 BrowserThread::PostTask( | 220 BrowserThread::PostTask( |
| 220 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 221 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 221 } | 222 } |
| 222 | 223 |
| 223 // Executes MoveEntry on the UI thread. | 224 // Executes MoveEntry on the UI thread. |
| 224 void MoveEntryOnUIThread( | 225 void MoveEntryOnUIThread( |
| 225 scoped_ptr<storage::FileSystemOperationContext> context, | 226 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 226 const storage::FileSystemURL& source_url, | 227 const storage::FileSystemURL& source_url, |
| 227 const storage::FileSystemURL& target_url, | 228 const storage::FileSystemURL& target_url, |
| 228 const storage::AsyncFileUtil::StatusCallback& callback) { | 229 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 229 util::FileSystemURLParser source_parser(source_url); | 230 util::FileSystemURLParser source_parser(source_url); |
| 230 util::FileSystemURLParser target_parser(target_url); | 231 util::FileSystemURLParser target_parser(target_url); |
| 231 | 232 |
| 232 if (!source_parser.Parse() || !target_parser.Parse() || | 233 if (!source_parser.Parse() || !target_parser.Parse() || |
| 233 source_parser.file_system() != target_parser.file_system()) { | 234 source_parser.file_system() != target_parser.file_system()) { |
| 234 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 235 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 235 return; | 236 return; |
| 236 } | 237 } |
| 237 | 238 |
| 238 target_parser.file_system()->MoveEntry( | 239 target_parser.file_system()->MoveEntry( |
| 239 source_parser.file_path(), target_parser.file_path(), callback); | 240 source_parser.file_path(), target_parser.file_path(), callback); |
| 240 } | 241 } |
| 241 | 242 |
| 242 // Routes the response of CopyEntry to a callback of MoveLocalFile() on the | 243 // Routes the response of CopyEntry to a callback of MoveLocalFile() on the |
| 243 // IO thread. | 244 // IO thread. |
| 244 void OnMoveEntry(const storage::AsyncFileUtil::StatusCallback& callback, | 245 void OnMoveEntry(const storage::AsyncFileUtil::StatusCallback& callback, |
| 245 base::File::Error result) { | 246 base::File::Error result) { |
| 246 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
| 247 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 248 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 248 } | 249 } |
| 249 | 250 |
| 250 // Executes Truncate on the UI thread. | 251 // Executes Truncate on the UI thread. |
| 251 void TruncateOnUIThread( | 252 void TruncateOnUIThread( |
| 252 scoped_ptr<storage::FileSystemOperationContext> context, | 253 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 253 const storage::FileSystemURL& url, | 254 const storage::FileSystemURL& url, |
| 254 int64_t length, | 255 int64_t length, |
| 255 const storage::AsyncFileUtil::StatusCallback& callback) { | 256 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 256 util::FileSystemURLParser parser(url); | 257 util::FileSystemURLParser parser(url); |
| 257 if (!parser.Parse()) { | 258 if (!parser.Parse()) { |
| 258 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 259 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 259 return; | 260 return; |
| 260 } | 261 } |
| 261 | 262 |
| 262 parser.file_system()->Truncate(parser.file_path(), length, callback); | 263 parser.file_system()->Truncate(parser.file_path(), length, callback); |
| 263 } | 264 } |
| 264 | 265 |
| 265 // Routes the response of Truncate back to the IO thread. | 266 // Routes the response of Truncate back to the IO thread. |
| 266 void OnTruncate(const storage::AsyncFileUtil::StatusCallback& callback, | 267 void OnTruncate(const storage::AsyncFileUtil::StatusCallback& callback, |
| 267 base::File::Error result) { | 268 base::File::Error result) { |
| 268 BrowserThread::PostTask( | 269 BrowserThread::PostTask( |
| 269 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 270 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 270 } | 271 } |
| 271 | 272 |
| 272 } // namespace | 273 } // namespace |
| 273 | 274 |
| 274 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} | 275 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} |
| 275 | 276 |
| 276 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} | 277 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} |
| 277 | 278 |
| 278 void ProviderAsyncFileUtil::CreateOrOpen( | 279 void ProviderAsyncFileUtil::CreateOrOpen( |
| 279 scoped_ptr<storage::FileSystemOperationContext> context, | 280 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 280 const storage::FileSystemURL& url, | 281 const storage::FileSystemURL& url, |
| 281 int file_flags, | 282 int file_flags, |
| 282 const CreateOrOpenCallback& callback) { | 283 const CreateOrOpenCallback& callback) { |
| 283 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 284 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 284 if ((file_flags & base::File::FLAG_CREATE) || | 285 if ((file_flags & base::File::FLAG_CREATE) || |
| 285 (file_flags & base::File::FLAG_OPEN_ALWAYS) || | 286 (file_flags & base::File::FLAG_OPEN_ALWAYS) || |
| 286 (file_flags & base::File::FLAG_CREATE_ALWAYS) || | 287 (file_flags & base::File::FLAG_CREATE_ALWAYS) || |
| 287 (file_flags & base::File::FLAG_OPEN_TRUNCATED)) { | 288 (file_flags & base::File::FLAG_OPEN_TRUNCATED)) { |
| 288 callback.Run(base::File(base::File::FILE_ERROR_ACCESS_DENIED), | 289 callback.Run(base::File(base::File::FILE_ERROR_ACCESS_DENIED), |
| 289 base::Closure()); | 290 base::Closure()); |
| 290 return; | 291 return; |
| 291 } | 292 } |
| 292 | 293 |
| 293 NOTIMPLEMENTED(); | 294 NOTIMPLEMENTED(); |
| 294 callback.Run(base::File(base::File::FILE_ERROR_INVALID_OPERATION), | 295 callback.Run(base::File(base::File::FILE_ERROR_INVALID_OPERATION), |
| 295 base::Closure()); | 296 base::Closure()); |
| 296 } | 297 } |
| 297 | 298 |
| 298 void ProviderAsyncFileUtil::EnsureFileExists( | 299 void ProviderAsyncFileUtil::EnsureFileExists( |
| 299 scoped_ptr<storage::FileSystemOperationContext> context, | 300 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 300 const storage::FileSystemURL& url, | 301 const storage::FileSystemURL& url, |
| 301 const EnsureFileExistsCallback& callback) { | 302 const EnsureFileExistsCallback& callback) { |
| 302 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 303 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 303 BrowserThread::PostTask( | 304 BrowserThread::PostTask( |
| 304 BrowserThread::UI, | 305 BrowserThread::UI, |
| 305 FROM_HERE, | 306 FROM_HERE, |
| 306 base::Bind(&CreateFileOnUIThread, | 307 base::Bind(&CreateFileOnUIThread, |
| 307 base::Passed(&context), | 308 base::Passed(&context), |
| 308 url, | 309 url, |
| 309 base::Bind(&OnCreateFileForEnsureFileExists, callback))); | 310 base::Bind(&OnCreateFileForEnsureFileExists, callback))); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void ProviderAsyncFileUtil::CreateDirectory( | 313 void ProviderAsyncFileUtil::CreateDirectory( |
| 313 scoped_ptr<storage::FileSystemOperationContext> context, | 314 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 314 const storage::FileSystemURL& url, | 315 const storage::FileSystemURL& url, |
| 315 bool exclusive, | 316 bool exclusive, |
| 316 bool recursive, | 317 bool recursive, |
| 317 const StatusCallback& callback) { | 318 const StatusCallback& callback) { |
| 318 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 319 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 319 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
| 320 BrowserThread::UI, | 321 BrowserThread::UI, |
| 321 FROM_HERE, | 322 FROM_HERE, |
| 322 base::Bind(&CreateDirectoryOnUIThread, | 323 base::Bind(&CreateDirectoryOnUIThread, |
| 323 base::Passed(&context), | 324 base::Passed(&context), |
| 324 url, | 325 url, |
| 325 exclusive, | 326 exclusive, |
| 326 recursive, | 327 recursive, |
| 327 base::Bind(&OnCreateDirectory, exclusive, callback))); | 328 base::Bind(&OnCreateDirectory, exclusive, callback))); |
| 328 } | 329 } |
| 329 | 330 |
| 330 void ProviderAsyncFileUtil::GetFileInfo( | 331 void ProviderAsyncFileUtil::GetFileInfo( |
| 331 scoped_ptr<storage::FileSystemOperationContext> context, | 332 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 332 const storage::FileSystemURL& url, | 333 const storage::FileSystemURL& url, |
| 333 int fields, | 334 int fields, |
| 334 const GetFileInfoCallback& callback) { | 335 const GetFileInfoCallback& callback) { |
| 335 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 336 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 336 BrowserThread::PostTask( | 337 BrowserThread::PostTask( |
| 337 BrowserThread::UI, FROM_HERE, | 338 BrowserThread::UI, FROM_HERE, |
| 338 base::Bind(&GetFileInfoOnUIThread, base::Passed(&context), url, fields, | 339 base::Bind(&GetFileInfoOnUIThread, base::Passed(&context), url, fields, |
| 339 base::Bind(&OnGetFileInfo, fields, callback))); | 340 base::Bind(&OnGetFileInfo, fields, callback))); |
| 340 } | 341 } |
| 341 | 342 |
| 342 void ProviderAsyncFileUtil::ReadDirectory( | 343 void ProviderAsyncFileUtil::ReadDirectory( |
| 343 scoped_ptr<storage::FileSystemOperationContext> context, | 344 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 344 const storage::FileSystemURL& url, | 345 const storage::FileSystemURL& url, |
| 345 const ReadDirectoryCallback& callback) { | 346 const ReadDirectoryCallback& callback) { |
| 346 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 347 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 347 BrowserThread::PostTask(BrowserThread::UI, | 348 BrowserThread::PostTask(BrowserThread::UI, |
| 348 FROM_HERE, | 349 FROM_HERE, |
| 349 base::Bind(&ReadDirectoryOnUIThread, | 350 base::Bind(&ReadDirectoryOnUIThread, |
| 350 base::Passed(&context), | 351 base::Passed(&context), |
| 351 url, | 352 url, |
| 352 base::Bind(&OnReadDirectory, callback))); | 353 base::Bind(&OnReadDirectory, callback))); |
| 353 } | 354 } |
| 354 | 355 |
| 355 void ProviderAsyncFileUtil::Touch( | 356 void ProviderAsyncFileUtil::Touch( |
| 356 scoped_ptr<storage::FileSystemOperationContext> context, | 357 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 357 const storage::FileSystemURL& url, | 358 const storage::FileSystemURL& url, |
| 358 const base::Time& last_access_time, | 359 const base::Time& last_access_time, |
| 359 const base::Time& last_modified_time, | 360 const base::Time& last_modified_time, |
| 360 const StatusCallback& callback) { | 361 const StatusCallback& callback) { |
| 361 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 362 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 362 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 363 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); |
| 363 } | 364 } |
| 364 | 365 |
| 365 void ProviderAsyncFileUtil::Truncate( | 366 void ProviderAsyncFileUtil::Truncate( |
| 366 scoped_ptr<storage::FileSystemOperationContext> context, | 367 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 367 const storage::FileSystemURL& url, | 368 const storage::FileSystemURL& url, |
| 368 int64_t length, | 369 int64_t length, |
| 369 const StatusCallback& callback) { | 370 const StatusCallback& callback) { |
| 370 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 371 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 371 BrowserThread::PostTask(BrowserThread::UI, | 372 BrowserThread::PostTask(BrowserThread::UI, |
| 372 FROM_HERE, | 373 FROM_HERE, |
| 373 base::Bind(&TruncateOnUIThread, | 374 base::Bind(&TruncateOnUIThread, |
| 374 base::Passed(&context), | 375 base::Passed(&context), |
| 375 url, | 376 url, |
| 376 length, | 377 length, |
| 377 base::Bind(&OnTruncate, callback))); | 378 base::Bind(&OnTruncate, callback))); |
| 378 } | 379 } |
| 379 | 380 |
| 380 void ProviderAsyncFileUtil::CopyFileLocal( | 381 void ProviderAsyncFileUtil::CopyFileLocal( |
| 381 scoped_ptr<storage::FileSystemOperationContext> context, | 382 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 382 const storage::FileSystemURL& src_url, | 383 const storage::FileSystemURL& src_url, |
| 383 const storage::FileSystemURL& dest_url, | 384 const storage::FileSystemURL& dest_url, |
| 384 CopyOrMoveOption option, | 385 CopyOrMoveOption option, |
| 385 const CopyFileProgressCallback& progress_callback, | 386 const CopyFileProgressCallback& progress_callback, |
| 386 const StatusCallback& callback) { | 387 const StatusCallback& callback) { |
| 387 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 388 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 388 // TODO(mtomasz): Consier adding support for options (preserving last modified | 389 // TODO(mtomasz): Consier adding support for options (preserving last modified |
| 389 // time) as well as the progress callback. | 390 // time) as well as the progress callback. |
| 390 BrowserThread::PostTask(BrowserThread::UI, | 391 BrowserThread::PostTask(BrowserThread::UI, |
| 391 FROM_HERE, | 392 FROM_HERE, |
| 392 base::Bind(&CopyEntryOnUIThread, | 393 base::Bind(&CopyEntryOnUIThread, |
| 393 base::Passed(&context), | 394 base::Passed(&context), |
| 394 src_url, | 395 src_url, |
| 395 dest_url, | 396 dest_url, |
| 396 base::Bind(&OnCopyEntry, callback))); | 397 base::Bind(&OnCopyEntry, callback))); |
| 397 } | 398 } |
| 398 | 399 |
| 399 void ProviderAsyncFileUtil::MoveFileLocal( | 400 void ProviderAsyncFileUtil::MoveFileLocal( |
| 400 scoped_ptr<storage::FileSystemOperationContext> context, | 401 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 401 const storage::FileSystemURL& src_url, | 402 const storage::FileSystemURL& src_url, |
| 402 const storage::FileSystemURL& dest_url, | 403 const storage::FileSystemURL& dest_url, |
| 403 CopyOrMoveOption option, | 404 CopyOrMoveOption option, |
| 404 const StatusCallback& callback) { | 405 const StatusCallback& callback) { |
| 405 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 406 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 406 // TODO(mtomasz): Consier adding support for options (preserving last modified | 407 // TODO(mtomasz): Consier adding support for options (preserving last modified |
| 407 // time) as well as the progress callback. | 408 // time) as well as the progress callback. |
| 408 BrowserThread::PostTask(BrowserThread::UI, | 409 BrowserThread::PostTask(BrowserThread::UI, |
| 409 FROM_HERE, | 410 FROM_HERE, |
| 410 base::Bind(&MoveEntryOnUIThread, | 411 base::Bind(&MoveEntryOnUIThread, |
| 411 base::Passed(&context), | 412 base::Passed(&context), |
| 412 src_url, | 413 src_url, |
| 413 dest_url, | 414 dest_url, |
| 414 base::Bind(&OnMoveEntry, callback))); | 415 base::Bind(&OnMoveEntry, callback))); |
| 415 } | 416 } |
| 416 | 417 |
| 417 void ProviderAsyncFileUtil::CopyInForeignFile( | 418 void ProviderAsyncFileUtil::CopyInForeignFile( |
| 418 scoped_ptr<storage::FileSystemOperationContext> context, | 419 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 419 const base::FilePath& src_file_path, | 420 const base::FilePath& src_file_path, |
| 420 const storage::FileSystemURL& dest_url, | 421 const storage::FileSystemURL& dest_url, |
| 421 const StatusCallback& callback) { | 422 const StatusCallback& callback) { |
| 422 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 423 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 423 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 424 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); |
| 424 } | 425 } |
| 425 | 426 |
| 426 void ProviderAsyncFileUtil::DeleteFile( | 427 void ProviderAsyncFileUtil::DeleteFile( |
| 427 scoped_ptr<storage::FileSystemOperationContext> context, | 428 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 428 const storage::FileSystemURL& url, | 429 const storage::FileSystemURL& url, |
| 429 const StatusCallback& callback) { | 430 const StatusCallback& callback) { |
| 430 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 431 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 431 BrowserThread::PostTask(BrowserThread::UI, | 432 BrowserThread::PostTask(BrowserThread::UI, |
| 432 FROM_HERE, | 433 FROM_HERE, |
| 433 base::Bind(&DeleteEntryOnUIThread, | 434 base::Bind(&DeleteEntryOnUIThread, |
| 434 base::Passed(&context), | 435 base::Passed(&context), |
| 435 url, | 436 url, |
| 436 false, // recursive | 437 false, // recursive |
| 437 base::Bind(&OnDeleteEntry, callback))); | 438 base::Bind(&OnDeleteEntry, callback))); |
| 438 } | 439 } |
| 439 | 440 |
| 440 void ProviderAsyncFileUtil::DeleteDirectory( | 441 void ProviderAsyncFileUtil::DeleteDirectory( |
| 441 scoped_ptr<storage::FileSystemOperationContext> context, | 442 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 442 const storage::FileSystemURL& url, | 443 const storage::FileSystemURL& url, |
| 443 const StatusCallback& callback) { | 444 const StatusCallback& callback) { |
| 444 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 445 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 445 BrowserThread::PostTask(BrowserThread::UI, | 446 BrowserThread::PostTask(BrowserThread::UI, |
| 446 FROM_HERE, | 447 FROM_HERE, |
| 447 base::Bind(&DeleteEntryOnUIThread, | 448 base::Bind(&DeleteEntryOnUIThread, |
| 448 base::Passed(&context), | 449 base::Passed(&context), |
| 449 url, | 450 url, |
| 450 false, // recursive | 451 false, // recursive |
| 451 base::Bind(&OnDeleteEntry, callback))); | 452 base::Bind(&OnDeleteEntry, callback))); |
| 452 } | 453 } |
| 453 | 454 |
| 454 void ProviderAsyncFileUtil::DeleteRecursively( | 455 void ProviderAsyncFileUtil::DeleteRecursively( |
| 455 scoped_ptr<storage::FileSystemOperationContext> context, | 456 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 456 const storage::FileSystemURL& url, | 457 const storage::FileSystemURL& url, |
| 457 const StatusCallback& callback) { | 458 const StatusCallback& callback) { |
| 458 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 459 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 459 BrowserThread::PostTask(BrowserThread::UI, | 460 BrowserThread::PostTask(BrowserThread::UI, |
| 460 FROM_HERE, | 461 FROM_HERE, |
| 461 base::Bind(&DeleteEntryOnUIThread, | 462 base::Bind(&DeleteEntryOnUIThread, |
| 462 base::Passed(&context), | 463 base::Passed(&context), |
| 463 url, | 464 url, |
| 464 true, // recursive | 465 true, // recursive |
| 465 base::Bind(&OnDeleteEntry, callback))); | 466 base::Bind(&OnDeleteEntry, callback))); |
| 466 } | 467 } |
| 467 | 468 |
| 468 void ProviderAsyncFileUtil::CreateSnapshotFile( | 469 void ProviderAsyncFileUtil::CreateSnapshotFile( |
| 469 scoped_ptr<storage::FileSystemOperationContext> context, | 470 std::unique_ptr<storage::FileSystemOperationContext> context, |
| 470 const storage::FileSystemURL& url, | 471 const storage::FileSystemURL& url, |
| 471 const CreateSnapshotFileCallback& callback) { | 472 const CreateSnapshotFileCallback& callback) { |
| 472 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 473 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 473 NOTIMPLEMENTED(); | 474 NOTIMPLEMENTED(); |
| 474 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 475 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
| 475 base::File::Info(), | 476 base::File::Info(), |
| 476 base::FilePath(), | 477 base::FilePath(), |
| 477 scoped_refptr<storage::ShareableFileReference>()); | 478 scoped_refptr<storage::ShareableFileReference>()); |
| 478 } | 479 } |
| 479 | 480 |
| 480 } // namespace internal | 481 } // namespace internal |
| 481 } // namespace file_system_provider | 482 } // namespace file_system_provider |
| 482 } // namespace chromeos | 483 } // namespace chromeos |
| OLD | NEW |