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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 DCHECK(!value.get()); | 351 DCHECK(!value.get()); |
352 OnProcessURLFetchResultsComplete(success); | 352 OnProcessURLFetchResultsComplete(success); |
353 } | 353 } |
354 | 354 |
355 void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, | 355 void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, |
356 scoped_ptr<base::Value> value) { | 356 scoped_ptr<base::Value> value) { |
357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
358 callback_.Run(fetch_error_code, value.Pass()); | 358 callback_.Run(fetch_error_code, value.Pass()); |
359 } | 359 } |
360 | 360 |
| 361 //============================ DownloadFileOperation =========================== |
| 362 |
| 363 DownloadFileOperation::DownloadFileOperation( |
| 364 OperationRegistry* registry, |
| 365 net::URLRequestContextGetter* url_request_context_getter, |
| 366 const DownloadActionCallback& download_action_callback, |
| 367 const GetContentCallback& get_content_callback, |
| 368 const GURL& download_url, |
| 369 const FilePath& drive_file_path, |
| 370 const FilePath& output_file_path) |
| 371 : UrlFetchOperationBase(registry, |
| 372 url_request_context_getter, |
| 373 OPERATION_DOWNLOAD, |
| 374 drive_file_path), |
| 375 download_action_callback_(download_action_callback), |
| 376 get_content_callback_(get_content_callback), |
| 377 download_url_(download_url) { |
| 378 DCHECK(!download_action_callback_.is_null()); |
| 379 // get_content_callback may be null. |
| 380 |
| 381 // Make sure we download the content into a temp file. |
| 382 if (output_file_path.empty()) |
| 383 set_save_temp_file(true); |
| 384 else |
| 385 set_output_file_path(output_file_path); |
| 386 } |
| 387 |
| 388 DownloadFileOperation::~DownloadFileOperation() {} |
| 389 |
| 390 // Overridden from UrlFetchOperationBase. |
| 391 GURL DownloadFileOperation::GetURL() const { |
| 392 return download_url_; |
| 393 } |
| 394 |
| 395 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, |
| 396 int64 current, |
| 397 int64 total) { |
| 398 NotifyProgress(current, total); |
| 399 } |
| 400 |
| 401 bool DownloadFileOperation::ShouldSendDownloadData() { |
| 402 return !get_content_callback_.is_null(); |
| 403 } |
| 404 |
| 405 void DownloadFileOperation::OnURLFetchDownloadData( |
| 406 const URLFetcher* source, |
| 407 scoped_ptr<std::string> download_data) { |
| 408 if (!get_content_callback_.is_null()) |
| 409 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); |
| 410 } |
| 411 |
| 412 void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) { |
| 413 GDataErrorCode code = GetErrorCode(source); |
| 414 |
| 415 // Take over the ownership of the the downloaded temp file. |
| 416 FilePath temp_file; |
| 417 if (code == HTTP_SUCCESS && |
| 418 !source->GetResponseAsFilePath(true, // take_ownership |
| 419 &temp_file)) { |
| 420 code = GDATA_FILE_ERROR; |
| 421 } |
| 422 |
| 423 download_action_callback_.Run(code, temp_file); |
| 424 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 425 } |
| 426 |
| 427 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
| 428 download_action_callback_.Run(code, FilePath()); |
| 429 } |
| 430 |
361 } // namespace google_apis | 431 } // namespace google_apis |
OLD | NEW |