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