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

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

Issue 1140583005: Show remaing space of MTP device in File Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix failed test case. Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6e0f24995a7aa8bc585cf8b85316855301ac4b4d..d04519f406199e684987946c22544bf75245dafa 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
@@ -10,6 +10,7 @@
#include "base/memory/weak_ptr.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/task_runner_util.h"
@@ -34,11 +35,15 @@
#include "chrome/common/extensions/api/file_manager_private.h"
#include "chrome/common/extensions/api/file_manager_private_internal.h"
#include "chromeos/disks/disk_mount_manager.h"
+#include "components/storage_monitor/storage_info.h"
+#include "components/storage_monitor/storage_monitor.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/url_constants.h"
+#include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
+#include "device/media_transfer_protocol/mtp_storage_info.pb.h"
#include "net/base/escape.h"
#include "storage/browser/fileapi/file_stream_reader.h"
#include "storage/browser/fileapi/file_system_context.h"
@@ -60,6 +65,8 @@ using storage::FileSystemURL;
namespace extensions {
namespace {
+const char kRootPath[] = "/";
+
// Retrieves total and remaining available size on |mount_path|.
void GetSizeStatsOnBlockingPool(const std::string& mount_path,
uint64* total_size,
@@ -410,6 +417,29 @@ bool FileManagerPrivateGetSizeStatsFunction::RunAsync() {
base::Bind(&FileManagerPrivateGetSizeStatsFunction::
GetDriveAvailableSpaceCallback,
this));
+ } else if (volume->type() == file_manager::VOLUME_TYPE_MTP) {
+ // Resolve storage_name.
+ storage_monitor::StorageMonitor* storage_monitor =
+ storage_monitor::StorageMonitor::GetInstance();
+ storage_monitor::StorageInfo info;
+ storage_monitor->GetStorageInfoForPath(volume->mount_path(), &info);
+ std::string storage_name;
+ base::RemoveChars(info.location(), kRootPath, &storage_name);
+ DCHECK(!storage_name.empty());
+
+ // Get MTP StorageInfo.
+ // TODO(yawano) Implement GetStorageInfoFromDevice on chrome side. Currently
+ // it returns stale storage info at the mount time.
+ device::MediaTransferProtocolManager* manager =
+ storage_monitor->media_transfer_protocol_manager();
+ const MtpStorageInfo* mtp_storage_info =
+ manager->GetStorageInfo(storage_name);
+ if (mtp_storage_info) {
+ const uint64 max_capacity = mtp_storage_info->max_capacity();
+ const uint64 free_space_in_bytes =
+ mtp_storage_info->free_space_in_bytes();
+ GetSizeStatsCallback(&max_capacity, &free_space_in_bytes);
+ }
kinaba 2015/05/19 09:37:31 I guess it's safer to return false when it is unav
yawano 2015/05/19 12:08:12 Done.
} else {
uint64* total_size = new uint64(0);
uint64* remaining_size = new uint64(0);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698