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 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
29 #include "chrome/common/extensions/api/file_manager_private.h" | 29 #include "chrome/common/extensions/api/file_manager_private.h" |
30 #include "chrome/common/extensions/api/file_manager_private_internal.h" | 30 #include "chrome/common/extensions/api/file_manager_private_internal.h" |
31 #include "chromeos/disks/disk_mount_manager.h" | 31 #include "chromeos/disks/disk_mount_manager.h" |
32 #include "content/public/browser/child_process_security_policy.h" | 32 #include "content/public/browser/child_process_security_policy.h" |
33 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
35 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
36 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
| 37 #include "storage/browser/blob/file_stream_reader.h" |
37 #include "storage/browser/fileapi/file_system_context.h" | 38 #include "storage/browser/fileapi/file_system_context.h" |
38 #include "storage/browser/fileapi/file_system_file_util.h" | 39 #include "storage/browser/fileapi/file_system_file_util.h" |
39 #include "storage/browser/fileapi/file_system_operation_context.h" | 40 #include "storage/browser/fileapi/file_system_operation_context.h" |
40 #include "storage/browser/fileapi/file_system_operation_runner.h" | 41 #include "storage/browser/fileapi/file_system_operation_runner.h" |
41 #include "storage/browser/fileapi/file_system_url.h" | 42 #include "storage/browser/fileapi/file_system_url.h" |
42 #include "storage/common/fileapi/file_system_info.h" | 43 #include "storage/common/fileapi/file_system_info.h" |
43 #include "storage/common/fileapi/file_system_types.h" | 44 #include "storage/common/fileapi/file_system_types.h" |
44 #include "storage/common/fileapi/file_system_util.h" | 45 #include "storage/common/fileapi/file_system_util.h" |
45 | 46 |
46 using chromeos::disks::DiskMountManager; | 47 using chromeos::disks::DiskMountManager; |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); | 707 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); |
707 entry->file_is_directory = entry_definition_list->at(i).is_directory; | 708 entry->file_is_directory = entry_definition_list->at(i).is_directory; |
708 entries.push_back(entry); | 709 entries.push_back(entry); |
709 } | 710 } |
710 | 711 |
711 results_ = extensions::api::file_manager_private_internal:: | 712 results_ = extensions::api::file_manager_private_internal:: |
712 ResolveIsolatedEntries::Results::Create(entries); | 713 ResolveIsolatedEntries::Results::Create(entries); |
713 SendResponse(true); | 714 SendResponse(true); |
714 } | 715 } |
715 | 716 |
| 717 FileManagerPrivateComputeChecksumFunction:: |
| 718 FileManagerPrivateComputeChecksumFunction() |
| 719 : digester_(new drive::util::FileStreamMd5Digester()) { |
| 720 } |
| 721 |
| 722 FileManagerPrivateComputeChecksumFunction:: |
| 723 ~FileManagerPrivateComputeChecksumFunction() { |
| 724 } |
| 725 |
716 bool FileManagerPrivateComputeChecksumFunction::RunAsync() { | 726 bool FileManagerPrivateComputeChecksumFunction::RunAsync() { |
717 using extensions::api::file_manager_private::ComputeChecksum::Params; | 727 using extensions::api::file_manager_private::ComputeChecksum::Params; |
718 const scoped_ptr<Params> params(Params::Create(*args_)); | 728 const scoped_ptr<Params> params(Params::Create(*args_)); |
719 EXTENSION_FUNCTION_VALIDATE(params); | 729 EXTENSION_FUNCTION_VALIDATE(params); |
720 | 730 |
721 if (params->file_url.empty()) { | 731 if (params->file_url.empty()) { |
722 // TODO(kenobi): call SetError() | 732 SetError("File URL must be provided"); |
723 return false; | 733 return false; |
724 } | 734 } |
725 | 735 |
726 scoped_refptr<storage::FileSystemContext> file_system_context = | 736 scoped_refptr<storage::FileSystemContext> file_system_context = |
727 file_manager::util::GetFileSystemContextForRenderViewHost( | 737 file_manager::util::GetFileSystemContextForRenderViewHost( |
728 GetProfile(), render_view_host()); | 738 GetProfile(), render_view_host()); |
729 | 739 |
730 storage::FileSystemURL file_url( | 740 storage::FileSystemURL file_url( |
731 file_system_context->CrackURL(GURL(params->file_url))); | 741 file_system_context->CrackURL(GURL(params->file_url))); |
732 if (!file_url.is_valid()) { | 742 if (!file_url.is_valid()) { |
733 // TODO(kenobi): Call SetError() | 743 SetError("File URL was invalid"); |
734 return false; | 744 return false; |
735 } | 745 } |
736 | 746 |
737 BrowserThread::PostTaskAndReplyWithResult( | 747 digester_->GetMd5Digest( |
738 BrowserThread::FILE, FROM_HERE, | 748 file_system_context->CreateFileStreamReader( |
739 base::Bind(&drive::util::GetMd5Digest, file_url.path()), | 749 file_url, 0, storage::kMaximumLength, base::Time()), |
740 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this)); | 750 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this)); |
741 | 751 |
742 return true; | 752 return true; |
743 } | 753 } |
744 | 754 |
745 void FileManagerPrivateComputeChecksumFunction::Respond( | 755 void FileManagerPrivateComputeChecksumFunction::Respond( |
746 const std::string& hash) { | 756 const std::string& hash) { |
| 757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
747 SetResult(new base::StringValue(hash)); | 758 SetResult(new base::StringValue(hash)); |
748 SendResponse(true); | 759 SendResponse(true); |
749 } | 760 } |
750 | 761 |
751 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { | 762 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { |
752 using api::file_manager_private::SearchFilesByHashes::Params; | 763 using api::file_manager_private::SearchFilesByHashes::Params; |
753 const scoped_ptr<Params> params(Params::Create(*args_)); | 764 const scoped_ptr<Params> params(Params::Create(*args_)); |
754 EXTENSION_FUNCTION_VALIDATE(params); | 765 EXTENSION_FUNCTION_VALIDATE(params); |
755 | 766 |
756 // TODO(hirono): Check the volume ID and fail the function for volumes other | 767 // TODO(hirono): Check the volume ID and fail the function for volumes other |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); | 815 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); |
805 list->AppendString( | 816 list->AppendString( |
806 file_manager::util::ConvertDrivePathToFileSystemUrl( | 817 file_manager::util::ConvertDrivePathToFileSystemUrl( |
807 GetProfile(), hashAndPath.path, extension_id()).spec()); | 818 GetProfile(), hashAndPath.path, extension_id()).spec()); |
808 } | 819 } |
809 SetResult(result.release()); | 820 SetResult(result.release()); |
810 SendResponse(true); | 821 SendResponse(true); |
811 } | 822 } |
812 | 823 |
813 } // namespace extensions | 824 } // namespace extensions |
OLD | NEW |