| 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 "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" | 5 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 bool exclusive, | 79 bool exclusive, |
| 80 const StatusCallback& callback) { | 80 const StatusCallback& callback) { |
| 81 DCHECK(CalledOnValidThread()); | 81 DCHECK(CalledOnValidThread()); |
| 82 if (!operation_runner_.get()) { | 82 if (!operation_runner_.get()) { |
| 83 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 83 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 DCHECK(operation_runner_.get()); | 86 DCHECK(operation_runner_.get()); |
| 87 target_paths_.push_back(url); | 87 target_paths_.push_back(url); |
| 88 completion_callback_ = callback; | 88 completion_callback_ = callback; |
| 89 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 89 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 90 weak_factory_.GetWeakPtr(), | 90 weak_factory_.GetWeakPtr(), |
| 91 base::Bind(&FileSystemOperation::CreateFile, | 91 base::Bind(&FileSystemOperation::CreateFile, |
| 92 base::Unretained(impl_.get()), | 92 base::Unretained(impl_.get()), url, exclusive, |
| 93 url, exclusive, | |
| 94 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 93 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 95 operation_runner_->PostOperationTask(std::move(task)); | 94 operation_runner_->PostOperationTask(std::move(task)); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void SyncableFileSystemOperation::CreateDirectory( | 97 void SyncableFileSystemOperation::CreateDirectory( |
| 99 const FileSystemURL& url, | 98 const FileSystemURL& url, |
| 100 bool exclusive, | 99 bool exclusive, |
| 101 bool recursive, | 100 bool recursive, |
| 102 const StatusCallback& callback) { | 101 const StatusCallback& callback) { |
| 103 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
| 104 if (!operation_runner_.get()) { | 103 if (!operation_runner_.get()) { |
| 105 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 104 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 106 return; | 105 return; |
| 107 } | 106 } |
| 108 DCHECK(operation_runner_.get()); | 107 DCHECK(operation_runner_.get()); |
| 109 target_paths_.push_back(url); | 108 target_paths_.push_back(url); |
| 110 completion_callback_ = callback; | 109 completion_callback_ = callback; |
| 111 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 110 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 112 weak_factory_.GetWeakPtr(), | 111 weak_factory_.GetWeakPtr(), |
| 113 base::Bind(&FileSystemOperation::CreateDirectory, | 112 base::Bind(&FileSystemOperation::CreateDirectory, |
| 114 base::Unretained(impl_.get()), | 113 base::Unretained(impl_.get()), url, exclusive, recursive, |
| 115 url, exclusive, recursive, | |
| 116 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 114 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 117 operation_runner_->PostOperationTask(std::move(task)); | 115 operation_runner_->PostOperationTask(std::move(task)); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void SyncableFileSystemOperation::Copy( | 118 void SyncableFileSystemOperation::Copy( |
| 121 const FileSystemURL& src_url, | 119 const FileSystemURL& src_url, |
| 122 const FileSystemURL& dest_url, | 120 const FileSystemURL& dest_url, |
| 123 CopyOrMoveOption option, | 121 CopyOrMoveOption option, |
| 124 ErrorBehavior error_behavior, | 122 ErrorBehavior error_behavior, |
| 125 const CopyProgressCallback& progress_callback, | 123 const CopyProgressCallback& progress_callback, |
| 126 const StatusCallback& callback) { | 124 const StatusCallback& callback) { |
| 127 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
| 128 if (!operation_runner_.get()) { | 126 if (!operation_runner_.get()) { |
| 129 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 127 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 130 return; | 128 return; |
| 131 } | 129 } |
| 132 DCHECK(operation_runner_.get()); | 130 DCHECK(operation_runner_.get()); |
| 133 target_paths_.push_back(dest_url); | 131 target_paths_.push_back(dest_url); |
| 134 completion_callback_ = callback; | 132 completion_callback_ = callback; |
| 135 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 133 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 136 weak_factory_.GetWeakPtr(), | 134 weak_factory_.GetWeakPtr(), |
| 137 base::Bind(&FileSystemOperation::Copy, base::Unretained(impl_.get()), | 135 base::Bind(&FileSystemOperation::Copy, base::Unretained(impl_.get()), |
| 138 src_url, dest_url, option, error_behavior, progress_callback, | 136 src_url, dest_url, option, error_behavior, progress_callback, |
| 139 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 137 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 140 operation_runner_->PostOperationTask(std::move(task)); | 138 operation_runner_->PostOperationTask(std::move(task)); |
| 141 } | 139 } |
| 142 | 140 |
| 143 void SyncableFileSystemOperation::Move( | 141 void SyncableFileSystemOperation::Move( |
| 144 const FileSystemURL& src_url, | 142 const FileSystemURL& src_url, |
| 145 const FileSystemURL& dest_url, | 143 const FileSystemURL& dest_url, |
| 146 CopyOrMoveOption option, | 144 CopyOrMoveOption option, |
| 147 const StatusCallback& callback) { | 145 const StatusCallback& callback) { |
| 148 DCHECK(CalledOnValidThread()); | 146 DCHECK(CalledOnValidThread()); |
| 149 if (!operation_runner_.get()) { | 147 if (!operation_runner_.get()) { |
| 150 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 148 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 151 return; | 149 return; |
| 152 } | 150 } |
| 153 DCHECK(operation_runner_.get()); | 151 DCHECK(operation_runner_.get()); |
| 154 target_paths_.push_back(src_url); | 152 target_paths_.push_back(src_url); |
| 155 target_paths_.push_back(dest_url); | 153 target_paths_.push_back(dest_url); |
| 156 completion_callback_ = callback; | 154 completion_callback_ = callback; |
| 157 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 155 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 158 weak_factory_.GetWeakPtr(), | 156 weak_factory_.GetWeakPtr(), |
| 159 base::Bind(&FileSystemOperation::Move, | 157 base::Bind(&FileSystemOperation::Move, base::Unretained(impl_.get()), |
| 160 base::Unretained(impl_.get()), | |
| 161 src_url, dest_url, option, | 158 src_url, dest_url, option, |
| 162 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 159 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 163 operation_runner_->PostOperationTask(std::move(task)); | 160 operation_runner_->PostOperationTask(std::move(task)); |
| 164 } | 161 } |
| 165 | 162 |
| 166 void SyncableFileSystemOperation::DirectoryExists( | 163 void SyncableFileSystemOperation::DirectoryExists( |
| 167 const FileSystemURL& url, | 164 const FileSystemURL& url, |
| 168 const StatusCallback& callback) { | 165 const StatusCallback& callback) { |
| 169 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
| 170 impl_->DirectoryExists(url, callback); | 167 impl_->DirectoryExists(url, callback); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 199 const FileSystemURL& url, bool recursive, | 196 const FileSystemURL& url, bool recursive, |
| 200 const StatusCallback& callback) { | 197 const StatusCallback& callback) { |
| 201 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
| 202 if (!operation_runner_.get()) { | 199 if (!operation_runner_.get()) { |
| 203 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 200 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 204 return; | 201 return; |
| 205 } | 202 } |
| 206 DCHECK(operation_runner_.get()); | 203 DCHECK(operation_runner_.get()); |
| 207 target_paths_.push_back(url); | 204 target_paths_.push_back(url); |
| 208 completion_callback_ = callback; | 205 completion_callback_ = callback; |
| 209 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 206 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 210 weak_factory_.GetWeakPtr(), | 207 weak_factory_.GetWeakPtr(), |
| 211 base::Bind(&FileSystemOperation::Remove, | 208 base::Bind(&FileSystemOperation::Remove, base::Unretained(impl_.get()), |
| 212 base::Unretained(impl_.get()), | |
| 213 url, recursive, | 209 url, recursive, |
| 214 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 210 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 215 operation_runner_->PostOperationTask(std::move(task)); | 211 operation_runner_->PostOperationTask(std::move(task)); |
| 216 } | 212 } |
| 217 | 213 |
| 218 void SyncableFileSystemOperation::Write( | 214 void SyncableFileSystemOperation::Write( |
| 219 const FileSystemURL& url, | 215 const FileSystemURL& url, |
| 220 scoped_ptr<storage::FileWriterDelegate> writer_delegate, | 216 std::unique_ptr<storage::FileWriterDelegate> writer_delegate, |
| 221 scoped_ptr<net::URLRequest> blob_request, | 217 std::unique_ptr<net::URLRequest> blob_request, |
| 222 const WriteCallback& callback) { | 218 const WriteCallback& callback) { |
| 223 DCHECK(CalledOnValidThread()); | 219 DCHECK(CalledOnValidThread()); |
| 224 if (!operation_runner_.get()) { | 220 if (!operation_runner_.get()) { |
| 225 callback.Run(base::File::FILE_ERROR_NOT_FOUND, 0, true); | 221 callback.Run(base::File::FILE_ERROR_NOT_FOUND, 0, true); |
| 226 return; | 222 return; |
| 227 } | 223 } |
| 228 DCHECK(operation_runner_.get()); | 224 DCHECK(operation_runner_.get()); |
| 229 target_paths_.push_back(url); | 225 target_paths_.push_back(url); |
| 230 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); | 226 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); |
| 231 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 227 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 232 weak_factory_.GetWeakPtr(), | 228 weak_factory_.GetWeakPtr(), |
| 233 base::Bind(&FileSystemOperation::Write, | 229 base::Bind( |
| 234 base::Unretained(impl_.get()), | 230 &FileSystemOperation::Write, base::Unretained(impl_.get()), url, |
| 235 url, | 231 base::Passed(&writer_delegate), base::Passed(&blob_request), |
| 236 base::Passed(&writer_delegate), | 232 base::Bind(&self::DidWrite, weak_factory_.GetWeakPtr(), callback)))); |
| 237 base::Passed(&blob_request), | |
| 238 base::Bind(&self::DidWrite, weak_factory_.GetWeakPtr(), | |
| 239 callback)))); | |
| 240 operation_runner_->PostOperationTask(std::move(task)); | 233 operation_runner_->PostOperationTask(std::move(task)); |
| 241 } | 234 } |
| 242 | 235 |
| 243 void SyncableFileSystemOperation::Truncate(const FileSystemURL& url, | 236 void SyncableFileSystemOperation::Truncate(const FileSystemURL& url, |
| 244 int64_t length, | 237 int64_t length, |
| 245 const StatusCallback& callback) { | 238 const StatusCallback& callback) { |
| 246 DCHECK(CalledOnValidThread()); | 239 DCHECK(CalledOnValidThread()); |
| 247 if (!operation_runner_.get()) { | 240 if (!operation_runner_.get()) { |
| 248 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 241 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 249 return; | 242 return; |
| 250 } | 243 } |
| 251 DCHECK(operation_runner_.get()); | 244 DCHECK(operation_runner_.get()); |
| 252 target_paths_.push_back(url); | 245 target_paths_.push_back(url); |
| 253 completion_callback_ = callback; | 246 completion_callback_ = callback; |
| 254 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 247 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 255 weak_factory_.GetWeakPtr(), | 248 weak_factory_.GetWeakPtr(), |
| 256 base::Bind(&FileSystemOperation::Truncate, | 249 base::Bind(&FileSystemOperation::Truncate, base::Unretained(impl_.get()), |
| 257 base::Unretained(impl_.get()), | |
| 258 url, length, | 250 url, length, |
| 259 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 251 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 260 operation_runner_->PostOperationTask(std::move(task)); | 252 operation_runner_->PostOperationTask(std::move(task)); |
| 261 } | 253 } |
| 262 | 254 |
| 263 void SyncableFileSystemOperation::TouchFile( | 255 void SyncableFileSystemOperation::TouchFile( |
| 264 const FileSystemURL& url, | 256 const FileSystemURL& url, |
| 265 const base::Time& last_access_time, | 257 const base::Time& last_access_time, |
| 266 const base::Time& last_modified_time, | 258 const base::Time& last_modified_time, |
| 267 const StatusCallback& callback) { | 259 const StatusCallback& callback) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 294 const FileSystemURL& dest_url, | 286 const FileSystemURL& dest_url, |
| 295 const StatusCallback& callback) { | 287 const StatusCallback& callback) { |
| 296 DCHECK(CalledOnValidThread()); | 288 DCHECK(CalledOnValidThread()); |
| 297 if (!operation_runner_.get()) { | 289 if (!operation_runner_.get()) { |
| 298 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 290 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 299 return; | 291 return; |
| 300 } | 292 } |
| 301 DCHECK(operation_runner_.get()); | 293 DCHECK(operation_runner_.get()); |
| 302 target_paths_.push_back(dest_url); | 294 target_paths_.push_back(dest_url); |
| 303 completion_callback_ = callback; | 295 completion_callback_ = callback; |
| 304 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 296 std::unique_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 305 weak_factory_.GetWeakPtr(), | 297 weak_factory_.GetWeakPtr(), |
| 306 base::Bind(&FileSystemOperation::CopyInForeignFile, | 298 base::Bind(&FileSystemOperation::CopyInForeignFile, |
| 307 base::Unretained(impl_.get()), | 299 base::Unretained(impl_.get()), src_local_disk_path, dest_url, |
| 308 src_local_disk_path, dest_url, | |
| 309 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 300 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
| 310 operation_runner_->PostOperationTask(std::move(task)); | 301 operation_runner_->PostOperationTask(std::move(task)); |
| 311 } | 302 } |
| 312 | 303 |
| 313 void SyncableFileSystemOperation::RemoveFile( | 304 void SyncableFileSystemOperation::RemoveFile( |
| 314 const FileSystemURL& url, | 305 const FileSystemURL& url, |
| 315 const StatusCallback& callback) { | 306 const StatusCallback& callback) { |
| 316 DCHECK(CalledOnValidThread()); | 307 DCHECK(CalledOnValidThread()); |
| 317 impl_->RemoveFile(url, callback); | 308 impl_->RemoveFile(url, callback); |
| 318 } | 309 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 345 | 336 |
| 346 base::File::Error SyncableFileSystemOperation::SyncGetPlatformPath( | 337 base::File::Error SyncableFileSystemOperation::SyncGetPlatformPath( |
| 347 const FileSystemURL& url, | 338 const FileSystemURL& url, |
| 348 base::FilePath* platform_path) { | 339 base::FilePath* platform_path) { |
| 349 return impl_->SyncGetPlatformPath(url, platform_path); | 340 return impl_->SyncGetPlatformPath(url, platform_path); |
| 350 } | 341 } |
| 351 | 342 |
| 352 SyncableFileSystemOperation::SyncableFileSystemOperation( | 343 SyncableFileSystemOperation::SyncableFileSystemOperation( |
| 353 const FileSystemURL& url, | 344 const FileSystemURL& url, |
| 354 storage::FileSystemContext* file_system_context, | 345 storage::FileSystemContext* file_system_context, |
| 355 scoped_ptr<storage::FileSystemOperationContext> operation_context) | 346 std::unique_ptr<storage::FileSystemOperationContext> operation_context) |
| 356 : url_(url), weak_factory_(this) { | 347 : url_(url), weak_factory_(this) { |
| 357 DCHECK(file_system_context); | 348 DCHECK(file_system_context); |
| 358 SyncFileSystemBackend* backend = | 349 SyncFileSystemBackend* backend = |
| 359 SyncFileSystemBackend::GetBackend(file_system_context); | 350 SyncFileSystemBackend::GetBackend(file_system_context); |
| 360 DCHECK(backend); | 351 DCHECK(backend); |
| 361 if (!backend->sync_context()) { | 352 if (!backend->sync_context()) { |
| 362 // Syncable FileSystem is opened in a file system context which doesn't | 353 // Syncable FileSystem is opened in a file system context which doesn't |
| 363 // support (or is not initialized for) the API. | 354 // support (or is not initialized for) the API. |
| 364 // Returning here to leave operation_runner_ as NULL. | 355 // Returning here to leave operation_runner_ as NULL. |
| 365 return; | 356 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 390 operation_runner_->OnOperationCompleted(target_paths_); | 381 operation_runner_->OnOperationCompleted(target_paths_); |
| 391 callback.Run(result, bytes, complete); | 382 callback.Run(result, bytes, complete); |
| 392 } | 383 } |
| 393 | 384 |
| 394 void SyncableFileSystemOperation::OnCancelled() { | 385 void SyncableFileSystemOperation::OnCancelled() { |
| 395 DCHECK(!completion_callback_.is_null()); | 386 DCHECK(!completion_callback_.is_null()); |
| 396 completion_callback_.Run(base::File::FILE_ERROR_ABORT); | 387 completion_callback_.Run(base::File::FILE_ERROR_ABORT); |
| 397 } | 388 } |
| 398 | 389 |
| 399 } // namespace sync_file_system | 390 } // namespace sync_file_system |
| OLD | NEW |