Index: chrome/browser/local_discovery/privet_http_impl.cc |
diff --git a/chrome/browser/local_discovery/privet_http_impl.cc b/chrome/browser/local_discovery/privet_http_impl.cc |
index f2329507fc199369c58633aa65de5e7379e2cf4b..210627dc3e9d3148477666da35e0ad04d0d840aa 100644 |
--- a/chrome/browser/local_discovery/privet_http_impl.cc |
+++ b/chrome/browser/local_discovery/privet_http_impl.cc |
@@ -60,6 +60,8 @@ const int kPrivetLocalPrintMaxRetries = 2; |
const int kPrivetLocalPrintDefaultTimeout = 5; |
+const char kFileTypeOctetStream[] = "application/octet-stream"; |
+ |
GURL CreatePrivetURL(const std::string& path) { |
GURL url(kUrlPlaceHolder); |
GURL::Replacements replacements; |
@@ -387,19 +389,21 @@ void PrivetJSONOperationImpl::AppendQueryParameter(const std::string& name, |
PrivetDataReadOperationImpl::PrivetDataReadOperationImpl( |
PrivetHTTPClientImpl* privet_client, |
const std::string& path, |
+ net::URLFetcher::RequestType request_type, |
const PrivetDataReadOperation::ResultCallback& callback) |
: privet_client_(privet_client), |
url_(CreatePrivetURL(path)), |
+ request_type_(request_type), |
callback_(callback), |
has_range_(false), |
- save_to_file_(false) {} |
+ save_to_file_(false), |
+ has_upload_file_(false) {} |
PrivetDataReadOperationImpl::~PrivetDataReadOperationImpl() { |
} |
void PrivetDataReadOperationImpl::Start() { |
- url_fetcher_ = |
- privet_client_->CreateURLFetcher(url_, net::URLFetcher::GET, this); |
+ url_fetcher_ = privet_client_->CreateURLFetcher(url_, request_type_, this); |
url_fetcher_->DoNotRetryOnTransientError(); |
if (has_range_) { |
@@ -410,6 +414,11 @@ void PrivetDataReadOperationImpl::Start() { |
url_fetcher_->SaveResponseToFile(); |
} |
+ if (has_upload_file_) { |
+ DCHECK(request_type_ == net::URLFetcher::PUT); |
+ url_fetcher_->SetUploadFilePath(kFileTypeOctetStream, upload_file_); |
+ } |
+ |
url_fetcher_->Start(); |
} |
@@ -421,6 +430,12 @@ void PrivetDataReadOperationImpl::SetDataRange(int range_start, int range_end) { |
void PrivetDataReadOperationImpl::SaveDataToFile() { save_to_file_ = true; } |
+void PrivetDataReadOperationImpl::SetUploadFile( |
+ const base::FilePath& upload_file) { |
+ has_upload_file_ = true; |
+ upload_file_ = upload_file; |
+} |
+ |
PrivetHTTPClient* PrivetDataReadOperationImpl::GetHTTPClient() { |
return privet_client_; |
} |
@@ -847,7 +862,7 @@ PrivetHTTPClientImpl::CreateStorageReadOperation( |
const PrivetDataReadOperation::ResultCallback& callback) { |
scoped_ptr<PrivetDataReadOperationImpl> operation( |
new PrivetDataReadOperationImpl( |
- this, kPrivetStorageContentPath, callback)); |
+ this, kPrivetStorageContentPath, net::URLFetcher::GET, callback)); |
operation->AppendQueryParameter(kPrivetStorageParamPath, path); |
return operation.PassAs<PrivetDataReadOperation>(); |
@@ -907,6 +922,18 @@ PrivetHTTPClientImpl::CreateStorageCreateOperation( |
return operation.PassAs<PrivetJSONOperation>(); |
} |
+scoped_ptr<PrivetDataReadOperation> |
+PrivetHTTPClientImpl::CreateStorageOverwriteOperation( |
+ const std::string& path, |
+ const PrivetDataReadOperation::ResultCallback& callback) { |
+ scoped_ptr<PrivetDataReadOperationImpl> operation( |
+ new PrivetDataReadOperationImpl( |
+ this, kPrivetStorageContentPath, net::URLFetcher::PUT, callback)); |
+ |
+ operation->AppendQueryParameter(kPrivetStorageParamPath, path); |
+ return operation.PassAs<PrivetDataReadOperation>(); |
+} |
+ |
const std::string& PrivetHTTPClientImpl::GetName() { |
return name_; |
} |