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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 operation_id, base::Bind(&OnCopyCancelled)); | 206 operation_id, base::Bind(&OnCopyCancelled)); |
206 } | 207 } |
207 | 208 |
208 // Converts a status code to a bool value and calls the |callback| with it. | 209 // Converts a status code to a bool value and calls the |callback| with it. |
209 void StatusCallbackToResponseCallback( | 210 void StatusCallbackToResponseCallback( |
210 const base::Callback<void(bool)>& callback, | 211 const base::Callback<void(bool)>& callback, |
211 base::File::Error result) { | 212 base::File::Error result) { |
212 callback.Run(result == base::File::FILE_OK); | 213 callback.Run(result == base::File::FILE_OK); |
213 } | 214 } |
214 | 215 |
| 216 // Calls a response callback (on the UI thread) with a file content hash |
| 217 // computed on the IO thread. |
| 218 void ComputeChecksumRespondOnUIThread( |
| 219 const base::Callback<void(const std::string&)>& callback, |
| 220 const std::string& hash) { |
| 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 222 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 223 base::Bind(callback, hash)); |
| 224 } |
| 225 |
215 } // namespace | 226 } // namespace |
216 | 227 |
217 void FileManagerPrivateRequestFileSystemFunction::DidFail( | 228 void FileManagerPrivateRequestFileSystemFunction::DidFail( |
218 base::File::Error error_code) { | 229 base::File::Error error_code) { |
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
220 | 231 |
221 SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); | 232 SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); |
222 SendResponse(false); | 233 SendResponse(false); |
223 } | 234 } |
224 | 235 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); | 717 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); |
707 entry->file_is_directory = entry_definition_list->at(i).is_directory; | 718 entry->file_is_directory = entry_definition_list->at(i).is_directory; |
708 entries.push_back(entry); | 719 entries.push_back(entry); |
709 } | 720 } |
710 | 721 |
711 results_ = extensions::api::file_manager_private_internal:: | 722 results_ = extensions::api::file_manager_private_internal:: |
712 ResolveIsolatedEntries::Results::Create(entries); | 723 ResolveIsolatedEntries::Results::Create(entries); |
713 SendResponse(true); | 724 SendResponse(true); |
714 } | 725 } |
715 | 726 |
| 727 FileManagerPrivateComputeChecksumFunction:: |
| 728 FileManagerPrivateComputeChecksumFunction() |
| 729 : digester_(new drive::util::FileStreamMd5Digester()) { |
| 730 } |
| 731 |
| 732 FileManagerPrivateComputeChecksumFunction:: |
| 733 ~FileManagerPrivateComputeChecksumFunction() { |
| 734 } |
| 735 |
716 bool FileManagerPrivateComputeChecksumFunction::RunAsync() { | 736 bool FileManagerPrivateComputeChecksumFunction::RunAsync() { |
717 using extensions::api::file_manager_private::ComputeChecksum::Params; | 737 using extensions::api::file_manager_private::ComputeChecksum::Params; |
| 738 using drive::util::FileStreamMd5Digester; |
718 const scoped_ptr<Params> params(Params::Create(*args_)); | 739 const scoped_ptr<Params> params(Params::Create(*args_)); |
719 EXTENSION_FUNCTION_VALIDATE(params); | 740 EXTENSION_FUNCTION_VALIDATE(params); |
720 | 741 |
721 if (params->file_url.empty()) { | 742 if (params->file_url.empty()) { |
722 // TODO(kenobi): call SetError() | 743 SetError("File URL must be provided"); |
723 return false; | 744 return false; |
724 } | 745 } |
725 | 746 |
726 scoped_refptr<storage::FileSystemContext> file_system_context = | 747 scoped_refptr<storage::FileSystemContext> file_system_context = |
727 file_manager::util::GetFileSystemContextForRenderViewHost( | 748 file_manager::util::GetFileSystemContextForRenderViewHost( |
728 GetProfile(), render_view_host()); | 749 GetProfile(), render_view_host()); |
729 | 750 |
730 storage::FileSystemURL file_url( | 751 FileSystemURL file_url(file_system_context->CrackURL(GURL(params->file_url))); |
731 file_system_context->CrackURL(GURL(params->file_url))); | |
732 if (!file_url.is_valid()) { | 752 if (!file_url.is_valid()) { |
733 // TODO(kenobi): Call SetError() | 753 SetError("File URL was invalid"); |
734 return false; | 754 return false; |
735 } | 755 } |
736 | 756 |
737 BrowserThread::PostTaskAndReplyWithResult( | 757 scoped_ptr<storage::FileStreamReader> reader = |
738 BrowserThread::FILE, FROM_HERE, | 758 file_system_context->CreateFileStreamReader( |
739 base::Bind(&drive::util::GetMd5Digest, file_url.path()), | 759 file_url, 0, storage::kMaximumLength, base::Time()); |
| 760 |
| 761 FileStreamMd5Digester::ResultCallback result_callback = base::Bind( |
| 762 &ComputeChecksumRespondOnUIThread, |
740 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this)); | 763 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this)); |
| 764 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 765 base::Bind(&FileStreamMd5Digester::GetMd5Digest, |
| 766 base::Unretained(digester_.get()), |
| 767 base::Passed(&reader), result_callback)); |
741 | 768 |
742 return true; | 769 return true; |
743 } | 770 } |
744 | 771 |
745 void FileManagerPrivateComputeChecksumFunction::Respond( | 772 void FileManagerPrivateComputeChecksumFunction::Respond( |
746 const std::string& hash) { | 773 const std::string& hash) { |
| 774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
747 SetResult(new base::StringValue(hash)); | 775 SetResult(new base::StringValue(hash)); |
748 SendResponse(true); | 776 SendResponse(true); |
749 } | 777 } |
750 | 778 |
751 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { | 779 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { |
752 using api::file_manager_private::SearchFilesByHashes::Params; | 780 using api::file_manager_private::SearchFilesByHashes::Params; |
753 const scoped_ptr<Params> params(Params::Create(*args_)); | 781 const scoped_ptr<Params> params(Params::Create(*args_)); |
754 EXTENSION_FUNCTION_VALIDATE(params); | 782 EXTENSION_FUNCTION_VALIDATE(params); |
755 | 783 |
756 // TODO(hirono): Check the volume ID and fail the function for volumes other | 784 // 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); | 832 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); |
805 list->AppendString( | 833 list->AppendString( |
806 file_manager::util::ConvertDrivePathToFileSystemUrl( | 834 file_manager::util::ConvertDrivePathToFileSystemUrl( |
807 GetProfile(), hashAndPath.path, extension_id()).spec()); | 835 GetProfile(), hashAndPath.path, extension_id()).spec()); |
808 } | 836 } |
809 SetResult(result.release()); | 837 SetResult(result.release()); |
810 SendResponse(true); | 838 SendResponse(true); |
811 } | 839 } |
812 | 840 |
813 } // namespace extensions | 841 } // namespace extensions |
OLD | NEW |