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 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/files/file_util.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/posix/eintr_wrapper.h" | 17 #include "base/posix/eintr_wrapper.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
21 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 ~FileManagerPrivateInternalComputeChecksumFunction() { | 794 ~FileManagerPrivateInternalComputeChecksumFunction() { |
794 } | 795 } |
795 | 796 |
796 bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() { | 797 bool FileManagerPrivateInternalComputeChecksumFunction::RunAsync() { |
797 using extensions::api::file_manager_private_internal::ComputeChecksum::Params; | 798 using extensions::api::file_manager_private_internal::ComputeChecksum::Params; |
798 using drive::util::FileStreamMd5Digester; | 799 using drive::util::FileStreamMd5Digester; |
799 const std::unique_ptr<Params> params(Params::Create(*args_)); | 800 const std::unique_ptr<Params> params(Params::Create(*args_)); |
800 EXTENSION_FUNCTION_VALIDATE(params); | 801 EXTENSION_FUNCTION_VALIDATE(params); |
801 | 802 |
802 if (params->url.empty()) { | 803 if (params->url.empty()) { |
803 SetError("File URL must be provided"); | 804 SetError("File URL must be provided."); |
804 return false; | 805 return false; |
805 } | 806 } |
806 | 807 |
807 scoped_refptr<storage::FileSystemContext> file_system_context = | 808 scoped_refptr<storage::FileSystemContext> file_system_context = |
808 file_manager::util::GetFileSystemContextForRenderFrameHost( | 809 file_manager::util::GetFileSystemContextForRenderFrameHost( |
809 GetProfile(), render_frame_host()); | 810 GetProfile(), render_frame_host()); |
810 | 811 |
811 FileSystemURL file_system_url( | 812 FileSystemURL file_system_url( |
812 file_system_context->CrackURL(GURL(params->url))); | 813 file_system_context->CrackURL(GURL(params->url))); |
813 if (!file_system_url.is_valid()) { | 814 if (!file_system_url.is_valid()) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 this)); | 949 this)); |
949 return RespondLater(); | 950 return RespondLater(); |
950 } | 951 } |
951 | 952 |
952 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( | 953 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( |
953 drive::FileError result) { | 954 drive::FileError result) { |
954 Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 955 Respond(result == drive::FILE_ERROR_OK ? NoArguments() |
955 : Error("Failed to set a tag.")); | 956 : Error("Failed to set a tag.")); |
956 } | 957 } |
957 | 958 |
| 959 bool FileManagerPrivateInternalGetDirectorySizeFunction::RunAsync() { |
| 960 using extensions::api::file_manager_private_internal::GetDirectorySize:: |
| 961 Params; |
| 962 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 963 EXTENSION_FUNCTION_VALIDATE(params); |
| 964 |
| 965 if (params->url.empty()) { |
| 966 SetError("File URL must be provided."); |
| 967 return false; |
| 968 } |
| 969 |
| 970 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 971 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 972 GetProfile(), render_frame_host()); |
| 973 const storage::FileSystemURL file_system_url( |
| 974 file_system_context->CrackURL(GURL(params->url))); |
| 975 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) { |
| 976 SetError("FileSystemBackend failed to handle the entry's url."); |
| 977 return false; |
| 978 } |
| 979 if (file_system_url.type() != storage::kFileSystemTypeNativeLocal) { |
| 980 SetError("Only local directories are supported."); |
| 981 return false; |
| 982 } |
| 983 |
| 984 const base::FilePath root_path = file_manager::util::GetLocalPathFromURL( |
| 985 render_frame_host(), GetProfile(), GURL(params->url)); |
| 986 if (root_path.empty()) { |
| 987 SetError("Failed to get a local path from the entry's url."); |
| 988 return false; |
| 989 } |
| 990 |
| 991 base::PostTaskAndReplyWithResult( |
| 992 BrowserThread::GetBlockingPool(), FROM_HERE, |
| 993 base::Bind(&base::ComputeDirectorySize, root_path), |
| 994 base::Bind(&FileManagerPrivateInternalGetDirectorySizeFunction:: |
| 995 OnDirectorySizeRetrieved, |
| 996 this)); |
| 997 return true; |
| 998 } |
| 999 |
| 1000 void FileManagerPrivateInternalGetDirectorySizeFunction:: |
| 1001 OnDirectorySizeRetrieved(int64_t size) { |
| 1002 SetResult( |
| 1003 base::MakeUnique<base::FundamentalValue>(static_cast<double>(size))); |
| 1004 SendResponse(true); |
| 1005 } |
| 1006 |
958 } // namespace extensions | 1007 } // namespace extensions |
OLD | NEW |