Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc

Issue 576063002: Modify the behavior of cancel button in syncing status to cancel all jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 569 // Create the mapping from file path to job ID.
570 drive::JobListInterface* job_list = integration_service->job_list(); 570 drive::JobListInterface* job_list = integration_service->job_list();
571 DCHECK(job_list); 571 DCHECK(job_list);
572 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); 572 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList();
573 573
574 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; 574 // If params->file_urls are empty, cancel all jobs.
575 PathToIdMap path_to_id_map; 575 if (params->file_urls.size() == 0) {
576 for (size_t i = 0; i < jobs.size(); ++i) { 576 for (size_t i = 0; i < jobs.size(); ++i) {
577 if (drive::IsActiveFileTransferJobInfo(jobs[i])) 577 if (drive::IsActiveFileTransferJobInfo(jobs[i]))
578 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); 578 job_list->CancelJob(jobs[i].job_id);
579 }
580 } else {
kinaba 2014/09/18 05:39:16 The "// Create the mapping from file path to job I
iseki 2014/09/18 05:45:44 Done.
581 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap;
582 PathToIdMap path_to_id_map;
583 for (size_t i = 0; i < jobs.size(); ++i) {
584 if (drive::IsActiveFileTransferJobInfo(jobs[i]))
585 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id);
586 }
587
588 for (size_t i = 0; i < params->file_urls.size(); ++i) {
589 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
590 render_view_host(), GetProfile(), GURL(params->file_urls[i]));
591 if (file_path.empty())
592 continue;
593
594 DCHECK(drive::util::IsUnderDriveMountPoint(file_path));
595 file_path = drive::util::ExtractDrivePath(file_path);
596
597 // Cancel all the jobs for the file.
598 PathToIdMap::iterator it = path_to_id_map.find(file_path);
599 if (it != path_to_id_map.end()) {
600 for (size_t i = 0; i < it->second.size(); ++i)
601 job_list->CancelJob(it->second[i]);
602 }
603 }
579 } 604 }
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); 605 SendResponse(true);
610 return true; 606 return true;
611 } 607 }
612 608
613 bool FileManagerPrivateSearchDriveFunction::RunAsync() { 609 bool FileManagerPrivateSearchDriveFunction::RunAsync() {
614 using extensions::api::file_manager_private::SearchDrive::Params; 610 using extensions::api::file_manager_private::SearchDrive::Params;
615 const scoped_ptr<Params> params(Params::Create(*args_)); 611 const scoped_ptr<Params> params(Params::Create(*args_));
616 EXTENSION_FUNCTION_VALIDATE(params); 612 EXTENSION_FUNCTION_VALIDATE(params);
617 613
618 drive::FileSystemInterface* const file_system = 614 drive::FileSystemInterface* const file_system =
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 return; 1028 return;
1033 } 1029 }
1034 1030
1035 const std::string url = download_url_ + "?access_token=" + access_token; 1031 const std::string url = download_url_ + "?access_token=" + access_token;
1036 SetResult(new base::StringValue(url)); 1032 SetResult(new base::StringValue(url));
1037 1033
1038 SendResponse(true); 1034 SendResponse(true);
1039 } 1035 }
1040 1036
1041 } // namespace extensions 1037 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698