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/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // changelists from GetResourceList(). | 480 // changelists from GetResourceList(). |
481 MessageLoop::current()->PostTask( | 481 MessageLoop::current()->PostTask( |
482 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); | 482 FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND)); |
483 } | 483 } |
484 | 484 |
485 void FakeDriveService::DownloadFile( | 485 void FakeDriveService::DownloadFile( |
486 const base::FilePath& virtual_path, | 486 const base::FilePath& virtual_path, |
487 const base::FilePath& local_cache_path, | 487 const base::FilePath& local_cache_path, |
488 const GURL& download_url, | 488 const GURL& download_url, |
489 const DownloadActionCallback& download_action_callback, | 489 const DownloadActionCallback& download_action_callback, |
490 const GetContentCallback& get_content_callback) { | 490 const GetContentCallback& get_content_callback, |
| 491 const ProgressCallback& progress_callback) { |
491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
492 DCHECK(!download_action_callback.is_null()); | 493 DCHECK(!download_action_callback.is_null()); |
493 | 494 |
494 if (offline_) { | 495 if (offline_) { |
495 MessageLoop::current()->PostTask( | 496 MessageLoop::current()->PostTask( |
496 FROM_HERE, | 497 FROM_HERE, |
497 base::Bind(download_action_callback, | 498 base::Bind(download_action_callback, |
498 GDATA_NO_CONNECTION, | 499 GDATA_NO_CONNECTION, |
499 base::FilePath())); | 500 base::FilePath())); |
500 return; | 501 return; |
501 } | 502 } |
502 | 503 |
503 // The field content.src is the URL to donwload the file. | 504 // The field content.src is the URL to download the file. |
504 base::DictionaryValue* entry = FindEntryByContentUrl(download_url); | 505 base::DictionaryValue* entry = FindEntryByContentUrl(download_url); |
505 if (!entry) { | 506 if (!entry) { |
506 base::MessageLoopProxy::current()->PostTask( | 507 base::MessageLoopProxy::current()->PostTask( |
507 FROM_HERE, | 508 FROM_HERE, |
508 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); | 509 base::Bind(download_action_callback, HTTP_NOT_FOUND, base::FilePath())); |
509 return; | 510 return; |
510 } | 511 } |
511 | 512 |
512 // Write "x"s of the file size specified in the entry. | 513 // Write "x"s of the file size specified in the entry. |
513 std::string file_size_string; | 514 std::string file_size_string; |
514 entry->GetString("docs$size.$t", &file_size_string); | 515 entry->GetString("docs$size.$t", &file_size_string); |
515 // TODO(satorux): To be correct, we should update docs$md5Checksum.$t here. | 516 // TODO(satorux): To be correct, we should update docs$md5Checksum.$t here. |
516 int64 file_size = 0; | 517 int64 file_size = 0; |
517 if (base::StringToInt64(file_size_string, &file_size)) { | 518 if (base::StringToInt64(file_size_string, &file_size)) { |
518 std::string content(file_size, 'x'); | 519 std::string content(file_size, 'x'); |
519 DCHECK_EQ(static_cast<size_t>(file_size), content.size()); | 520 DCHECK_EQ(static_cast<size_t>(file_size), content.size()); |
520 | 521 |
521 if (static_cast<int>(content.size()) == | 522 if (static_cast<int>(content.size()) == |
522 file_util::WriteFile(local_cache_path, | 523 file_util::WriteFile(local_cache_path, |
523 content.data(), | 524 content.data(), |
524 content.size())) { | 525 content.size())) { |
| 526 if (!progress_callback.is_null()) { |
| 527 // See also the comment in ResumeUpload(). For testing that clients |
| 528 // can handle the case progress_callback is called multiple times, |
| 529 // here we invoke the callback twice. |
| 530 base::MessageLoopProxy::current()->PostTask( |
| 531 FROM_HERE, |
| 532 base::Bind(progress_callback, file_size / 2, file_size)); |
| 533 base::MessageLoopProxy::current()->PostTask( |
| 534 FROM_HERE, |
| 535 base::Bind(progress_callback, file_size, file_size)); |
| 536 } |
525 base::MessageLoopProxy::current()->PostTask( | 537 base::MessageLoopProxy::current()->PostTask( |
526 FROM_HERE, | 538 FROM_HERE, |
527 base::Bind(download_action_callback, | 539 base::Bind(download_action_callback, |
528 HTTP_SUCCESS, | 540 HTTP_SUCCESS, |
529 local_cache_path)); | 541 local_cache_path)); |
530 return; | 542 return; |
531 } | 543 } |
532 } | 544 } |
533 | 545 |
534 // Failed to write the content. | 546 // Failed to write the content. |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 | 1323 |
1312 ++resource_list_load_count_; | 1324 ++resource_list_load_count_; |
1313 MessageLoop::current()->PostTask( | 1325 MessageLoop::current()->PostTask( |
1314 FROM_HERE, | 1326 FROM_HERE, |
1315 base::Bind(callback, | 1327 base::Bind(callback, |
1316 HTTP_SUCCESS, | 1328 HTTP_SUCCESS, |
1317 base::Passed(&resource_list))); | 1329 base::Passed(&resource_list))); |
1318 } | 1330 } |
1319 | 1331 |
1320 } // namespace google_apis | 1332 } // namespace google_apis |
OLD | NEW |