| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/file_manager/private_api_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 550 | 550 |
| 551 if (error == drive::FILE_ERROR_OK) { | 551 if (error == drive::FILE_ERROR_OK) { |
| 552 SendResponse(true); | 552 SendResponse(true); |
| 553 } else { | 553 } else { |
| 554 SetError(drive::FileErrorToString(error)); | 554 SetError(drive::FileErrorToString(error)); |
| 555 SendResponse(false); | 555 SendResponse(false); |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 | 558 |
| 559 FileManagerPrivateGetDriveFilesFunction:: | |
| 560 FileManagerPrivateGetDriveFilesFunction() { | |
| 561 } | |
| 562 | |
| 563 FileManagerPrivateGetDriveFilesFunction:: | |
| 564 ~FileManagerPrivateGetDriveFilesFunction() { | |
| 565 } | |
| 566 | |
| 567 bool FileManagerPrivateGetDriveFilesFunction::RunAsync() { | |
| 568 using extensions::api::file_manager_private::GetDriveFiles::Params; | |
| 569 const scoped_ptr<Params> params(Params::Create(*args_)); | |
| 570 EXTENSION_FUNCTION_VALIDATE(params); | |
| 571 | |
| 572 // Convert the list of strings to a list of GURLs. | |
| 573 for (size_t i = 0; i < params->file_urls.size(); ++i) { | |
| 574 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | |
| 575 render_view_host(), GetProfile(), GURL(params->file_urls[i])); | |
| 576 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | |
| 577 base::FilePath drive_path = drive::util::ExtractDrivePath(path); | |
| 578 remaining_drive_paths_.push(drive_path); | |
| 579 } | |
| 580 | |
| 581 GetFileOrSendResponse(); | |
| 582 return true; | |
| 583 } | |
| 584 | |
| 585 void FileManagerPrivateGetDriveFilesFunction::GetFileOrSendResponse() { | |
| 586 // Send the response if all files are obtained. | |
| 587 if (remaining_drive_paths_.empty()) { | |
| 588 results_ = extensions::api::file_manager_private:: | |
| 589 GetDriveFiles::Results::Create(local_paths_); | |
| 590 SendResponse(true); | |
| 591 return; | |
| 592 } | |
| 593 | |
| 594 // Get the file on the top of the queue. | |
| 595 base::FilePath drive_path = remaining_drive_paths_.front(); | |
| 596 | |
| 597 drive::FileSystemInterface* file_system = | |
| 598 drive::util::GetFileSystemByProfile(GetProfile()); | |
| 599 if (!file_system) { | |
| 600 // |file_system| is NULL if Drive is disabled or not mounted. | |
| 601 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, | |
| 602 scoped_ptr<drive::ResourceEntry>()); | |
| 603 return; | |
| 604 } | |
| 605 | |
| 606 file_system->GetFile( | |
| 607 drive_path, | |
| 608 base::Bind(&FileManagerPrivateGetDriveFilesFunction::OnFileReady, this)); | |
| 609 } | |
| 610 | |
| 611 | |
| 612 void FileManagerPrivateGetDriveFilesFunction::OnFileReady( | |
| 613 drive::FileError error, | |
| 614 const base::FilePath& local_path, | |
| 615 scoped_ptr<drive::ResourceEntry> entry) { | |
| 616 base::FilePath drive_path = remaining_drive_paths_.front(); | |
| 617 | |
| 618 if (error == drive::FILE_ERROR_OK) { | |
| 619 local_paths_.push_back(local_path.AsUTF8Unsafe()); | |
| 620 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); | |
| 621 } else { | |
| 622 local_paths_.push_back(""); | |
| 623 DVLOG(1) << "Failed to get " << drive_path.value() | |
| 624 << " with error code: " << error; | |
| 625 } | |
| 626 | |
| 627 remaining_drive_paths_.pop(); | |
| 628 | |
| 629 // Start getting the next file. | |
| 630 GetFileOrSendResponse(); | |
| 631 } | |
| 632 | |
| 633 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() { | 559 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() { |
| 634 using extensions::api::file_manager_private::CancelFileTransfers::Params; | 560 using extensions::api::file_manager_private::CancelFileTransfers::Params; |
| 635 const scoped_ptr<Params> params(Params::Create(*args_)); | 561 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 636 EXTENSION_FUNCTION_VALIDATE(params); | 562 EXTENSION_FUNCTION_VALIDATE(params); |
| 637 | 563 |
| 638 drive::DriveIntegrationService* integration_service = | 564 drive::DriveIntegrationService* integration_service = |
| 639 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); | 565 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); |
| 640 if (!integration_service || !integration_service->IsMounted()) | 566 if (!integration_service || !integration_service->IsMounted()) |
| 641 return false; | 567 return false; |
| 642 | 568 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 return; | 1032 return; |
| 1107 } | 1033 } |
| 1108 | 1034 |
| 1109 const std::string url = download_url_ + "?access_token=" + access_token; | 1035 const std::string url = download_url_ + "?access_token=" + access_token; |
| 1110 SetResult(new base::StringValue(url)); | 1036 SetResult(new base::StringValue(url)); |
| 1111 | 1037 |
| 1112 SendResponse(true); | 1038 SendResponse(true); |
| 1113 } | 1039 } |
| 1114 | 1040 |
| 1115 } // namespace extensions | 1041 } // namespace extensions |
| OLD | NEW |