Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/local_discovery/storage/privet_filesystem_operations.cc

Issue 177373010: [Privet FS] Allow files to be able to be copied in to the privet filesystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/local_discovery/storage/privet_filesystem_operations.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/local_discovery/storage/privet_filesystem_operations.h" 5 #include "chrome/browser/local_discovery/storage/privet_filesystem_operations.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/numerics/safe_conversions.h" 9 #include "base/numerics/safe_conversions.h"
10 #include "chrome/browser/local_discovery/privet_constants.h" 10 #include "chrome/browser/local_discovery/privet_constants.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 url.path(), 236 url.path(),
237 base::Bind(&CreateCreateDirectory, containing_path, name), 237 base::Bind(&CreateCreateDirectory, containing_path, name),
238 false, 238 false,
239 browser_context_, 239 browser_context_,
240 this, 240 this,
241 callback); 241 callback);
242 async_operations_.insert(operation); 242 async_operations_.insert(operation);
243 operation->Start(); 243 operation->Start();
244 } 244 }
245 245
246 void PrivetFileSystemOperationFactory::CopyInForeignFile(
247 base::FilePath src_file_path,
248 const fileapi::FileSystemURL& dest_url,
249 const fileapi::AsyncFileUtil::StatusCallback& callback) {
250 TemporaryServiceDiscoveryClient();
251
252 PrivetFileSystemAsyncOperation* operation =
253 new PrivetFileSystemUploadOperation(
254 dest_url.path(), src_file_path, browser_context_, this, callback);
255 async_operations_.insert(operation);
256 operation->Start();
257 }
258
246 void PrivetFileSystemOperationFactory::RemoveOperation( 259 void PrivetFileSystemOperationFactory::RemoveOperation(
247 PrivetFileSystemAsyncOperation* operation) { 260 PrivetFileSystemAsyncOperation* operation) {
248 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 261 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
249 async_operations_.erase(operation); 262 async_operations_.erase(operation);
250 delete operation; 263 delete operation;
251 } 264 }
252 265
253 void PrivetFileSystemOperationFactory::RemoveAllOperations() { 266 void PrivetFileSystemOperationFactory::RemoveAllOperations() {
254 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 267 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
255 STLDeleteElements(&async_operations_); 268 STLDeleteElements(&async_operations_);
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 817 }
805 818
806 void PrivetFileSystemStatusOperation::TriggerCallbackAndDestroy( 819 void PrivetFileSystemStatusOperation::TriggerCallbackAndDestroy(
807 base::File::Error result) { 820 base::File::Error result) {
808 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 821 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
809 content::BrowserThread::PostTask( 822 content::BrowserThread::PostTask(
810 content::BrowserThread::IO, FROM_HERE, base::Bind(callback_, result)); 823 content::BrowserThread::IO, FROM_HERE, base::Bind(callback_, result));
811 container_->RemoveOperation(this); 824 container_->RemoveOperation(this);
812 } 825 }
813 826
827 PrivetFileSystemUploadOperation::PrivetFileSystemUploadOperation(
828 const base::FilePath& full_path,
829 const base::FilePath& upload_path,
830 content::BrowserContext* browser_context,
831 PrivetFileSystemAsyncOperationContainer* container,
832 const fileapi::AsyncFileUtil::StatusCallback& callback)
833 : core_(full_path, browser_context, this),
834 full_path_(full_path),
835 upload_path_(upload_path),
836 container_(container),
837 callback_(callback) {
838 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
839 }
840
841 PrivetFileSystemUploadOperation::~PrivetFileSystemUploadOperation() {
842 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
843 }
844
845 void PrivetFileSystemUploadOperation::Start() {
846 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
847 core_.Start();
848 }
849
850 void PrivetFileSystemUploadOperation::PrivetFileSystemResolved(
851 PrivetHTTPClient* http_client,
852 const std::string& path) {
853 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
854 if (!http_client) {
855 SignalError();
856 return;
857 }
858
859 overwrite_operation_ = http_client->CreateStorageOverwriteOperation(
860 path,
861 base::Bind(&PrivetFileSystemUploadOperation::OnStorageOverwriteResult,
862 base::Unretained(this)));
863 overwrite_operation_->SetUploadFile(upload_path_);
864 overwrite_operation_->Start();
865 }
866
867 void PrivetFileSystemUploadOperation::OnStorageOverwriteResult(
868 PrivetDataReadOperation::ResponseType result_type,
869 const std::string& data,
870 const base::FilePath& file) {
871 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
872
873 if (result_type == PrivetDataReadOperation::RESPONSE_TYPE_ERROR) {
874 SignalError();
875 } else {
876 TriggerCallbackAndDestroy(base::File::FILE_OK);
877 }
878 }
879
880 void PrivetFileSystemUploadOperation::SignalError() {
881 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
882 TriggerCallbackAndDestroy(base::File::FILE_ERROR_FAILED);
883 }
884
885 void PrivetFileSystemUploadOperation::TriggerCallbackAndDestroy(
886 base::File::Error result) {
887 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
888 content::BrowserThread::PostTask(
889 content::BrowserThread::IO, FROM_HERE, base::Bind(callback_, result));
890 container_->RemoveOperation(this);
891 }
892
814 } // namespace local_discovery 893 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/storage/privet_filesystem_operations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698