| 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/base_requests.h" | 5 #include "chrome/browser/google_apis/base_requests.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // Content-Range: bytes */13851821 | 595 // Content-Range: bytes */13851821 |
| 596 DCHECK_GE(content_length_, 0); | 596 DCHECK_GE(content_length_, 0); |
| 597 | 597 |
| 598 std::vector<std::string> headers; | 598 std::vector<std::string> headers; |
| 599 headers.push_back( | 599 headers.push_back( |
| 600 std::string(kUploadContentRange) + "*/" + | 600 std::string(kUploadContentRange) + "*/" + |
| 601 base::Int64ToString(content_length_)); | 601 base::Int64ToString(content_length_)); |
| 602 return headers; | 602 return headers; |
| 603 } | 603 } |
| 604 | 604 |
| 605 //============================ DownloadFileRequest =========================== | 605 //============================ DownloadFileRequestBase ========================= |
| 606 | 606 |
| 607 DownloadFileRequest::DownloadFileRequest( | 607 DownloadFileRequestBase::DownloadFileRequestBase( |
| 608 RequestSender* sender, | 608 RequestSender* sender, |
| 609 const DownloadActionCallback& download_action_callback, | 609 const DownloadActionCallback& download_action_callback, |
| 610 const GetContentCallback& get_content_callback, | 610 const GetContentCallback& get_content_callback, |
| 611 const ProgressCallback& progress_callback, | 611 const ProgressCallback& progress_callback, |
| 612 const GURL& download_url, | 612 const GURL& download_url, |
| 613 const base::FilePath& output_file_path) | 613 const base::FilePath& output_file_path) |
| 614 : UrlFetchRequestBase(sender), | 614 : UrlFetchRequestBase(sender), |
| 615 download_action_callback_(download_action_callback), | 615 download_action_callback_(download_action_callback), |
| 616 get_content_callback_(get_content_callback), | 616 get_content_callback_(get_content_callback), |
| 617 progress_callback_(progress_callback), | 617 progress_callback_(progress_callback), |
| 618 download_url_(download_url), | 618 download_url_(download_url), |
| 619 output_file_path_(output_file_path) { | 619 output_file_path_(output_file_path) { |
| 620 DCHECK(!download_action_callback_.is_null()); | 620 DCHECK(!download_action_callback_.is_null()); |
| 621 DCHECK(!output_file_path_.empty()); | 621 DCHECK(!output_file_path_.empty()); |
| 622 // get_content_callback may be null. | 622 // get_content_callback may be null. |
| 623 } | 623 } |
| 624 | 624 |
| 625 DownloadFileRequest::~DownloadFileRequest() {} | 625 DownloadFileRequestBase::~DownloadFileRequestBase() {} |
| 626 | 626 |
| 627 // Overridden from UrlFetchRequestBase. | 627 // Overridden from UrlFetchRequestBase. |
| 628 GURL DownloadFileRequest::GetURL() const { | 628 GURL DownloadFileRequestBase::GetURL() const { |
| 629 return download_url_; | 629 return download_url_; |
| 630 } | 630 } |
| 631 | 631 |
| 632 bool DownloadFileRequest::GetOutputFilePath(base::FilePath* local_file_path) { | 632 bool DownloadFileRequestBase::GetOutputFilePath( |
| 633 base::FilePath* local_file_path) { |
| 633 // Configure so that the downloaded content is saved to |output_file_path_|. | 634 // Configure so that the downloaded content is saved to |output_file_path_|. |
| 634 *local_file_path = output_file_path_; | 635 *local_file_path = output_file_path_; |
| 635 return true; | 636 return true; |
| 636 } | 637 } |
| 637 | 638 |
| 638 void DownloadFileRequest::OnURLFetchDownloadProgress(const URLFetcher* source, | 639 void DownloadFileRequestBase::OnURLFetchDownloadProgress( |
| 639 int64 current, | 640 const URLFetcher* source, |
| 640 int64 total) { | 641 int64 current, |
| 642 int64 total) { |
| 641 if (!progress_callback_.is_null()) | 643 if (!progress_callback_.is_null()) |
| 642 progress_callback_.Run(current, total); | 644 progress_callback_.Run(current, total); |
| 643 } | 645 } |
| 644 | 646 |
| 645 bool DownloadFileRequest::ShouldSendDownloadData() { | 647 bool DownloadFileRequestBase::ShouldSendDownloadData() { |
| 646 return !get_content_callback_.is_null(); | 648 return !get_content_callback_.is_null(); |
| 647 } | 649 } |
| 648 | 650 |
| 649 void DownloadFileRequest::OnURLFetchDownloadData( | 651 void DownloadFileRequestBase::OnURLFetchDownloadData( |
| 650 const URLFetcher* source, | 652 const URLFetcher* source, |
| 651 scoped_ptr<std::string> download_data) { | 653 scoped_ptr<std::string> download_data) { |
| 652 if (!get_content_callback_.is_null()) | 654 if (!get_content_callback_.is_null()) |
| 653 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); | 655 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); |
| 654 } | 656 } |
| 655 | 657 |
| 656 void DownloadFileRequest::ProcessURLFetchResults(const URLFetcher* source) { | 658 void DownloadFileRequestBase::ProcessURLFetchResults(const URLFetcher* source) { |
| 657 GDataErrorCode code = GetErrorCode(source); | 659 GDataErrorCode code = GetErrorCode(source); |
| 658 | 660 |
| 659 // Take over the ownership of the the downloaded temp file. | 661 // Take over the ownership of the the downloaded temp file. |
| 660 base::FilePath temp_file; | 662 base::FilePath temp_file; |
| 661 if (code == HTTP_SUCCESS && | 663 if (code == HTTP_SUCCESS && |
| 662 !source->GetResponseAsFilePath(true, // take_ownership | 664 !source->GetResponseAsFilePath(true, // take_ownership |
| 663 &temp_file)) { | 665 &temp_file)) { |
| 664 code = GDATA_FILE_ERROR; | 666 code = GDATA_FILE_ERROR; |
| 665 } | 667 } |
| 666 | 668 |
| 667 download_action_callback_.Run(code, temp_file); | 669 download_action_callback_.Run(code, temp_file); |
| 668 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 670 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 669 } | 671 } |
| 670 | 672 |
| 671 void DownloadFileRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 673 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( |
| 674 GDataErrorCode code) { |
| 672 download_action_callback_.Run(code, base::FilePath()); | 675 download_action_callback_.Run(code, base::FilePath()); |
| 673 } | 676 } |
| 674 | 677 |
| 675 } // namespace google_apis | 678 } // namespace google_apis |
| OLD | NEW |