Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_operations.h" | 5 #include "chrome/browser/google_apis/gdata_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_util.h" | 10 #include "chrome/browser/google_apis/gdata_util.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 | 171 |
| 172 ResumeUploadResponse::~ResumeUploadResponse() { | 172 ResumeUploadResponse::~ResumeUploadResponse() { |
| 173 } | 173 } |
| 174 | 174 |
| 175 InitiateUploadParams::InitiateUploadParams( | 175 InitiateUploadParams::InitiateUploadParams( |
| 176 UploadMode upload_mode, | 176 UploadMode upload_mode, |
| 177 const std::string& title, | 177 const std::string& title, |
| 178 const std::string& content_type, | 178 const std::string& content_type, |
| 179 int64 content_length, | 179 int64 content_length, |
| 180 const GURL& upload_location, | 180 const GURL& upload_location, |
| 181 const FilePath& virtual_path) | 181 const FilePath& virtual_path, |
| 182 const std::string& etag) | |
| 182 : upload_mode(upload_mode), | 183 : upload_mode(upload_mode), |
| 183 title(title), | 184 title(title), |
| 184 content_type(content_type), | 185 content_type(content_type), |
| 185 content_length(content_length), | 186 content_length(content_length), |
| 186 upload_location(upload_location), | 187 upload_location(upload_location), |
| 187 virtual_path(virtual_path) { | 188 virtual_path(virtual_path), |
| 189 etag(etag) { | |
| 188 } | 190 } |
| 189 | 191 |
| 190 InitiateUploadParams::~InitiateUploadParams() { | 192 InitiateUploadParams::~InitiateUploadParams() { |
| 191 } | 193 } |
| 192 | 194 |
| 193 ResumeUploadParams::ResumeUploadParams( | 195 ResumeUploadParams::ResumeUploadParams( |
| 194 UploadMode upload_mode, | 196 UploadMode upload_mode, |
| 195 int64 start_range, | 197 int64 start_range, |
| 196 int64 end_range, | 198 int64 end_range, |
| 197 int64 content_length, | 199 int64 content_length, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } | 287 } |
| 286 | 288 |
| 287 //============================ DownloadFileOperation =========================== | 289 //============================ DownloadFileOperation =========================== |
| 288 | 290 |
| 289 DownloadFileOperation::DownloadFileOperation( | 291 DownloadFileOperation::DownloadFileOperation( |
| 290 OperationRegistry* registry, | 292 OperationRegistry* registry, |
| 291 const DownloadActionCallback& download_action_callback, | 293 const DownloadActionCallback& download_action_callback, |
| 292 const GetContentCallback& get_content_callback, | 294 const GetContentCallback& get_content_callback, |
| 293 const GURL& document_url, | 295 const GURL& document_url, |
| 294 const FilePath& virtual_path, | 296 const FilePath& virtual_path, |
| 295 const FilePath& output_file_path) | 297 const FilePath& output_file_path, |
| 298 const std::string& etag) | |
| 296 : UrlFetchOperationBase(registry, | 299 : UrlFetchOperationBase(registry, |
| 297 OPERATION_DOWNLOAD, | 300 OPERATION_DOWNLOAD, |
| 298 virtual_path), | 301 virtual_path), |
| 299 download_action_callback_(download_action_callback), | 302 download_action_callback_(download_action_callback), |
| 300 get_content_callback_(get_content_callback), | 303 get_content_callback_(get_content_callback), |
| 301 document_url_(document_url) { | 304 document_url_(document_url), |
| 305 etag_(etag) { | |
| 302 // Make sure we download the content into a temp file. | 306 // Make sure we download the content into a temp file. |
| 303 if (output_file_path.empty()) | 307 if (output_file_path.empty()) |
| 304 save_temp_file_ = true; | 308 save_temp_file_ = true; |
| 305 else | 309 else |
| 306 output_file_path_ = output_file_path; | 310 output_file_path_ = output_file_path; |
| 307 } | 311 } |
| 308 | 312 |
| 309 DownloadFileOperation::~DownloadFileOperation() {} | 313 DownloadFileOperation::~DownloadFileOperation() {} |
| 310 | 314 |
| 311 // Overridden from UrlFetchOperationBase. | 315 // Overridden from UrlFetchOperationBase. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 if (!download_action_callback_.is_null()) | 348 if (!download_action_callback_.is_null()) |
| 345 download_action_callback_.Run(code, document_url_, temp_file); | 349 download_action_callback_.Run(code, document_url_, temp_file); |
| 346 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 350 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 347 } | 351 } |
| 348 | 352 |
| 349 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 353 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
| 350 if (!download_action_callback_.is_null()) | 354 if (!download_action_callback_.is_null()) |
| 351 download_action_callback_.Run(code, document_url_, FilePath()); | 355 download_action_callback_.Run(code, document_url_, FilePath()); |
| 352 } | 356 } |
| 353 | 357 |
| 358 std::vector<std::string> DownloadFileOperation::GetExtraRequestHeaders() const { | |
| 359 std::vector<std::string> headers; | |
| 360 if (!etag_.empty()) | |
| 361 headers.push_back(base::StringPrintf(kIfMatchHeaderFormat, etag_.c_str())); | |
| 362 return headers; | |
| 363 } | |
| 364 | |
| 354 //=========================== DeleteDocumentOperation ========================== | 365 //=========================== DeleteDocumentOperation ========================== |
| 355 | 366 |
| 356 DeleteDocumentOperation::DeleteDocumentOperation( | 367 DeleteDocumentOperation::DeleteDocumentOperation( |
| 357 OperationRegistry* registry, | 368 OperationRegistry* registry, |
| 358 const EntryActionCallback& callback, | 369 const EntryActionCallback& callback, |
| 359 const GURL& document_url) | 370 const GURL& document_url, |
| 360 : EntryActionOperation(registry, callback, document_url) { | 371 const std::string& etag) |
| 372 : EntryActionOperation(registry, callback, document_url), | |
| 373 etag_(etag) { | |
| 361 } | 374 } |
| 362 | 375 |
| 363 DeleteDocumentOperation::~DeleteDocumentOperation() {} | 376 DeleteDocumentOperation::~DeleteDocumentOperation() {} |
| 364 | 377 |
| 365 GURL DeleteDocumentOperation::GetURL() const { | 378 GURL DeleteDocumentOperation::GetURL() const { |
| 366 return AddStandardUrlParams(document_url()); | 379 return AddStandardUrlParams(document_url()); |
| 367 } | 380 } |
| 368 | 381 |
| 369 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const { | 382 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const { |
| 370 return URLFetcher::DELETE_REQUEST; | 383 return URLFetcher::DELETE_REQUEST; |
| 371 } | 384 } |
| 372 | 385 |
| 373 std::vector<std::string> | 386 std::vector<std::string> |
| 374 DeleteDocumentOperation::GetExtraRequestHeaders() const { | 387 DeleteDocumentOperation::GetExtraRequestHeaders() const { |
| 375 std::vector<std::string> headers; | 388 std::vector<std::string> headers; |
| 376 headers.push_back(kIfMatchAllHeader); | 389 if (etag_.empty()) |
| 390 headers.push_back(kIfMatchAllHeader); | |
| 391 else | |
| 392 headers.push_back(base::StringPrintf(kIfMatchHeaderFormat, etag_.c_str())); | |
| 377 return headers; | 393 return headers; |
| 378 } | 394 } |
| 379 | 395 |
| 380 //========================== CreateDirectoryOperation ========================== | 396 //========================== CreateDirectoryOperation ========================== |
| 381 | 397 |
| 382 CreateDirectoryOperation::CreateDirectoryOperation( | 398 CreateDirectoryOperation::CreateDirectoryOperation( |
| 383 OperationRegistry* registry, | 399 OperationRegistry* registry, |
| 384 const GetDataCallback& callback, | 400 const GetDataCallback& callback, |
| 385 const GURL& parent_content_url, | 401 const GURL& parent_content_url, |
| 386 const FilePath::StringType& directory_name) | 402 const FilePath::StringType& directory_name) |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 | 762 |
| 747 std::vector<std::string> | 763 std::vector<std::string> |
| 748 InitiateUploadOperation::GetExtraRequestHeaders() const { | 764 InitiateUploadOperation::GetExtraRequestHeaders() const { |
| 749 std::vector<std::string> headers; | 765 std::vector<std::string> headers; |
| 750 if (!params_.content_type.empty()) | 766 if (!params_.content_type.empty()) |
| 751 headers.push_back(kUploadContentType + params_.content_type); | 767 headers.push_back(kUploadContentType + params_.content_type); |
| 752 | 768 |
| 753 headers.push_back( | 769 headers.push_back( |
| 754 kUploadContentLength + base::Int64ToString(params_.content_length)); | 770 kUploadContentLength + base::Int64ToString(params_.content_length)); |
| 755 | 771 |
| 756 if (params_.upload_mode == UPLOAD_EXISTING_FILE) | 772 if (params_.upload_mode == UPLOAD_EXISTING_FILE) { |
| 757 headers.push_back("If-Match: *"); | 773 if (params_.etag.empty()) { |
| 774 headers.push_back(kIfMatchAllHeader); | |
|
kochi
2012/10/16 05:04:58
Even when uploading existing file, is there a poss
tzik
2012/10/16 05:48:05
I think we can, since existing code do so.
Maybe,
| |
| 775 } else { | |
| 776 headers.push_back( | |
| 777 base::StringPrintf(kIfMatchHeaderFormat, params_.etag.c_str())); | |
| 778 } | |
| 779 } | |
| 758 | 780 |
| 759 return headers; | 781 return headers; |
| 760 } | 782 } |
| 761 | 783 |
| 762 bool InitiateUploadOperation::GetContentData(std::string* upload_content_type, | 784 bool InitiateUploadOperation::GetContentData(std::string* upload_content_type, |
| 763 std::string* upload_content) { | 785 std::string* upload_content) { |
| 764 if (params_.upload_mode == UPLOAD_EXISTING_FILE) { | 786 if (params_.upload_mode == UPLOAD_EXISTING_FILE) { |
| 765 // When uploading an existing file, the body is empty as we don't modify | 787 // When uploading an existing file, the body is empty as we don't modify |
| 766 // the metadata. | 788 // the metadata. |
| 767 *upload_content = ""; | 789 *upload_content = ""; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 scoped_ptr<DocumentEntry> entry; | 910 scoped_ptr<DocumentEntry> entry; |
| 889 if (!callback_.is_null()) | 911 if (!callback_.is_null()) |
| 890 callback_.Run(ResumeUploadResponse(code, 0, 0), entry.Pass()); | 912 callback_.Run(ResumeUploadResponse(code, 0, 0), entry.Pass()); |
| 891 } | 913 } |
| 892 | 914 |
| 893 URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const { | 915 URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const { |
| 894 return URLFetcher::PUT; | 916 return URLFetcher::PUT; |
| 895 } | 917 } |
| 896 | 918 |
| 897 std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const { | 919 std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const { |
| 920 std::vector<std::string> headers; | |
| 921 | |
| 922 if (params_.etag.empty()) { | |
| 923 headers.push_back(kIfMatchAllHeader); | |
| 924 } else { | |
| 925 headers.push_back( | |
| 926 base::StringPrintf(kIfMatchHeaderFormat, params_.etag.c_str())); | |
| 927 } | |
| 928 | |
| 898 if (params_.content_length == 0) { | 929 if (params_.content_length == 0) { |
| 899 // For uploading an empty document, just PUT an empty content. | 930 // For uploading an empty document, just PUT an empty content. |
| 900 DCHECK_EQ(params_.start_range, 0); | 931 DCHECK_EQ(params_.start_range, 0); |
| 901 DCHECK_EQ(params_.end_range, -1); | 932 DCHECK_EQ(params_.end_range, -1); |
| 902 return std::vector<std::string>(); | 933 return headers; |
| 903 } | 934 } |
| 904 | 935 |
| 905 // The header looks like | 936 // The header looks like |
| 906 // Content-Range: bytes <start_range>-<end_range>/<content_length> | 937 // Content-Range: bytes <start_range>-<end_range>/<content_length> |
| 907 // for example: | 938 // for example: |
| 908 // Content-Range: bytes 7864320-8388607/13851821 | 939 // Content-Range: bytes 7864320-8388607/13851821 |
| 909 // Use * for unknown/streaming content length. | 940 // Use * for unknown/streaming content length. |
| 910 DCHECK_GE(params_.start_range, 0); | 941 DCHECK_GE(params_.start_range, 0); |
| 911 DCHECK_GE(params_.end_range, 0); | 942 DCHECK_GE(params_.end_range, 0); |
| 912 DCHECK_GE(params_.content_length, -1); | 943 DCHECK_GE(params_.content_length, -1); |
| 913 | 944 |
| 914 std::vector<std::string> headers; | |
| 915 headers.push_back( | 945 headers.push_back( |
| 916 std::string(kUploadContentRange) + | 946 std::string(kUploadContentRange) + |
| 917 base::Int64ToString(params_.start_range) + "-" + | 947 base::Int64ToString(params_.start_range) + "-" + |
| 918 base::Int64ToString(params_.end_range) + "/" + | 948 base::Int64ToString(params_.end_range) + "/" + |
| 919 (params_.content_length == -1 ? "*" : | 949 (params_.content_length == -1 ? "*" : |
| 920 base::Int64ToString(params_.content_length))); | 950 base::Int64ToString(params_.content_length))); |
| 921 return headers; | 951 return headers; |
| 922 } | 952 } |
| 923 | 953 |
| 924 bool ResumeUploadOperation::GetContentData(std::string* upload_content_type, | 954 bool ResumeUploadOperation::GetContentData(std::string* upload_content_type, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 1038 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 1009 } | 1039 } |
| 1010 | 1040 |
| 1011 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( | 1041 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( |
| 1012 GDataErrorCode code) { | 1042 GDataErrorCode code) { |
| 1013 scoped_ptr<std::string> data(new std::string); | 1043 scoped_ptr<std::string> data(new std::string); |
| 1014 callback_.Run(code, data.Pass()); | 1044 callback_.Run(code, data.Pass()); |
| 1015 } | 1045 } |
| 1016 | 1046 |
| 1017 } // namespace gdata | 1047 } // namespace gdata |
| OLD | NEW |