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_operations.h" | 5 #include "chrome/browser/google_apis/base_operations.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 NotifyProgress(start_position_ + current, content_length_); | 648 NotifyProgress(start_position_ + current, content_length_); |
649 } | 649 } |
650 | 650 |
651 //============================ DownloadFileOperation =========================== | 651 //============================ DownloadFileOperation =========================== |
652 | 652 |
653 DownloadFileOperation::DownloadFileOperation( | 653 DownloadFileOperation::DownloadFileOperation( |
654 OperationRegistry* registry, | 654 OperationRegistry* registry, |
655 net::URLRequestContextGetter* url_request_context_getter, | 655 net::URLRequestContextGetter* url_request_context_getter, |
656 const DownloadActionCallback& download_action_callback, | 656 const DownloadActionCallback& download_action_callback, |
657 const GetContentCallback& get_content_callback, | 657 const GetContentCallback& get_content_callback, |
| 658 const ProgressCallback& progress_callback, |
658 const GURL& download_url, | 659 const GURL& download_url, |
659 const base::FilePath& drive_file_path, | 660 const base::FilePath& drive_file_path, |
660 const base::FilePath& output_file_path) | 661 const base::FilePath& output_file_path) |
661 : UrlFetchOperationBase(registry, | 662 : UrlFetchOperationBase(registry, |
662 url_request_context_getter, | 663 url_request_context_getter, |
663 OPERATION_DOWNLOAD, | 664 OPERATION_DOWNLOAD, |
664 drive_file_path), | 665 drive_file_path), |
665 download_action_callback_(download_action_callback), | 666 download_action_callback_(download_action_callback), |
666 get_content_callback_(get_content_callback), | 667 get_content_callback_(get_content_callback), |
| 668 progress_callback_(progress_callback), |
667 download_url_(download_url) { | 669 download_url_(download_url) { |
668 DCHECK(!download_action_callback_.is_null()); | 670 DCHECK(!download_action_callback_.is_null()); |
669 // get_content_callback may be null. | 671 // get_content_callback may be null. |
670 | 672 |
671 // Make sure we download the content into a temp file. | 673 // Make sure we download the content into a temp file. |
672 if (output_file_path.empty()) | 674 if (output_file_path.empty()) |
673 set_save_temp_file(true); | 675 set_save_temp_file(true); |
674 else | 676 else |
675 set_output_file_path(output_file_path); | 677 set_output_file_path(output_file_path); |
676 } | 678 } |
677 | 679 |
678 DownloadFileOperation::~DownloadFileOperation() {} | 680 DownloadFileOperation::~DownloadFileOperation() {} |
679 | 681 |
680 // Overridden from UrlFetchOperationBase. | 682 // Overridden from UrlFetchOperationBase. |
681 GURL DownloadFileOperation::GetURL() const { | 683 GURL DownloadFileOperation::GetURL() const { |
682 return download_url_; | 684 return download_url_; |
683 } | 685 } |
684 | 686 |
685 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, | 687 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, |
686 int64 current, | 688 int64 current, |
687 int64 total) { | 689 int64 total) { |
688 NotifyProgress(current, total); | 690 NotifyProgress(current, total); |
| 691 if (!progress_callback_.is_null()) |
| 692 progress_callback_.Run(current, total); |
689 } | 693 } |
690 | 694 |
691 bool DownloadFileOperation::ShouldSendDownloadData() { | 695 bool DownloadFileOperation::ShouldSendDownloadData() { |
692 return !get_content_callback_.is_null(); | 696 return !get_content_callback_.is_null(); |
693 } | 697 } |
694 | 698 |
695 void DownloadFileOperation::OnURLFetchDownloadData( | 699 void DownloadFileOperation::OnURLFetchDownloadData( |
696 const URLFetcher* source, | 700 const URLFetcher* source, |
697 scoped_ptr<std::string> download_data) { | 701 scoped_ptr<std::string> download_data) { |
698 if (!get_content_callback_.is_null()) | 702 if (!get_content_callback_.is_null()) |
(...skipping 13 matching lines...) Expand all Loading... |
712 | 716 |
713 download_action_callback_.Run(code, temp_file); | 717 download_action_callback_.Run(code, temp_file); |
714 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 718 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
715 } | 719 } |
716 | 720 |
717 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 721 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
718 download_action_callback_.Run(code, base::FilePath()); | 722 download_action_callback_.Run(code, base::FilePath()); |
719 } | 723 } |
720 | 724 |
721 } // namespace google_apis | 725 } // namespace google_apis |
OLD | NEW |