| Index: chrome/browser/google_apis/base_operations.cc
|
| diff --git a/chrome/browser/google_apis/base_operations.cc b/chrome/browser/google_apis/base_operations.cc
|
| index 37e7581cff942058a184f7847ffa04f6d2e5a7b0..997e70e2fc3fe8837038e5e38864b6852dd217df 100644
|
| --- a/chrome/browser/google_apis/base_operations.cc
|
| +++ b/chrome/browser/google_apis/base_operations.cc
|
| @@ -358,4 +358,74 @@ void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code,
|
| callback_.Run(fetch_error_code, value.Pass());
|
| }
|
|
|
| +//============================ DownloadFileOperation ===========================
|
| +
|
| +DownloadFileOperation::DownloadFileOperation(
|
| + OperationRegistry* registry,
|
| + net::URLRequestContextGetter* url_request_context_getter,
|
| + const DownloadActionCallback& download_action_callback,
|
| + const GetContentCallback& get_content_callback,
|
| + const GURL& download_url,
|
| + const FilePath& drive_file_path,
|
| + const FilePath& output_file_path)
|
| + : UrlFetchOperationBase(registry,
|
| + url_request_context_getter,
|
| + OPERATION_DOWNLOAD,
|
| + drive_file_path),
|
| + download_action_callback_(download_action_callback),
|
| + get_content_callback_(get_content_callback),
|
| + download_url_(download_url) {
|
| + DCHECK(!download_action_callback_.is_null());
|
| + // get_content_callback may be null.
|
| +
|
| + // Make sure we download the content into a temp file.
|
| + if (output_file_path.empty())
|
| + set_save_temp_file(true);
|
| + else
|
| + set_output_file_path(output_file_path);
|
| +}
|
| +
|
| +DownloadFileOperation::~DownloadFileOperation() {}
|
| +
|
| +// Overridden from UrlFetchOperationBase.
|
| +GURL DownloadFileOperation::GetURL() const {
|
| + return download_url_;
|
| +}
|
| +
|
| +void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source,
|
| + int64 current,
|
| + int64 total) {
|
| + NotifyProgress(current, total);
|
| +}
|
| +
|
| +bool DownloadFileOperation::ShouldSendDownloadData() {
|
| + return !get_content_callback_.is_null();
|
| +}
|
| +
|
| +void DownloadFileOperation::OnURLFetchDownloadData(
|
| + const URLFetcher* source,
|
| + scoped_ptr<std::string> download_data) {
|
| + if (!get_content_callback_.is_null())
|
| + get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass());
|
| +}
|
| +
|
| +void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) {
|
| + GDataErrorCode code = GetErrorCode(source);
|
| +
|
| + // Take over the ownership of the the downloaded temp file.
|
| + FilePath temp_file;
|
| + if (code == HTTP_SUCCESS &&
|
| + !source->GetResponseAsFilePath(true, // take_ownership
|
| + &temp_file)) {
|
| + code = GDATA_FILE_ERROR;
|
| + }
|
| +
|
| + download_action_callback_.Run(code, temp_file);
|
| + OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
|
| +}
|
| +
|
| +void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) {
|
| + download_action_callback_.Run(code, FilePath());
|
| +}
|
| +
|
| } // namespace google_apis
|
|
|