| Index: chrome/browser/google_apis/gdata_operations.cc
|
| diff --git a/chrome/browser/google_apis/gdata_operations.cc b/chrome/browser/google_apis/gdata_operations.cc
|
| index 046671d9f4d0ca177101c14a72eb53ea4398c60b..6075693eab892f89a9a206c45776deb1ac4e3238 100644
|
| --- a/chrome/browser/google_apis/gdata_operations.cc
|
| +++ b/chrome/browser/google_apis/gdata_operations.cc
|
| @@ -178,13 +178,18 @@ InitiateUploadParams::InitiateUploadParams(
|
| const std::string& content_type,
|
| int64 content_length,
|
| const GURL& upload_location,
|
| - const FilePath& virtual_path)
|
| + const FilePath& virtual_path,
|
| + const std::string& etag)
|
| : upload_mode(upload_mode),
|
| title(title),
|
| content_type(content_type),
|
| content_length(content_length),
|
| upload_location(upload_location),
|
| - virtual_path(virtual_path) {
|
| + virtual_path(virtual_path),
|
| + etag(etag) {
|
| + DCHECK(upload_mode == UPLOAD_NEW_FILE || upload_mode == UPLOAD_EXISTING_FILE);
|
| + DCHECK(upload_mode != UPLOAD_NEW_FILE || (!title.empty() && etag.empty()));
|
| + DCHECK(upload_mode != UPLOAD_EXISTING_FILE || title.empty());
|
| }
|
|
|
| InitiateUploadParams::~InitiateUploadParams() {
|
| @@ -198,14 +203,17 @@ ResumeUploadParams::ResumeUploadParams(
|
| const std::string& content_type,
|
| scoped_refptr<net::IOBuffer> buf,
|
| const GURL& upload_location,
|
| - const FilePath& virtual_path) : upload_mode(upload_mode),
|
| - start_range(start_range),
|
| - end_range(end_range),
|
| - content_length(content_length),
|
| - content_type(content_type),
|
| - buf(buf),
|
| - upload_location(upload_location),
|
| - virtual_path(virtual_path) {
|
| + const FilePath& virtual_path,
|
| + const std::string& etag)
|
| + : upload_mode(upload_mode),
|
| + start_range(start_range),
|
| + end_range(end_range),
|
| + content_length(content_length),
|
| + content_type(content_type),
|
| + buf(buf),
|
| + upload_location(upload_location),
|
| + virtual_path(virtual_path),
|
| + etag(etag) {
|
| }
|
|
|
| ResumeUploadParams::~ResumeUploadParams() {
|
| @@ -292,13 +300,15 @@ DownloadFileOperation::DownloadFileOperation(
|
| const GetContentCallback& get_content_callback,
|
| const GURL& document_url,
|
| const FilePath& virtual_path,
|
| - const FilePath& output_file_path)
|
| + const FilePath& output_file_path,
|
| + const std::string& etag)
|
| : UrlFetchOperationBase(registry,
|
| OPERATION_DOWNLOAD,
|
| virtual_path),
|
| download_action_callback_(download_action_callback),
|
| get_content_callback_(get_content_callback),
|
| - document_url_(document_url) {
|
| + document_url_(document_url),
|
| + etag_(etag) {
|
| // Make sure we download the content into a temp file.
|
| if (output_file_path.empty())
|
| save_temp_file_ = true;
|
| @@ -351,13 +361,22 @@ void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) {
|
| download_action_callback_.Run(code, document_url_, FilePath());
|
| }
|
|
|
| +std::vector<std::string> DownloadFileOperation::GetExtraRequestHeaders() const {
|
| + std::vector<std::string> headers;
|
| + if (!etag_.empty())
|
| + headers.push_back(base::StringPrintf(kIfMatchHeaderFormat, etag_.c_str()));
|
| + return headers;
|
| +}
|
| +
|
| //=========================== DeleteDocumentOperation ==========================
|
|
|
| DeleteDocumentOperation::DeleteDocumentOperation(
|
| OperationRegistry* registry,
|
| const EntryActionCallback& callback,
|
| - const GURL& document_url)
|
| - : EntryActionOperation(registry, callback, document_url) {
|
| + const GURL& document_url,
|
| + const std::string& etag)
|
| + : EntryActionOperation(registry, callback, document_url),
|
| + etag_(etag) {
|
| }
|
|
|
| DeleteDocumentOperation::~DeleteDocumentOperation() {}
|
| @@ -373,7 +392,10 @@ URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const {
|
| std::vector<std::string>
|
| DeleteDocumentOperation::GetExtraRequestHeaders() const {
|
| std::vector<std::string> headers;
|
| - headers.push_back(kIfMatchAllHeader);
|
| + if (etag_.empty())
|
| + headers.push_back(kIfMatchAllHeader);
|
| + else
|
| + headers.push_back(base::StringPrintf(kIfMatchHeaderFormat, etag_.c_str()));
|
| return headers;
|
| }
|
|
|
| @@ -753,8 +775,14 @@ InitiateUploadOperation::GetExtraRequestHeaders() const {
|
| headers.push_back(
|
| kUploadContentLength + base::Int64ToString(params_.content_length));
|
|
|
| - if (params_.upload_mode == UPLOAD_EXISTING_FILE)
|
| - headers.push_back("If-Match: *");
|
| + if (params_.upload_mode == UPLOAD_EXISTING_FILE) {
|
| + if (params_.etag.empty()) {
|
| + headers.push_back(kIfMatchAllHeader);
|
| + } else {
|
| + headers.push_back(
|
| + base::StringPrintf(kIfMatchHeaderFormat, params_.etag.c_str()));
|
| + }
|
| + }
|
|
|
| return headers;
|
| }
|
| @@ -895,11 +923,20 @@ URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const {
|
| }
|
|
|
| std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const {
|
| + std::vector<std::string> headers;
|
| +
|
| + if (params_.etag.empty()) {
|
| + headers.push_back(kIfMatchAllHeader);
|
| + } else {
|
| + headers.push_back(
|
| + base::StringPrintf(kIfMatchHeaderFormat, params_.etag.c_str()));
|
| + }
|
| +
|
| if (params_.content_length == 0) {
|
| // For uploading an empty document, just PUT an empty content.
|
| DCHECK_EQ(params_.start_range, 0);
|
| DCHECK_EQ(params_.end_range, -1);
|
| - return std::vector<std::string>();
|
| + return headers;
|
| }
|
|
|
| // The header looks like
|
| @@ -911,7 +948,6 @@ std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const {
|
| DCHECK_GE(params_.end_range, 0);
|
| DCHECK_GE(params_.content_length, -1);
|
|
|
| - std::vector<std::string> headers;
|
| headers.push_back(
|
| std::string(kUploadContentRange) +
|
| base::Int64ToString(params_.start_range) + "-" +
|
|
|