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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc

Issue 2285393003: Add API to get a folder's size. (Closed)
Patch Set: Add API to get a folder's size. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
index 0cdc8c6702629349dec42dbf0bf85b62bb1a366d..5a58dcb733eb065184695d7ed709047bd99e6510 100644
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
@@ -11,6 +11,7 @@
#include <utility>
#include <vector>
+#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/posix/eintr_wrapper.h"
@@ -955,4 +956,53 @@ void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted(
: Error("Failed to set a tag."));
}
+bool FileManagerPrivateInternalGetDirectorySizeFunction::RunAsync() {
+ using extensions::api::file_manager_private_internal::GetDirectorySize::
+ Params;
+ const std::unique_ptr<Params> params(Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ if (params->url.empty()) {
+ SetError("File URL must be provided.");
+ return false;
+ }
+
+ scoped_refptr<storage::FileSystemContext> file_system_context =
+ file_manager::util::GetFileSystemContextForRenderFrameHost(
+ GetProfile(), render_frame_host());
+ const storage::FileSystemURL file_system_url(
+ file_system_context->CrackURL(GURL(params->url)));
+ if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) {
+ SetError("FileSystemBackend failed to handle the entry's url.");
+ return false;
+ }
+ if (file_system_url.type() != storage::kFileSystemTypeNativeLocal &&
+ file_system_url.type() != storage::kFileSystemTypeRestrictedNativeLocal) {
fukino 2016/09/02 01:40:25 I think external media like USB memory, SD card, e
fukino 2016/09/02 01:40:25 Should we add both file systems (kFileSystemTypeNa
fukino 2016/09/02 02:33:53 It seems USB memory, SD card, etc... are also Nati
fukino 2016/09/02 02:33:53 Maybe we can drop kFileSystemTypeRestrictedNativeL
harukam 2016/09/02 03:45:38 Acknowledged.
harukam 2016/09/02 03:45:38 Acknowledged.
harukam 2016/09/02 03:45:38 Thanks for checking.
harukam 2016/09/02 03:45:38 Acknowledged.
+ SetError("Only local directories are supported.");
+ return false;
+ }
+
+ const base::FilePath root_path = file_manager::util::GetLocalPathFromURL(
+ render_frame_host(), GetProfile(), GURL(params->url));
+ if (root_path.empty()) {
+ SetError("Failed to get a local path from the entry's url.");
+ return false;
+ }
+
+ base::PostTaskAndReplyWithResult(
+ BrowserThread::GetBlockingPool(), FROM_HERE,
+ base::Bind(&base::ComputeDirectorySize, root_path),
+ base::Bind(&FileManagerPrivateInternalGetDirectorySizeFunction::
+ OnDirectorySizeRetrieved,
+ this));
+ return true;
+}
+
+void FileManagerPrivateInternalGetDirectorySizeFunction::
+ OnDirectorySizeRetrieved(int64_t size) {
+ SetResult(
+ base::MakeUnique<base::FundamentalValue>(static_cast<double>(size)));
+ SendResponse(true);
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698