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

Side by Side 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: Remove unknown content length support, which is not used. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google_apis/gdata_wapi_operations.h" 5 #include "chrome/browser/google_apis/gdata_wapi_operations.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 10 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 // For uploading an empty document, just PUT an empty content. 751 // For uploading an empty document, just PUT an empty content.
752 DCHECK_EQ(start_position_, 0); 752 DCHECK_EQ(start_position_, 0);
753 DCHECK_EQ(end_position_, 0); 753 DCHECK_EQ(end_position_, 0);
754 return std::vector<std::string>(); 754 return std::vector<std::string>();
755 } 755 }
756 756
757 // The header looks like 757 // The header looks like
758 // Content-Range: bytes <start_position>-<end_position>/<content_length> 758 // Content-Range: bytes <start_position>-<end_position>/<content_length>
759 // for example: 759 // for example:
760 // Content-Range: bytes 7864320-8388607/13851821 760 // Content-Range: bytes 7864320-8388607/13851821
761 // Use * for unknown/streaming content length.
762 // The header takes inclusive range, so we adjust by "end_position - 1". 761 // The header takes inclusive range, so we adjust by "end_position - 1".
763 DCHECK_GE(start_position_, 0); 762 DCHECK_GE(start_position_, 0);
764 DCHECK_GT(end_position_, 0); 763 DCHECK_GT(end_position_, 0);
765 DCHECK_GE(content_length_, -1); 764 DCHECK_GE(content_length_, 0);
766 765
767 std::vector<std::string> headers; 766 std::vector<std::string> headers;
768 headers.push_back( 767 headers.push_back(
769 std::string(kUploadContentRange) + 768 std::string(kUploadContentRange) +
770 base::Int64ToString(start_position_) + "-" + 769 base::Int64ToString(start_position_) + "-" +
771 base::Int64ToString(end_position_ - 1) + "/" + 770 base::Int64ToString(end_position_ - 1) + "/" +
772 (content_length_ == -1 ? "*" : 771 base::Int64ToString(content_length_));
773 base::Int64ToString(content_length_)));
774 return headers; 772 return headers;
775 } 773 }
776 774
777 bool ResumeUploadOperation::GetContentData(std::string* upload_content_type, 775 bool ResumeUploadOperation::GetContentData(std::string* upload_content_type,
778 std::string* upload_content) { 776 std::string* upload_content) {
779 *upload_content_type = content_type_; 777 *upload_content_type = content_type_;
780 *upload_content = std::string(buf_->data(), end_position_ - start_position_); 778 *upload_content = std::string(buf_->data(), end_position_ - start_position_);
781 return true; 779 return true;
782 } 780 }
783 781
784 void ResumeUploadOperation::OnURLFetchUploadProgress( 782 void ResumeUploadOperation::OnURLFetchUploadProgress(
785 const URLFetcher* source, int64 current, int64 total) { 783 const URLFetcher* source, int64 current, int64 total) {
786 // Adjust the progress values according to the range currently uploaded. 784 // Adjust the progress values according to the range currently uploaded.
787 NotifyProgress(start_position_ + current, content_length_); 785 NotifyProgress(start_position_ + current, content_length_);
788 } 786 }
789 787
788 //========================== GetUploadStatusOperation ==========================
789
790 GetUploadStatusOperation::GetUploadStatusOperation(
791 OperationRegistry* registry,
792 net::URLRequestContextGetter* url_request_context_getter,
793 const UploadRangeCallback& callback,
794 UploadMode upload_mode,
795 const FilePath& drive_file_path,
796 const GURL& upload_url,
797 int64 content_length)
798 : UploadRangeOperationBase(registry,
799 url_request_context_getter,
800 callback,
801 upload_mode,
802 drive_file_path,
803 upload_url),
804 content_length_(content_length) {}
805
806 GetUploadStatusOperation::~GetUploadStatusOperation() {}
807
808 std::vector<std::string>
809 GetUploadStatusOperation::GetExtraRequestHeaders() const {
810 // The header looks like
811 // Content-Range: bytes */<content_length>
812 // for example:
813 // Content-Range: bytes */13851821
814 DCHECK_GE(content_length_, 0);
815
816 std::vector<std::string> headers;
817 headers.push_back(
818 std::string(kUploadContentRange) + "*/" +
819 base::Int64ToString(content_length_));
820 return headers;
821 }
822
790 } // namespace google_apis 823 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698