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

Unified Diff: chrome/browser/google_apis/gdata_wapi_operations.cc

Issue 12246002: Implement GetUploadStatusOperation on GData WAPI. (Closed) Base URL: http://git.chromium.org/chromium/src.git@b148632_create_base_operation
Patch Set: Fix mock server's behavior, as well as empty Range header handling. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google_apis/gdata_wapi_operations.cc
diff --git a/chrome/browser/google_apis/gdata_wapi_operations.cc b/chrome/browser/google_apis/gdata_wapi_operations.cc
index 20ec6a58f8088bd7b1579af16dc37d259b3e52d7..5ef26880e3ae581558330022f3fa1cdd1911ce38 100644
--- a/chrome/browser/google_apis/gdata_wapi_operations.cc
+++ b/chrome/browser/google_apis/gdata_wapi_operations.cc
@@ -634,8 +634,11 @@ void UploadRangeOperationBase::ProcessURLFetchResults(
if (code == HTTP_RESUME_INCOMPLETE) {
// Retrieve value of the first "Range" header.
- int64 start_position_received = -1;
- int64 end_position_received = -1;
+ // The Range header is appeared only if there is at least one received
+ // byte. So, initialize the positions by 0 so that the [0,0) will be
+ // returned via the |callback_| for empty data case.
+ int64 start_position_received = 0;
+ int64 end_position_received = 0;
std::string range_received;
hdrs->EnumerateHeader(NULL, kUploadResponseRange, &range_received);
if (!range_received.empty()) { // Parse the range header.
@@ -651,6 +654,9 @@ void UploadRangeOperationBase::ProcessURLFetchResults(
end_position_received = ranges[0].last_byte_position() + 1;
}
}
+ // The Range header has the received data range, so the start position
+ // should be always 0.
+ DCHECK_EQ(start_position_received, 0);
DVLOG(1) << "Got response for [" << drive_file_path_.value()
<< "]: code=" << code
<< ", range_hdr=[" << range_received
@@ -751,19 +757,17 @@ std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const {
// Content-Range: bytes <start_position>-<end_position>/<content_length>
// for example:
// Content-Range: bytes 7864320-8388607/13851821
- // Use * for unknown/streaming content length.
// The header takes inclusive range, so we adjust by "end_position - 1".
DCHECK_GE(start_position_, 0);
DCHECK_GT(end_position_, 0);
- DCHECK_GE(content_length_, -1);
+ DCHECK_GE(content_length_, 0);
std::vector<std::string> headers;
headers.push_back(
std::string(kUploadContentRange) +
base::Int64ToString(start_position_) + "-" +
base::Int64ToString(end_position_ - 1) + "/" +
- (content_length_ == -1 ? "*" :
- base::Int64ToString(content_length_)));
+ base::Int64ToString(content_length_));
return headers;
}
@@ -780,4 +784,39 @@ void ResumeUploadOperation::OnURLFetchUploadProgress(
NotifyProgress(start_position_ + current, content_length_);
}
+//========================== GetUploadStatusOperation ==========================
+
+GetUploadStatusOperation::GetUploadStatusOperation(
+ OperationRegistry* registry,
+ net::URLRequestContextGetter* url_request_context_getter,
+ const UploadRangeCallback& callback,
+ UploadMode upload_mode,
+ const FilePath& drive_file_path,
+ const GURL& upload_url,
+ int64 content_length)
+ : UploadRangeOperationBase(registry,
+ url_request_context_getter,
+ callback,
+ upload_mode,
+ drive_file_path,
+ upload_url),
+ content_length_(content_length) {}
+
+GetUploadStatusOperation::~GetUploadStatusOperation() {}
+
+std::vector<std::string>
+GetUploadStatusOperation::GetExtraRequestHeaders() const {
+ // The header looks like
+ // Content-Range: bytes */<content_length>
+ // for example:
+ // Content-Range: bytes */13851821
+ DCHECK_GE(content_length_, 0);
+
+ std::vector<std::string> headers;
+ headers.push_back(
+ std::string(kUploadContentRange) + "*/" +
+ base::Int64ToString(content_length_));
+ return headers;
+}
+
} // namespace google_apis

Powered by Google App Engine
This is Rietveld 408576698