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

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

Issue 875513006: Files.app: Implement md5 hashing over file streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback. Move I/O onto the IO thread. Created 5 years, 10 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_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
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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 ResolveIsolatedEntries::Results::Create(entries); 713 ResolveIsolatedEntries::Results::Create(entries);
713 SendResponse(true); 714 SendResponse(true);
714 } 715 }
715 716
716 bool FileManagerPrivateComputeChecksumFunction::RunAsync() { 717 bool FileManagerPrivateComputeChecksumFunction::RunAsync() {
717 using extensions::api::file_manager_private::ComputeChecksum::Params; 718 using extensions::api::file_manager_private::ComputeChecksum::Params;
718 const scoped_ptr<Params> params(Params::Create(*args_)); 719 const scoped_ptr<Params> params(Params::Create(*args_));
719 EXTENSION_FUNCTION_VALIDATE(params); 720 EXTENSION_FUNCTION_VALIDATE(params);
720 721
721 if (params->file_url.empty()) { 722 if (params->file_url.empty()) {
722 // TODO(kenobi): call SetError() 723 SetError("File URL must be provided");
723 return false; 724 return false;
724 } 725 }
725 726
726 scoped_refptr<storage::FileSystemContext> file_system_context = 727 scoped_refptr<storage::FileSystemContext> file_system_context =
727 file_manager::util::GetFileSystemContextForRenderViewHost( 728 file_manager::util::GetFileSystemContextForRenderViewHost(
728 GetProfile(), render_view_host()); 729 GetProfile(), render_view_host());
729 730
730 storage::FileSystemURL file_url( 731 storage::FileSystemURL file_url(
731 file_system_context->CrackURL(GURL(params->file_url))); 732 file_system_context->CrackURL(GURL(params->file_url)));
732 if (!file_url.is_valid()) { 733 if (!file_url.is_valid()) {
733 // TODO(kenobi): Call SetError() 734 SetError("File URL was invalid");
734 return false; 735 return false;
735 } 736 }
736 737
737 BrowserThread::PostTaskAndReplyWithResult( 738 scoped_ptr<storage::FileStreamReader> reader =
738 BrowserThread::FILE, FROM_HERE, 739 file_system_context->CreateFileStreamReader(
739 base::Bind(&drive::util::GetMd5Digest, file_url.path()), 740 file_url, 0, storage::kMaximumLength, base::Time());
740 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this)); 741
742 scoped_refptr<drive::util::FileStreamMd5Digester> digester(
mtomasz 2015/02/02 23:47:07 You don't need to make it a ref counter class. We
Ben Kwa 2015/02/03 06:28:54 So, you're suggesting making the FileStreamMd5Dige
mtomasz 2015/02/03 10:36:53 We use members for that, as the FileManagerPrivate
Ben Kwa 2015/02/03 16:32:19 OK, done.
743 new drive::util::FileStreamMd5Digester());
744 BrowserThread::PostTask(
745 BrowserThread::IO, FROM_HERE,
746 base::Bind(&drive::util::FileStreamMd5Digester::GetMd5Digest, digester,
747 base::Passed(&reader),
748 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond,
749 this)));
741 750
742 return true; 751 return true;
743 } 752 }
744 753
745 void FileManagerPrivateComputeChecksumFunction::Respond( 754 void FileManagerPrivateComputeChecksumFunction::Respond(
746 const std::string& hash) { 755 const std::string& hash) {
756 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
mtomasz 2015/02/02 23:47:07 This is a little bit hacky. Each method should be
Ben Kwa 2015/02/03 06:28:54 I don't think I can use PostTaskAndReply, because
mtomasz 2015/02/03 10:36:53 You're right. I'd suggest to repost then in an ano
Ben Kwa 2015/02/03 16:32:19 Done.
757 // If not called from the UI thread, repost to the UI thread. The only
758 // other thread that this should be getting called from is the IO thread.
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
760 BrowserThread::PostTask(
761 BrowserThread::UI, FROM_HERE,
762 base::Bind(&FileManagerPrivateComputeChecksumFunction::Respond, this,
763 hash));
764 return;
765 }
766 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
747 SetResult(new base::StringValue(hash)); 767 SetResult(new base::StringValue(hash));
748 SendResponse(true); 768 SendResponse(true);
749 } 769 }
750 770
751 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { 771 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() {
752 using api::file_manager_private::SearchFilesByHashes::Params; 772 using api::file_manager_private::SearchFilesByHashes::Params;
753 const scoped_ptr<Params> params(Params::Create(*args_)); 773 const scoped_ptr<Params> params(Params::Create(*args_));
754 EXTENSION_FUNCTION_VALIDATE(params); 774 EXTENSION_FUNCTION_VALIDATE(params);
755 775
756 // TODO(hirono): Check the volume ID and fail the function for volumes other 776 // 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
804 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); 824 result->GetListWithoutPathExpansion(hashAndPath.hash, &list);
805 list->AppendString( 825 list->AppendString(
806 file_manager::util::ConvertDrivePathToFileSystemUrl( 826 file_manager::util::ConvertDrivePathToFileSystemUrl(
807 GetProfile(), hashAndPath.path, extension_id()).spec()); 827 GetProfile(), hashAndPath.path, extension_id()).spec());
808 } 828 }
809 SetResult(result.release()); 829 SetResult(result.release());
810 SendResponse(true); 830 SendResponse(true);
811 } 831 }
812 832
813 } // namespace extensions 833 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/drive/drive_api_util.h » ('j') | chrome/browser/drive/drive_api_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698