| 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_file_syste
m.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste
m.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> |
| 8 |
| 8 #include <set> | 9 #include <set> |
| 9 | 10 |
| 11 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/posix/eintr_wrapper.h" | 13 #include "base/posix/eintr_wrapper.h" |
| 12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 16 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/drive/file_system_util.h" | 21 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 render_frame_host()->GetProcess()->GetID(), content::kExternalFileScheme); | 279 render_frame_host()->GetProcess()->GetID(), content::kExternalFileScheme); |
| 278 return RespondNow(NoArguments()); | 280 return RespondNow(NoArguments()); |
| 279 } | 281 } |
| 280 | 282 |
| 281 FileManagerPrivateGrantAccessFunction::FileManagerPrivateGrantAccessFunction() | 283 FileManagerPrivateGrantAccessFunction::FileManagerPrivateGrantAccessFunction() |
| 282 : chrome_details_(this) { | 284 : chrome_details_(this) { |
| 283 } | 285 } |
| 284 | 286 |
| 285 ExtensionFunction::ResponseAction FileManagerPrivateGrantAccessFunction::Run() { | 287 ExtensionFunction::ResponseAction FileManagerPrivateGrantAccessFunction::Run() { |
| 286 using extensions::api::file_manager_private::GrantAccess::Params; | 288 using extensions::api::file_manager_private::GrantAccess::Params; |
| 287 const scoped_ptr<Params> params(Params::Create(*args_)); | 289 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 288 EXTENSION_FUNCTION_VALIDATE(params); | 290 EXTENSION_FUNCTION_VALIDATE(params); |
| 289 | 291 |
| 290 scoped_refptr<storage::FileSystemContext> file_system_context = | 292 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 291 file_manager::util::GetFileSystemContextForRenderFrameHost( | 293 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 292 chrome_details_.GetProfile(), render_frame_host()); | 294 chrome_details_.GetProfile(), render_frame_host()); |
| 293 | 295 |
| 294 storage::ExternalFileSystemBackend* const backend = | 296 storage::ExternalFileSystemBackend* const backend = |
| 295 file_system_context->external_backend(); | 297 file_system_context->external_backend(); |
| 296 DCHECK(backend); | 298 DCHECK(backend); |
| 297 | 299 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return; | 409 return; |
| 408 } | 410 } |
| 409 | 411 |
| 410 // Obsolete. Fallback code if storage::WatcherManager is not implemented. | 412 // Obsolete. Fallback code if storage::WatcherManager is not implemented. |
| 411 event_router->RemoveFileWatch(file_system_url.path(), extension_id); | 413 event_router->RemoveFileWatch(file_system_url.path(), extension_id); |
| 412 Respond(true); | 414 Respond(true); |
| 413 } | 415 } |
| 414 | 416 |
| 415 bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { | 417 bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { |
| 416 using extensions::api::file_manager_private::GetSizeStats::Params; | 418 using extensions::api::file_manager_private::GetSizeStats::Params; |
| 417 const scoped_ptr<Params> params(Params::Create(*args_)); | 419 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 418 EXTENSION_FUNCTION_VALIDATE(params); | 420 EXTENSION_FUNCTION_VALIDATE(params); |
| 419 | 421 |
| 420 using file_manager::VolumeManager; | 422 using file_manager::VolumeManager; |
| 421 using file_manager::Volume; | 423 using file_manager::Volume; |
| 422 VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); | 424 VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); |
| 423 if (!volume_manager) | 425 if (!volume_manager) |
| 424 return false; | 426 return false; |
| 425 | 427 |
| 426 base::WeakPtr<Volume> volume = | 428 base::WeakPtr<Volume> volume = |
| 427 volume_manager->FindVolumeById(params->volume_id); | 429 volume_manager->FindVolumeById(params->volume_id); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 536 |
| 535 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); | 537 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); |
| 536 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); | 538 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); |
| 537 | 539 |
| 538 SendResponse(true); | 540 SendResponse(true); |
| 539 } | 541 } |
| 540 | 542 |
| 541 bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { | 543 bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { |
| 542 using extensions::api::file_manager_private_internal::ValidatePathNameLength:: | 544 using extensions::api::file_manager_private_internal::ValidatePathNameLength:: |
| 543 Params; | 545 Params; |
| 544 const scoped_ptr<Params> params(Params::Create(*args_)); | 546 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 545 EXTENSION_FUNCTION_VALIDATE(params); | 547 EXTENSION_FUNCTION_VALIDATE(params); |
| 546 | 548 |
| 547 scoped_refptr<storage::FileSystemContext> file_system_context = | 549 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 548 file_manager::util::GetFileSystemContextForRenderFrameHost( | 550 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 549 GetProfile(), render_frame_host()); | 551 GetProfile(), render_frame_host()); |
| 550 | 552 |
| 551 const storage::FileSystemURL file_system_url( | 553 const storage::FileSystemURL file_system_url( |
| 552 file_system_context->CrackURL(GURL(params->parent_url))); | 554 file_system_context->CrackURL(GURL(params->parent_url))); |
| 553 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) | 555 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) |
| 554 return false; | 556 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 571 } | 573 } |
| 572 | 574 |
| 573 void FileManagerPrivateInternalValidatePathNameLengthFunction:: | 575 void FileManagerPrivateInternalValidatePathNameLengthFunction:: |
| 574 OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { | 576 OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { |
| 575 SetResult(new base::FundamentalValue(current_length <= max_length)); | 577 SetResult(new base::FundamentalValue(current_length <= max_length)); |
| 576 SendResponse(true); | 578 SendResponse(true); |
| 577 } | 579 } |
| 578 | 580 |
| 579 bool FileManagerPrivateFormatVolumeFunction::RunAsync() { | 581 bool FileManagerPrivateFormatVolumeFunction::RunAsync() { |
| 580 using extensions::api::file_manager_private::FormatVolume::Params; | 582 using extensions::api::file_manager_private::FormatVolume::Params; |
| 581 const scoped_ptr<Params> params(Params::Create(*args_)); | 583 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 582 EXTENSION_FUNCTION_VALIDATE(params); | 584 EXTENSION_FUNCTION_VALIDATE(params); |
| 583 | 585 |
| 584 using file_manager::VolumeManager; | 586 using file_manager::VolumeManager; |
| 585 using file_manager::Volume; | 587 using file_manager::Volume; |
| 586 VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); | 588 VolumeManager* const volume_manager = VolumeManager::Get(GetProfile()); |
| 587 if (!volume_manager) | 589 if (!volume_manager) |
| 588 return false; | 590 return false; |
| 589 | 591 |
| 590 base::WeakPtr<Volume> volume = | 592 base::WeakPtr<Volume> volume = |
| 591 volume_manager->FindVolumeById(params->volume_id); | 593 volume_manager->FindVolumeById(params->volume_id); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 613 bool CheckLocalDiskSpaceOnIOThread(const base::FilePath& path, int64_t bytes) { | 615 bool CheckLocalDiskSpaceOnIOThread(const base::FilePath& path, int64_t bytes) { |
| 614 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 616 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 615 return bytes <= base::SysInfo::AmountOfFreeDiskSpace(path) - | 617 return bytes <= base::SysInfo::AmountOfFreeDiskSpace(path) - |
| 616 cryptohome::kMinFreeSpaceInBytes; | 618 cryptohome::kMinFreeSpaceInBytes; |
| 617 } | 619 } |
| 618 | 620 |
| 619 bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { | 621 bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { |
| 620 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 622 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 621 | 623 |
| 622 using extensions::api::file_manager_private_internal::StartCopy::Params; | 624 using extensions::api::file_manager_private_internal::StartCopy::Params; |
| 623 const scoped_ptr<Params> params(Params::Create(*args_)); | 625 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 624 EXTENSION_FUNCTION_VALIDATE(params); | 626 EXTENSION_FUNCTION_VALIDATE(params); |
| 625 | 627 |
| 626 if (params->url.empty() || params->parent_url.empty() || | 628 if (params->url.empty() || params->parent_url.empty() || |
| 627 params->new_name.empty()) { | 629 params->new_name.empty()) { |
| 628 // Error code in format of DOMError.name. | 630 // Error code in format of DOMError.name. |
| 629 SetError("EncodingError"); | 631 SetError("EncodingError"); |
| 630 return false; | 632 return false; |
| 631 } | 633 } |
| 632 | 634 |
| 633 scoped_refptr<storage::FileSystemContext> file_system_context = | 635 scoped_refptr<storage::FileSystemContext> file_system_context = |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 735 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 734 | 736 |
| 735 SetResult(new base::FundamentalValue(operation_id)); | 737 SetResult(new base::FundamentalValue(operation_id)); |
| 736 SendResponse(true); | 738 SendResponse(true); |
| 737 } | 739 } |
| 738 | 740 |
| 739 bool FileManagerPrivateCancelCopyFunction::RunAsync() { | 741 bool FileManagerPrivateCancelCopyFunction::RunAsync() { |
| 740 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 742 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 741 | 743 |
| 742 using extensions::api::file_manager_private::CancelCopy::Params; | 744 using extensions::api::file_manager_private::CancelCopy::Params; |
| 743 const scoped_ptr<Params> params(Params::Create(*args_)); | 745 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 744 EXTENSION_FUNCTION_VALIDATE(params); | 746 EXTENSION_FUNCTION_VALIDATE(params); |
| 745 | 747 |
| 746 scoped_refptr<storage::FileSystemContext> file_system_context = | 748 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 747 file_manager::util::GetFileSystemContextForRenderFrameHost( | 749 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 748 GetProfile(), render_frame_host()); | 750 GetProfile(), render_frame_host()); |
| 749 | 751 |
| 750 // We don't much take care about the result of cancellation. | 752 // We don't much take care about the result of cancellation. |
| 751 BrowserThread::PostTask( | 753 BrowserThread::PostTask( |
| 752 BrowserThread::IO, | 754 BrowserThread::IO, |
| 753 FROM_HERE, | 755 FROM_HERE, |
| 754 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); | 756 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); |
| 755 SendResponse(true); | 757 SendResponse(true); |
| 756 return true; | 758 return true; |
| 757 } | 759 } |
| 758 | 760 |
| 759 bool FileManagerPrivateInternalResolveIsolatedEntriesFunction::RunAsync() { | 761 bool FileManagerPrivateInternalResolveIsolatedEntriesFunction::RunAsync() { |
| 760 using extensions::api::file_manager_private_internal::ResolveIsolatedEntries:: | 762 using extensions::api::file_manager_private_internal::ResolveIsolatedEntries:: |
| 761 Params; | 763 Params; |
| 762 const scoped_ptr<Params> params(Params::Create(*args_)); | 764 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 763 EXTENSION_FUNCTION_VALIDATE(params); | 765 EXTENSION_FUNCTION_VALIDATE(params); |
| 764 | 766 |
| 765 scoped_refptr<storage::FileSystemContext> file_system_context = | 767 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 766 file_manager::util::GetFileSystemContextForRenderFrameHost( | 768 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 767 GetProfile(), render_frame_host()); | 769 GetProfile(), render_frame_host()); |
| 768 DCHECK(file_system_context.get()); | 770 DCHECK(file_system_context.get()); |
| 769 | 771 |
| 770 const storage::ExternalFileSystemBackend* external_backend = | 772 const storage::ExternalFileSystemBackend* external_backend = |
| 771 file_system_context->external_backend(); | 773 file_system_context->external_backend(); |
| 772 DCHECK(external_backend); | 774 DCHECK(external_backend); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 794 extension_->id(), | 796 extension_->id(), |
| 795 file_definition_list, // Safe, since copied internally. | 797 file_definition_list, // Safe, since copied internally. |
| 796 base::Bind( | 798 base::Bind( |
| 797 &FileManagerPrivateInternalResolveIsolatedEntriesFunction:: | 799 &FileManagerPrivateInternalResolveIsolatedEntriesFunction:: |
| 798 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList, | 800 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList, |
| 799 this)); | 801 this)); |
| 800 return true; | 802 return true; |
| 801 } | 803 } |
| 802 | 804 |
| 803 void FileManagerPrivateInternalResolveIsolatedEntriesFunction:: | 805 void FileManagerPrivateInternalResolveIsolatedEntriesFunction:: |
| 804 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr< | 806 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList( |
| 805 file_manager::util::EntryDefinitionList> entry_definition_list) { | 807 std::unique_ptr<file_manager::util::EntryDefinitionList> |
| 808 entry_definition_list) { |
| 806 using extensions::api::file_manager_private_internal::EntryDescription; | 809 using extensions::api::file_manager_private_internal::EntryDescription; |
| 807 std::vector<EntryDescription> entries; | 810 std::vector<EntryDescription> entries; |
| 808 | 811 |
| 809 for (const auto& definition : *entry_definition_list) { | 812 for (const auto& definition : *entry_definition_list) { |
| 810 if (definition.error != base::File::FILE_OK) | 813 if (definition.error != base::File::FILE_OK) |
| 811 continue; | 814 continue; |
| 812 EntryDescription entry; | 815 EntryDescription entry; |
| 813 entry.file_system_name = definition.file_system_name; | 816 entry.file_system_name = definition.file_system_name; |
| 814 entry.file_system_root = definition.file_system_root_url; | 817 entry.file_system_root = definition.file_system_root_url; |
| 815 entry.file_full_path = "/" + definition.full_path.AsUTF8Unsafe(); | 818 entry.file_full_path = "/" + definition.full_path.AsUTF8Unsafe(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 827 : digester_(new drive::util::FileStreamMd5Digester()) { | 830 : digester_(new drive::util::FileStreamMd5Digester()) { |
| 828 } | 831 } |
| 829 | 832 |
| 830 FileManagerPrivateInternalComputeChecksumFunction:: | 833 FileManagerPrivateInternalComputeChecksumFunction:: |
| 831 ~FileManagerPrivateInternalComputeChecksumFunction() { | 834 ~FileManagerPrivateInternalComputeChecksumFunction() { |
| 832 } | 835 } |
| 833 | 836 |
| 834 bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() { | 837 bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() { |
| 835 using extensions::api::file_manager_private_internal::ComputeChecksum::Params; | 838 using extensions::api::file_manager_private_internal::ComputeChecksum::Params; |
| 836 using drive::util::FileStreamMd5Digester; | 839 using drive::util::FileStreamMd5Digester; |
| 837 const scoped_ptr<Params> params(Params::Create(*args_)); | 840 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 838 EXTENSION_FUNCTION_VALIDATE(params); | 841 EXTENSION_FUNCTION_VALIDATE(params); |
| 839 | 842 |
| 840 if (params->url.empty()) { | 843 if (params->url.empty()) { |
| 841 SetError("File URL must be provided"); | 844 SetError("File URL must be provided"); |
| 842 return false; | 845 return false; |
| 843 } | 846 } |
| 844 | 847 |
| 845 scoped_refptr<storage::FileSystemContext> file_system_context = | 848 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 846 file_manager::util::GetFileSystemContextForRenderFrameHost( | 849 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 847 GetProfile(), render_frame_host()); | 850 GetProfile(), render_frame_host()); |
| 848 | 851 |
| 849 FileSystemURL file_system_url( | 852 FileSystemURL file_system_url( |
| 850 file_system_context->CrackURL(GURL(params->url))); | 853 file_system_context->CrackURL(GURL(params->url))); |
| 851 if (!file_system_url.is_valid()) { | 854 if (!file_system_url.is_valid()) { |
| 852 SetError("File URL was invalid"); | 855 SetError("File URL was invalid"); |
| 853 return false; | 856 return false; |
| 854 } | 857 } |
| 855 | 858 |
| 856 scoped_ptr<storage::FileStreamReader> reader = | 859 std::unique_ptr<storage::FileStreamReader> reader = |
| 857 file_system_context->CreateFileStreamReader( | 860 file_system_context->CreateFileStreamReader( |
| 858 file_system_url, 0, storage::kMaximumLength, base::Time()); | 861 file_system_url, 0, storage::kMaximumLength, base::Time()); |
| 859 | 862 |
| 860 FileStreamMd5Digester::ResultCallback result_callback = base::Bind( | 863 FileStreamMd5Digester::ResultCallback result_callback = base::Bind( |
| 861 &ComputeChecksumRespondOnUIThread, | 864 &ComputeChecksumRespondOnUIThread, |
| 862 base::Bind(&FileManagerPrivateInternalComputeChecksumFunction::Respond, | 865 base::Bind(&FileManagerPrivateInternalComputeChecksumFunction::Respond, |
| 863 this)); | 866 this)); |
| 864 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 867 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 865 base::Bind(&FileStreamMd5Digester::GetMd5Digest, | 868 base::Bind(&FileStreamMd5Digester::GetMd5Digest, |
| 866 base::Unretained(digester_.get()), | 869 base::Unretained(digester_.get()), |
| 867 base::Passed(&reader), result_callback)); | 870 base::Passed(&reader), result_callback)); |
| 868 | 871 |
| 869 return true; | 872 return true; |
| 870 } | 873 } |
| 871 | 874 |
| 872 void FileManagerPrivateInternalComputeChecksumFunction::Respond( | 875 void FileManagerPrivateInternalComputeChecksumFunction::Respond( |
| 873 const std::string& hash) { | 876 const std::string& hash) { |
| 874 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 877 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 875 SetResult(new base::StringValue(hash)); | 878 SetResult(new base::StringValue(hash)); |
| 876 SendResponse(true); | 879 SendResponse(true); |
| 877 } | 880 } |
| 878 | 881 |
| 879 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { | 882 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { |
| 880 using api::file_manager_private::SearchFilesByHashes::Params; | 883 using api::file_manager_private::SearchFilesByHashes::Params; |
| 881 const scoped_ptr<Params> params(Params::Create(*args_)); | 884 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 882 EXTENSION_FUNCTION_VALIDATE(params); | 885 EXTENSION_FUNCTION_VALIDATE(params); |
| 883 | 886 |
| 884 // TODO(hirono): Check the volume ID and fail the function for volumes other | 887 // TODO(hirono): Check the volume ID and fail the function for volumes other |
| 885 // than Drive. | 888 // than Drive. |
| 886 | 889 |
| 887 drive::EventLogger* const logger = | 890 drive::EventLogger* const logger = |
| 888 file_manager::util::GetLogger(GetProfile()); | 891 file_manager::util::GetLogger(GetProfile()); |
| 889 if (logger) { | 892 if (logger) { |
| 890 logger->Log(logging::LOG_INFO, | 893 logger->Log(logging::LOG_INFO, |
| 891 "%s[%d] called. (volume id: %s, number of hashes: %zd)", name(), | 894 "%s[%d] called. (volume id: %s, number of hashes: %zd)", name(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 913 | 916 |
| 914 void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes( | 917 void FileManagerPrivateSearchFilesByHashesFunction::OnSearchByHashes( |
| 915 const std::set<std::string>& hashes, | 918 const std::set<std::string>& hashes, |
| 916 drive::FileError error, | 919 drive::FileError error, |
| 917 const std::vector<drive::HashAndFilePath>& search_results) { | 920 const std::vector<drive::HashAndFilePath>& search_results) { |
| 918 if (error != drive::FileError::FILE_ERROR_OK) { | 921 if (error != drive::FileError::FILE_ERROR_OK) { |
| 919 SendResponse(false); | 922 SendResponse(false); |
| 920 return; | 923 return; |
| 921 } | 924 } |
| 922 | 925 |
| 923 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 926 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 924 for (const auto& hash : hashes) { | 927 for (const auto& hash : hashes) { |
| 925 result->SetWithoutPathExpansion(hash, | 928 result->SetWithoutPathExpansion(hash, |
| 926 make_scoped_ptr(new base::ListValue())); | 929 base::WrapUnique(new base::ListValue())); |
| 927 } | 930 } |
| 928 | 931 |
| 929 for (const auto& hashAndPath : search_results) { | 932 for (const auto& hashAndPath : search_results) { |
| 930 DCHECK(result->HasKey(hashAndPath.hash)); | 933 DCHECK(result->HasKey(hashAndPath.hash)); |
| 931 base::ListValue* list; | 934 base::ListValue* list; |
| 932 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); | 935 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); |
| 933 list->AppendString( | 936 list->AppendString( |
| 934 file_manager::util::ConvertDrivePathToFileSystemUrl( | 937 file_manager::util::ConvertDrivePathToFileSystemUrl( |
| 935 GetProfile(), hashAndPath.path, extension_id()).spec()); | 938 GetProfile(), hashAndPath.path, extension_id()).spec()); |
| 936 } | 939 } |
| 937 SetResult(result.release()); | 940 SetResult(result.release()); |
| 938 SendResponse(true); | 941 SendResponse(true); |
| 939 } | 942 } |
| 940 | 943 |
| 941 ExtensionFunction::ResponseAction | 944 ExtensionFunction::ResponseAction |
| 942 FileManagerPrivateIsUMAEnabledFunction::Run() { | 945 FileManagerPrivateIsUMAEnabledFunction::Run() { |
| 943 return RespondNow(OneArgument(new base::FundamentalValue( | 946 return RespondNow(OneArgument(new base::FundamentalValue( |
| 944 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); | 947 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); |
| 945 } | 948 } |
| 946 | 949 |
| 947 FileManagerPrivateInternalSetEntryTagFunction:: | 950 FileManagerPrivateInternalSetEntryTagFunction:: |
| 948 FileManagerPrivateInternalSetEntryTagFunction() | 951 FileManagerPrivateInternalSetEntryTagFunction() |
| 949 : chrome_details_(this) {} | 952 : chrome_details_(this) {} |
| 950 | 953 |
| 951 ExtensionFunction::ResponseAction | 954 ExtensionFunction::ResponseAction |
| 952 FileManagerPrivateInternalSetEntryTagFunction::Run() { | 955 FileManagerPrivateInternalSetEntryTagFunction::Run() { |
| 953 using extensions::api::file_manager_private_internal::SetEntryTag::Params; | 956 using extensions::api::file_manager_private_internal::SetEntryTag::Params; |
| 954 const scoped_ptr<Params> params(Params::Create(*args_)); | 957 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 955 EXTENSION_FUNCTION_VALIDATE(params); | 958 EXTENSION_FUNCTION_VALIDATE(params); |
| 956 | 959 |
| 957 const base::FilePath local_path = file_manager::util::GetLocalPathFromURL( | 960 const base::FilePath local_path = file_manager::util::GetLocalPathFromURL( |
| 958 render_frame_host(), chrome_details_.GetProfile(), GURL(params->url)); | 961 render_frame_host(), chrome_details_.GetProfile(), GURL(params->url)); |
| 959 const base::FilePath drive_path = drive::util::ExtractDrivePath(local_path); | 962 const base::FilePath drive_path = drive::util::ExtractDrivePath(local_path); |
| 960 if (drive_path.empty()) | 963 if (drive_path.empty()) |
| 961 return RespondNow(Error("Only Drive files and directories are supported.")); | 964 return RespondNow(Error("Only Drive files and directories are supported.")); |
| 962 | 965 |
| 963 drive::FileSystemInterface* const file_system = | 966 drive::FileSystemInterface* const file_system = |
| 964 drive::util::GetFileSystemByProfile(chrome_details_.GetProfile()); | 967 drive::util::GetFileSystemByProfile(chrome_details_.GetProfile()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 988 return RespondLater(); | 991 return RespondLater(); |
| 989 } | 992 } |
| 990 | 993 |
| 991 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( | 994 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( |
| 992 drive::FileError result) { | 995 drive::FileError result) { |
| 993 Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 996 Respond(result == drive::FILE_ERROR_OK ? NoArguments() |
| 994 : Error("Failed to set a tag.")); | 997 : Error("Failed to set a tag.")); |
| 995 } | 998 } |
| 996 | 999 |
| 997 } // namespace extensions | 1000 } // namespace extensions |
| OLD | NEW |