| 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/chromeos/gdata/gdata_operations.h" | 5 #include "chrome/browser/chromeos/gdata/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/chromeos/gdata/gdata_util.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 net::EscapePath( | 154 net::EscapePath( |
| 155 directory_resource_id).c_str())); | 155 directory_resource_id).c_str())); |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace | 158 } // namespace |
| 159 | 159 |
| 160 namespace gdata { | 160 namespace gdata { |
| 161 | 161 |
| 162 //============================ Structs =========================== | 162 //============================ Structs =========================== |
| 163 | 163 |
| 164 ResumeUploadResponse::ResumeUploadResponse(GDataErrorCode code, | 164 ResumeUploadResponse::ResumeUploadResponse(DriveErrorCode code, |
| 165 int64 start_range_received, | 165 int64 start_range_received, |
| 166 int64 end_range_received) | 166 int64 end_range_received) |
| 167 : code(code), | 167 : code(code), |
| 168 start_range_received(start_range_received), | 168 start_range_received(start_range_received), |
| 169 end_range_received(end_range_received) { | 169 end_range_received(end_range_received) { |
| 170 } | 170 } |
| 171 | 171 |
| 172 ResumeUploadResponse::~ResumeUploadResponse() { | 172 ResumeUploadResponse::~ResumeUploadResponse() { |
| 173 } | 173 } |
| 174 | 174 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 324 } |
| 325 | 325 |
| 326 void DownloadFileOperation::OnURLFetchDownloadData( | 326 void DownloadFileOperation::OnURLFetchDownloadData( |
| 327 const URLFetcher* source, | 327 const URLFetcher* source, |
| 328 scoped_ptr<std::string> download_data) { | 328 scoped_ptr<std::string> download_data) { |
| 329 if (!get_content_callback_.is_null()) | 329 if (!get_content_callback_.is_null()) |
| 330 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); | 330 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) { | 333 void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) { |
| 334 GDataErrorCode code = GetErrorCode(source); | 334 DriveErrorCode code = GetErrorCode(source); |
| 335 | 335 |
| 336 // Take over the ownership of the the downloaded temp file. | 336 // Take over the ownership of the the downloaded temp file. |
| 337 FilePath temp_file; | 337 FilePath temp_file; |
| 338 if (code == HTTP_SUCCESS && | 338 if (code == HTTP_SUCCESS && |
| 339 !source->GetResponseAsFilePath(true, // take_ownership | 339 !source->GetResponseAsFilePath(true, // take_ownership |
| 340 &temp_file)) { | 340 &temp_file)) { |
| 341 code = GDATA_FILE_ERROR; | 341 code = DRIVE_FILE_ERROR; |
| 342 } | 342 } |
| 343 | 343 |
| 344 if (!download_action_callback_.is_null()) | 344 if (!download_action_callback_.is_null()) |
| 345 download_action_callback_.Run(code, document_url_, temp_file); | 345 download_action_callback_.Run(code, document_url_, temp_file); |
| 346 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 346 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 349 void DownloadFileOperation::RunCallbackOnPrematureFailure(DriveErrorCode code) { |
| 350 if (!download_action_callback_.is_null()) | 350 if (!download_action_callback_.is_null()) |
| 351 download_action_callback_.Run(code, document_url_, FilePath()); | 351 download_action_callback_.Run(code, document_url_, FilePath()); |
| 352 } | 352 } |
| 353 | 353 |
| 354 //=========================== DeleteDocumentOperation ========================== | 354 //=========================== DeleteDocumentOperation ========================== |
| 355 | 355 |
| 356 DeleteDocumentOperation::DeleteDocumentOperation( | 356 DeleteDocumentOperation::DeleteDocumentOperation( |
| 357 OperationRegistry* registry, | 357 OperationRegistry* registry, |
| 358 const EntryActionCallback& callback, | 358 const EntryActionCallback& callback, |
| 359 const GURL& document_url) | 359 const GURL& document_url) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 558 |
| 559 xml_writer.EndElement(); // Ends "entry" element. | 559 xml_writer.EndElement(); // Ends "entry" element. |
| 560 xml_writer.StopWriting(); | 560 xml_writer.StopWriting(); |
| 561 upload_content->assign(xml_writer.GetWrittenString()); | 561 upload_content->assign(xml_writer.GetWrittenString()); |
| 562 DVLOG(1) << "AuthorizeAppOperation data: " << *upload_content_type << ", [" | 562 DVLOG(1) << "AuthorizeAppOperation data: " << *upload_content_type << ", [" |
| 563 << *upload_content << "]"; | 563 << *upload_content << "]"; |
| 564 return true; | 564 return true; |
| 565 } | 565 } |
| 566 | 566 |
| 567 void AuthorizeAppsOperation::ParseResponse( | 567 void AuthorizeAppsOperation::ParseResponse( |
| 568 GDataErrorCode fetch_error_code, | 568 DriveErrorCode fetch_error_code, |
| 569 const std::string& data) { | 569 const std::string& data) { |
| 570 // Parse entry XML. | 570 // Parse entry XML. |
| 571 XmlReader xml_reader; | 571 XmlReader xml_reader; |
| 572 scoped_ptr<DocumentEntry> entry; | 572 scoped_ptr<DocumentEntry> entry; |
| 573 if (xml_reader.Load(data)) { | 573 if (xml_reader.Load(data)) { |
| 574 while (xml_reader.Read()) { | 574 while (xml_reader.Read()) { |
| 575 if (xml_reader.NodeName() == DocumentEntry::GetEntryNodeName()) { | 575 if (xml_reader.NodeName() == DocumentEntry::GetEntryNodeName()) { |
| 576 entry.reset(DocumentEntry::CreateFromXml(&xml_reader)); | 576 entry.reset(DocumentEntry::CreateFromXml(&xml_reader)); |
| 577 break; | 577 break; |
| 578 } | 578 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 } | 701 } |
| 702 | 702 |
| 703 InitiateUploadOperation::~InitiateUploadOperation() {} | 703 InitiateUploadOperation::~InitiateUploadOperation() {} |
| 704 | 704 |
| 705 GURL InitiateUploadOperation::GetURL() const { | 705 GURL InitiateUploadOperation::GetURL() const { |
| 706 return initiate_upload_url_; | 706 return initiate_upload_url_; |
| 707 } | 707 } |
| 708 | 708 |
| 709 void InitiateUploadOperation::ProcessURLFetchResults( | 709 void InitiateUploadOperation::ProcessURLFetchResults( |
| 710 const URLFetcher* source) { | 710 const URLFetcher* source) { |
| 711 GDataErrorCode code = GetErrorCode(source); | 711 DriveErrorCode code = GetErrorCode(source); |
| 712 | 712 |
| 713 std::string upload_location; | 713 std::string upload_location; |
| 714 if (code == HTTP_SUCCESS) { | 714 if (code == HTTP_SUCCESS) { |
| 715 // Retrieve value of the first "Location" header. | 715 // Retrieve value of the first "Location" header. |
| 716 source->GetResponseHeaders()->EnumerateHeader(NULL, | 716 source->GetResponseHeaders()->EnumerateHeader(NULL, |
| 717 kUploadResponseLocation, | 717 kUploadResponseLocation, |
| 718 &upload_location); | 718 &upload_location); |
| 719 } | 719 } |
| 720 VLOG(1) << "Got response for [" << params_.title | 720 VLOG(1) << "Got response for [" << params_.title |
| 721 << "]: code=" << code | 721 << "]: code=" << code |
| 722 << ", location=[" << upload_location << "]"; | 722 << ", location=[" << upload_location << "]"; |
| 723 | 723 |
| 724 if (!callback_.is_null()) | 724 if (!callback_.is_null()) |
| 725 callback_.Run(code, GURL(upload_location)); | 725 callback_.Run(code, GURL(upload_location)); |
| 726 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 726 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 727 } | 727 } |
| 728 | 728 |
| 729 void InitiateUploadOperation::NotifySuccessToOperationRegistry() { | 729 void InitiateUploadOperation::NotifySuccessToOperationRegistry() { |
| 730 NotifySuspend(); | 730 NotifySuspend(); |
| 731 } | 731 } |
| 732 | 732 |
| 733 void InitiateUploadOperation::RunCallbackOnPrematureFailure( | 733 void InitiateUploadOperation::RunCallbackOnPrematureFailure( |
| 734 GDataErrorCode code) { | 734 DriveErrorCode code) { |
| 735 if (!callback_.is_null()) | 735 if (!callback_.is_null()) |
| 736 callback_.Run(code, GURL()); | 736 callback_.Run(code, GURL()); |
| 737 } | 737 } |
| 738 | 738 |
| 739 URLFetcher::RequestType InitiateUploadOperation::GetRequestType() const { | 739 URLFetcher::RequestType InitiateUploadOperation::GetRequestType() const { |
| 740 if (params_.upload_mode == UPLOAD_NEW_FILE) | 740 if (params_.upload_mode == UPLOAD_NEW_FILE) |
| 741 return URLFetcher::POST; | 741 return URLFetcher::POST; |
| 742 | 742 |
| 743 DCHECK_EQ(UPLOAD_EXISTING_FILE, params_.upload_mode); | 743 DCHECK_EQ(UPLOAD_EXISTING_FILE, params_.upload_mode); |
| 744 return URLFetcher::PUT; | 744 return URLFetcher::PUT; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 last_chunk_completed_(false) { | 802 last_chunk_completed_(false) { |
| 803 } | 803 } |
| 804 | 804 |
| 805 ResumeUploadOperation::~ResumeUploadOperation() {} | 805 ResumeUploadOperation::~ResumeUploadOperation() {} |
| 806 | 806 |
| 807 GURL ResumeUploadOperation::GetURL() const { | 807 GURL ResumeUploadOperation::GetURL() const { |
| 808 return params_.upload_location; | 808 return params_.upload_location; |
| 809 } | 809 } |
| 810 | 810 |
| 811 void ResumeUploadOperation::ProcessURLFetchResults(const URLFetcher* source) { | 811 void ResumeUploadOperation::ProcessURLFetchResults(const URLFetcher* source) { |
| 812 GDataErrorCode code = GetErrorCode(source); | 812 DriveErrorCode code = GetErrorCode(source); |
| 813 net::HttpResponseHeaders* hdrs = source->GetResponseHeaders(); | 813 net::HttpResponseHeaders* hdrs = source->GetResponseHeaders(); |
| 814 int64 start_range_received = -1; | 814 int64 start_range_received = -1; |
| 815 int64 end_range_received = -1; | 815 int64 end_range_received = -1; |
| 816 scoped_ptr<DocumentEntry> entry; | 816 scoped_ptr<DocumentEntry> entry; |
| 817 | 817 |
| 818 if (code == HTTP_RESUME_INCOMPLETE) { | 818 if (code == HTTP_RESUME_INCOMPLETE) { |
| 819 // Retrieve value of the first "Range" header. | 819 // Retrieve value of the first "Range" header. |
| 820 std::string range_received; | 820 std::string range_received; |
| 821 hdrs->EnumerateHeader(NULL, kUploadResponseRange, &range_received); | 821 hdrs->EnumerateHeader(NULL, kUploadResponseRange, &range_received); |
| 822 if (!range_received.empty()) { // Parse the range header. | 822 if (!range_received.empty()) { // Parse the range header. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 NotifyResume(); | 877 NotifyResume(); |
| 878 } | 878 } |
| 879 | 879 |
| 880 void ResumeUploadOperation::NotifySuccessToOperationRegistry() { | 880 void ResumeUploadOperation::NotifySuccessToOperationRegistry() { |
| 881 if (last_chunk_completed_) | 881 if (last_chunk_completed_) |
| 882 NotifyFinish(OperationRegistry::OPERATION_COMPLETED); | 882 NotifyFinish(OperationRegistry::OPERATION_COMPLETED); |
| 883 else | 883 else |
| 884 NotifySuspend(); | 884 NotifySuspend(); |
| 885 } | 885 } |
| 886 | 886 |
| 887 void ResumeUploadOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 887 void ResumeUploadOperation::RunCallbackOnPrematureFailure(DriveErrorCode code) { |
| 888 scoped_ptr<DocumentEntry> entry; | 888 scoped_ptr<DocumentEntry> entry; |
| 889 if (!callback_.is_null()) | 889 if (!callback_.is_null()) |
| 890 callback_.Run(ResumeUploadResponse(code, 0, 0), entry.Pass()); | 890 callback_.Run(ResumeUploadResponse(code, 0, 0), entry.Pass()); |
| 891 } | 891 } |
| 892 | 892 |
| 893 URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const { | 893 URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const { |
| 894 return URLFetcher::PUT; | 894 return URLFetcher::PUT; |
| 895 } | 895 } |
| 896 | 896 |
| 897 std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const { | 897 std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 } | 994 } |
| 995 | 995 |
| 996 GetContactPhotoOperation::~GetContactPhotoOperation() {} | 996 GetContactPhotoOperation::~GetContactPhotoOperation() {} |
| 997 | 997 |
| 998 GURL GetContactPhotoOperation::GetURL() const { | 998 GURL GetContactPhotoOperation::GetURL() const { |
| 999 return photo_url_; | 999 return photo_url_; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 void GetContactPhotoOperation::ProcessURLFetchResults( | 1002 void GetContactPhotoOperation::ProcessURLFetchResults( |
| 1003 const net::URLFetcher* source) { | 1003 const net::URLFetcher* source) { |
| 1004 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode()); | 1004 DriveErrorCode code = static_cast<DriveErrorCode>(source->GetResponseCode()); |
| 1005 scoped_ptr<std::string> data(new std::string); | 1005 scoped_ptr<std::string> data(new std::string); |
| 1006 source->GetResponseAsString(data.get()); | 1006 source->GetResponseAsString(data.get()); |
| 1007 callback_.Run(code, data.Pass()); | 1007 callback_.Run(code, data.Pass()); |
| 1008 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 1008 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( | 1011 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( |
| 1012 GDataErrorCode code) { | 1012 DriveErrorCode code) { |
| 1013 scoped_ptr<std::string> data(new std::string); | 1013 scoped_ptr<std::string> data(new std::string); |
| 1014 callback_.Run(code, data.Pass()); | 1014 callback_.Run(code, data.Pass()); |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 } // namespace gdata | 1017 } // namespace gdata |
| OLD | NEW |