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

Side by Side 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 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 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 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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.
981 SetError("Only local directories are supported.");
982 return false;
983 }
984
985 const base::FilePath root_path = file_manager::util::GetLocalPathFromURL(
986 render_frame_host(), GetProfile(), GURL(params->url));
987 if (root_path.empty()) {
988 SetError("Failed to get a local path from the entry's url.");
989 return false;
990 }
991
992 base::PostTaskAndReplyWithResult(
993 BrowserThread::GetBlockingPool(), FROM_HERE,
994 base::Bind(&base::ComputeDirectorySize, root_path),
995 base::Bind(&FileManagerPrivateInternalGetDirectorySizeFunction::
996 OnDirectorySizeRetrieved,
997 this));
998 return true;
999 }
1000
1001 void FileManagerPrivateInternalGetDirectorySizeFunction::
1002 OnDirectorySizeRetrieved(int64_t size) {
1003 SetResult(
1004 base::MakeUnique<base::FundamentalValue>(static_cast<double>(size)));
1005 SendResponse(true);
1006 }
1007
958 } // namespace extensions 1008 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698