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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() { | 559 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() { |
560 using extensions::api::file_manager_private::CancelFileTransfers::Params; | 560 using extensions::api::file_manager_private::CancelFileTransfers::Params; |
561 const scoped_ptr<Params> params(Params::Create(*args_)); | 561 const scoped_ptr<Params> params(Params::Create(*args_)); |
562 EXTENSION_FUNCTION_VALIDATE(params); | 562 EXTENSION_FUNCTION_VALIDATE(params); |
563 | 563 |
564 drive::DriveIntegrationService* integration_service = | 564 drive::DriveIntegrationService* integration_service = |
565 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); | 565 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); |
566 if (!integration_service || !integration_service->IsMounted()) | 566 if (!integration_service || !integration_service->IsMounted()) |
567 return false; | 567 return false; |
568 | 568 |
569 // Create the mapping from file path to job ID. | |
570 drive::JobListInterface* job_list = integration_service->job_list(); | 569 drive::JobListInterface* job_list = integration_service->job_list(); |
571 DCHECK(job_list); | 570 DCHECK(job_list); |
572 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); | 571 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); |
573 | 572 |
574 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; | 573 // If file_urls are empty, cancel all jobs. |
575 PathToIdMap path_to_id_map; | 574 if (!params->file_urls.get()) { |
576 for (size_t i = 0; i < jobs.size(); ++i) { | 575 for (size_t i = 0; i < jobs.size(); ++i) { |
577 if (drive::IsActiveFileTransferJobInfo(jobs[i])) | 576 if (drive::IsActiveFileTransferJobInfo(jobs[i])) |
578 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); | 577 job_list->CancelJob(jobs[i].job_id); |
578 } | |
579 } else { | |
580 // Create the mapping from file path to job ID. | |
581 std::vector<std::string> file_urls(*params->file_urls.get()); | |
582 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; | |
583 PathToIdMap path_to_id_map; | |
584 for (size_t i = 0; i < jobs.size(); ++i) { | |
585 if (drive::IsActiveFileTransferJobInfo(jobs[i])) | |
586 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); | |
587 } | |
588 | |
589 for (size_t i = 0; i < file_urls.size(); ++i) { | |
590 base::FilePath file_path = file_manager::util::GetLocalPathFromURL( | |
591 render_view_host(), GetProfile(), GURL(file_urls[i])); | |
592 if (file_path.empty()) | |
593 continue; | |
594 | |
595 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); | |
596 file_path = drive::util::ExtractDrivePath(file_path); | |
hirono
2014/09/18 08:17:59
Actually IsUnderDriveMountPoint calles ExtractDriv
iseki
2014/09/18 08:25:11
Done.
| |
597 | |
598 // Cancel all the jobs for the file. | |
599 PathToIdMap::iterator it = path_to_id_map.find(file_path); | |
600 if (it != path_to_id_map.end()) { | |
601 for (size_t i = 0; i < it->second.size(); ++i) | |
602 job_list->CancelJob(it->second[i]); | |
603 } | |
604 } | |
579 } | 605 } |
580 | |
581 // Cancel by Job ID. | |
582 std::vector<linked_ptr<api::file_manager_private:: | |
583 FileTransferCancelStatus> > responses; | |
584 for (size_t i = 0; i < params->file_urls.size(); ++i) { | |
585 base::FilePath file_path = file_manager::util::GetLocalPathFromURL( | |
586 render_view_host(), GetProfile(), GURL(params->file_urls[i])); | |
587 if (file_path.empty()) | |
588 continue; | |
589 | |
590 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); | |
591 file_path = drive::util::ExtractDrivePath(file_path); | |
592 | |
593 // Cancel all the jobs for the file. | |
594 PathToIdMap::iterator it = path_to_id_map.find(file_path); | |
595 if (it != path_to_id_map.end()) { | |
596 for (size_t i = 0; i < it->second.size(); ++i) | |
597 job_list->CancelJob(it->second[i]); | |
598 } | |
599 linked_ptr<api::file_manager_private::FileTransferCancelStatus> result( | |
600 new api::file_manager_private::FileTransferCancelStatus); | |
601 result->canceled = it != path_to_id_map.end(); | |
602 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, | |
603 // and eliminate this field; it is just returning a copy of the argument. | |
604 result->file_url = params->file_urls[i]; | |
605 responses.push_back(result); | |
606 } | |
607 results_ = api::file_manager_private::CancelFileTransfers::Results::Create( | |
608 responses); | |
609 SendResponse(true); | 606 SendResponse(true); |
610 return true; | 607 return true; |
611 } | 608 } |
612 | 609 |
613 bool FileManagerPrivateSearchDriveFunction::RunAsync() { | 610 bool FileManagerPrivateSearchDriveFunction::RunAsync() { |
614 using extensions::api::file_manager_private::SearchDrive::Params; | 611 using extensions::api::file_manager_private::SearchDrive::Params; |
615 const scoped_ptr<Params> params(Params::Create(*args_)); | 612 const scoped_ptr<Params> params(Params::Create(*args_)); |
616 EXTENSION_FUNCTION_VALIDATE(params); | 613 EXTENSION_FUNCTION_VALIDATE(params); |
617 | 614 |
618 drive::FileSystemInterface* const file_system = | 615 drive::FileSystemInterface* const file_system = |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 return; | 1029 return; |
1033 } | 1030 } |
1034 | 1031 |
1035 const std::string url = download_url_ + "?access_token=" + access_token; | 1032 const std::string url = download_url_ + "?access_token=" + access_token; |
1036 SetResult(new base::StringValue(url)); | 1033 SetResult(new base::StringValue(url)); |
1037 | 1034 |
1038 SendResponse(true); | 1035 SendResponse(true); |
1039 } | 1036 } |
1040 | 1037 |
1041 } // namespace extensions | 1038 } // namespace extensions |
OLD | NEW |