| 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 "google_apis/drive/base_requests.h" | 5 #include "google_apis/drive/base_requests.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 549 |
| 550 void UrlFetchRequestBase::OnAuthFailed(DriveApiErrorCode code) { | 550 void UrlFetchRequestBase::OnAuthFailed(DriveApiErrorCode code) { |
| 551 CompleteRequestWithError(code); | 551 CompleteRequestWithError(code); |
| 552 } | 552 } |
| 553 | 553 |
| 554 base::WeakPtr<AuthenticatedRequestInterface> | 554 base::WeakPtr<AuthenticatedRequestInterface> |
| 555 UrlFetchRequestBase::GetWeakPtr() { | 555 UrlFetchRequestBase::GetWeakPtr() { |
| 556 return weak_ptr_factory_.GetWeakPtr(); | 556 return weak_ptr_factory_.GetWeakPtr(); |
| 557 } | 557 } |
| 558 | 558 |
| 559 //============================ BatchableRequestBase ============================ |
| 560 |
| 561 net::URLFetcher::RequestType BatchableRequestBase::GetRequestType() const { |
| 562 return UrlFetchRequestBase::GetRequestType(); |
| 563 } |
| 564 |
| 565 std::vector<std::string> BatchableRequestBase::GetExtraRequestHeaders() const { |
| 566 return UrlFetchRequestBase::GetExtraRequestHeaders(); |
| 567 } |
| 568 |
| 569 void BatchableRequestBase::Prepare(const PrepareCallback& callback) { |
| 570 return UrlFetchRequestBase::Prepare(callback); |
| 571 } |
| 572 |
| 573 bool BatchableRequestBase::GetContentData( |
| 574 std::string* upload_content_type, std::string* upload_content) { |
| 575 return UrlFetchRequestBase::GetContentData( |
| 576 upload_content_type, upload_content); |
| 577 } |
| 578 |
| 579 void BatchableRequestBase::ProcessURLFetchResults( |
| 580 const net::URLFetcher* source) { |
| 581 ProcessURLFetchResults(GetErrorCode(), response_writer()->data()); |
| 582 } |
| 583 |
| 559 //============================ EntryActionRequest ============================ | 584 //============================ EntryActionRequest ============================ |
| 560 | 585 |
| 561 EntryActionRequest::EntryActionRequest(RequestSender* sender, | 586 EntryActionRequest::EntryActionRequest(RequestSender* sender, |
| 562 const EntryActionCallback& callback) | 587 const EntryActionCallback& callback) |
| 563 : UrlFetchRequestBase(sender), | 588 : UrlFetchRequestBase(sender), |
| 564 callback_(callback) { | 589 callback_(callback) { |
| 565 DCHECK(!callback_.is_null()); | 590 DCHECK(!callback_.is_null()); |
| 566 } | 591 } |
| 567 | 592 |
| 568 EntryActionRequest::~EntryActionRequest() {} | 593 EntryActionRequest::~EntryActionRequest() {} |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 //========================= MultipartUploadRequestBase ======================== | 850 //========================= MultipartUploadRequestBase ======================== |
| 826 | 851 |
| 827 MultipartUploadRequestBase::MultipartUploadRequestBase( | 852 MultipartUploadRequestBase::MultipartUploadRequestBase( |
| 828 RequestSender* sender, | 853 RequestSender* sender, |
| 829 const std::string& metadata_json, | 854 const std::string& metadata_json, |
| 830 const std::string& content_type, | 855 const std::string& content_type, |
| 831 int64 content_length, | 856 int64 content_length, |
| 832 const base::FilePath& local_file_path, | 857 const base::FilePath& local_file_path, |
| 833 const FileResourceCallback& callback, | 858 const FileResourceCallback& callback, |
| 834 const ProgressCallback& progress_callback) | 859 const ProgressCallback& progress_callback) |
| 835 : UrlFetchRequestBase(sender), | 860 : BatchableRequestBase(sender), |
| 836 metadata_json_(metadata_json), | 861 metadata_json_(metadata_json), |
| 837 content_type_(content_type), | 862 content_type_(content_type), |
| 838 local_path_(local_file_path), | 863 local_path_(local_file_path), |
| 839 callback_(callback), | 864 callback_(callback), |
| 840 progress_callback_(progress_callback), | 865 progress_callback_(progress_callback), |
| 841 weak_ptr_factory_(this) { | 866 weak_ptr_factory_(this) { |
| 842 DCHECK(!content_type.empty()); | 867 DCHECK(!content_type.empty()); |
| 843 DCHECK_GE(content_length, 0); | 868 DCHECK_GE(content_length, 0); |
| 844 DCHECK(!local_file_path.empty()); | 869 DCHECK(!local_file_path.empty()); |
| 845 DCHECK(!callback.is_null()); | 870 DCHECK(!callback.is_null()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 bool MultipartUploadRequestBase::GetContentData( | 911 bool MultipartUploadRequestBase::GetContentData( |
| 887 std::string* upload_content_type, | 912 std::string* upload_content_type, |
| 888 std::string* upload_content_data) { | 913 std::string* upload_content_data) { |
| 889 // TODO(hirono): Pass stream instead of actual data to reduce memory usage. | 914 // TODO(hirono): Pass stream instead of actual data to reduce memory usage. |
| 890 upload_content_type->swap(upload_content_type_); | 915 upload_content_type->swap(upload_content_type_); |
| 891 upload_content_data->swap(upload_content_data_); | 916 upload_content_data->swap(upload_content_data_); |
| 892 return true; | 917 return true; |
| 893 } | 918 } |
| 894 | 919 |
| 895 void MultipartUploadRequestBase::ProcessURLFetchResults( | 920 void MultipartUploadRequestBase::ProcessURLFetchResults( |
| 896 const URLFetcher* source) { | 921 DriveApiErrorCode code, const std::string& body) { |
| 897 // The upload is successfully done. Parse the response which should be | 922 // The upload is successfully done. Parse the response which should be |
| 898 // the entry's metadata. | 923 // the entry's metadata. |
| 899 const DriveApiErrorCode code = GetErrorCode(); | |
| 900 if (code == HTTP_CREATED || code == HTTP_SUCCESS) { | 924 if (code == HTTP_CREATED || code == HTTP_SUCCESS) { |
| 901 ParseJsonOnBlockingPool( | 925 ParseJsonOnBlockingPool( |
| 902 blocking_task_runner(), response_writer()->data(), | 926 blocking_task_runner(), body, |
| 903 base::Bind(&MultipartUploadRequestBase::OnDataParsed, | 927 base::Bind(&MultipartUploadRequestBase::OnDataParsed, |
| 904 weak_ptr_factory_.GetWeakPtr(), code)); | 928 weak_ptr_factory_.GetWeakPtr(), code)); |
| 905 } else { | 929 } else { |
| 906 OnDataParsed(code, scoped_ptr<base::Value>()); | 930 OnDataParsed(code, scoped_ptr<base::Value>()); |
| 907 } | 931 } |
| 908 } | 932 } |
| 909 | 933 |
| 910 void MultipartUploadRequestBase::RunCallbackOnPrematureFailure( | 934 void MultipartUploadRequestBase::RunCallbackOnPrematureFailure( |
| 911 DriveApiErrorCode code) { | 935 DriveApiErrorCode code) { |
| 912 callback_.Run(code, scoped_ptr<FileResource>()); | 936 callback_.Run(code, scoped_ptr<FileResource>()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 download_action_callback_.Run(code, temp_file); | 1010 download_action_callback_.Run(code, temp_file); |
| 987 OnProcessURLFetchResultsComplete(); | 1011 OnProcessURLFetchResultsComplete(); |
| 988 } | 1012 } |
| 989 | 1013 |
| 990 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( | 1014 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( |
| 991 DriveApiErrorCode code) { | 1015 DriveApiErrorCode code) { |
| 992 download_action_callback_.Run(code, base::FilePath()); | 1016 download_action_callback_.Run(code, base::FilePath()); |
| 993 } | 1017 } |
| 994 | 1018 |
| 995 } // namespace google_apis | 1019 } // namespace google_apis |
| OLD | NEW |