Chromium Code Reviews| Index: chrome/browser/local_discovery/storage/privet_filesystem_operations.cc |
| diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc b/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc |
| index aa84d25cc9d5fae550cda19d9a36160d0e2112da..cdcc980ee0459115147cf5bfb1517462fae0e3f4 100644 |
| --- a/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc |
| +++ b/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc |
| @@ -243,6 +243,19 @@ void PrivetFileSystemOperationFactory::CreateDirectory( |
| operation->Start(); |
| } |
| +void PrivetFileSystemOperationFactory::CopyInForeignFile( |
| + base::FilePath src_file_path, |
| + const fileapi::FileSystemURL& dest_url, |
| + const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| + TemporaryServiceDiscoveryClient(); |
| + |
| + PrivetFileSystemAsyncOperation* operation = |
| + new PrivetFileSystemUploadOperation( |
| + dest_url.path(), src_file_path, browser_context_, this, callback); |
| + async_operations_.insert(operation); |
| + operation->Start(); |
| +} |
| + |
| void PrivetFileSystemOperationFactory::RemoveOperation( |
| PrivetFileSystemAsyncOperation* operation) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| @@ -811,4 +824,72 @@ void PrivetFileSystemStatusOperation::TriggerCallbackAndDestroy( |
| container_->RemoveOperation(this); |
| } |
| +PrivetFileSystemUploadOperation::PrivetFileSystemUploadOperation( |
| + const base::FilePath& full_path, |
| + const base::FilePath& upload_path, |
| + content::BrowserContext* browser_context, |
| + PrivetFileSystemAsyncOperationContainer* container, |
| + const fileapi::AsyncFileUtil::StatusCallback& callback) |
| + : core_(full_path, browser_context, this), |
| + full_path_(full_path), |
| + upload_path_(upload_path), |
| + container_(container), |
| + callback_(callback) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| +} |
| + |
| +PrivetFileSystemUploadOperation::~PrivetFileSystemUploadOperation() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| +} |
| + |
| +void PrivetFileSystemUploadOperation::Start() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + core_.Start(); |
| +} |
| + |
| +void PrivetFileSystemUploadOperation::PrivetFileSystemResolved( |
| + PrivetHTTPClient* http_client, |
| + const std::string& path) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + if (!http_client) { |
| + SignalError(); |
| + return; |
| + } |
| + |
| + overwrite_operation_ = http_client->CreateStorageOverwriteOperation( |
| + path, |
| + base::Bind(&PrivetFileSystemUploadOperation::OnStorageOverwriteResult, |
| + base::Unretained(this))); |
| + overwrite_operation_->SetUploadFile(upload_path_); |
| + overwrite_operation_->Start(); |
|
Vitaly Buka (NO REVIEWS)
2014/03/04 19:39:00
start twice?
Noam Samuel
2014/03/04 20:10:30
Done.
|
| + |
| + overwrite_operation_->Start(); |
| +} |
| + |
| +void PrivetFileSystemUploadOperation::OnStorageOverwriteResult( |
| + PrivetDataReadOperation::ResponseType result_type, |
| + const std::string& data, |
| + const base::FilePath& file) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + if (result_type == PrivetDataReadOperation::RESPONSE_TYPE_ERROR) { |
| + SignalError(); |
| + } else { |
| + TriggerCallbackAndDestroy(base::File::FILE_OK); |
| + } |
| +} |
| + |
| +void PrivetFileSystemUploadOperation::SignalError() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + TriggerCallbackAndDestroy(base::File::FILE_ERROR_FAILED); |
| +} |
| + |
| +void PrivetFileSystemUploadOperation::TriggerCallbackAndDestroy( |
| + base::File::Error result) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, FROM_HERE, base::Bind(callback_, result)); |
| + container_->RemoveOperation(this); |
| +} |
| + |
| } // namespace local_discovery |