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 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
15 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/drive/drive.pb.h" | 19 #include "chrome/browser/chromeos/drive/drive.pb.h" |
19 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 20 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
20 #include "chrome/browser/chromeos/drive/file_system_util.h" | 21 #include "chrome/browser/chromeos/drive/file_system_util.h" |
21 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" | 22 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
22 #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h " | 23 #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h " |
23 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 24 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
24 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 25 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
25 #include "chrome/browser/chromeos/file_manager/path_util.h" | 26 #include "chrome/browser/chromeos/file_manager/path_util.h" |
26 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 27 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
27 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" | 28 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
28 #include "chrome/browser/drive/drive_api_util.h" | 29 #include "chrome/browser/drive/drive_api_util.h" |
29 #include "chrome/browser/drive/event_logger.h" | 30 #include "chrome/browser/drive/event_logger.h" |
30 #include "chrome/browser/extensions/extension_util.h" | 31 #include "chrome/browser/extensions/extension_util.h" |
31 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 32 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
34 #include "chrome/common/extensions/api/file_manager_private.h" | 35 #include "chrome/common/extensions/api/file_manager_private.h" |
35 #include "chrome/common/extensions/api/file_manager_private_internal.h" | 36 #include "chrome/common/extensions/api/file_manager_private_internal.h" |
36 #include "chromeos/disks/disk_mount_manager.h" | 37 #include "chromeos/disks/disk_mount_manager.h" |
38 #include "components/storage_monitor/storage_info.h" | |
39 #include "components/storage_monitor/storage_monitor.h" | |
37 #include "content/public/browser/child_process_security_policy.h" | 40 #include "content/public/browser/child_process_security_policy.h" |
38 #include "content/public/browser/render_process_host.h" | 41 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/storage_partition.h" | 43 #include "content/public/browser/storage_partition.h" |
41 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
45 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | |
46 #include "device/media_transfer_protocol/mtp_storage_info.pb.h" | |
42 #include "net/base/escape.h" | 47 #include "net/base/escape.h" |
43 #include "storage/browser/fileapi/file_stream_reader.h" | 48 #include "storage/browser/fileapi/file_stream_reader.h" |
44 #include "storage/browser/fileapi/file_system_context.h" | 49 #include "storage/browser/fileapi/file_system_context.h" |
45 #include "storage/browser/fileapi/file_system_file_util.h" | 50 #include "storage/browser/fileapi/file_system_file_util.h" |
46 #include "storage/browser/fileapi/file_system_operation_context.h" | 51 #include "storage/browser/fileapi/file_system_operation_context.h" |
47 #include "storage/browser/fileapi/file_system_operation_runner.h" | 52 #include "storage/browser/fileapi/file_system_operation_runner.h" |
48 #include "storage/common/fileapi/file_system_info.h" | 53 #include "storage/common/fileapi/file_system_info.h" |
49 #include "storage/common/fileapi/file_system_types.h" | 54 #include "storage/common/fileapi/file_system_types.h" |
50 #include "storage/common/fileapi/file_system_util.h" | 55 #include "storage/common/fileapi/file_system_util.h" |
51 #include "third_party/cros_system_api/constants/cryptohome.h" | 56 #include "third_party/cros_system_api/constants/cryptohome.h" |
52 | 57 |
53 using chromeos::disks::DiskMountManager; | 58 using chromeos::disks::DiskMountManager; |
54 using content::BrowserThread; | 59 using content::BrowserThread; |
55 using content::ChildProcessSecurityPolicy; | 60 using content::ChildProcessSecurityPolicy; |
56 using file_manager::util::EntryDefinition; | 61 using file_manager::util::EntryDefinition; |
57 using file_manager::util::FileDefinition; | 62 using file_manager::util::FileDefinition; |
58 using storage::FileSystemURL; | 63 using storage::FileSystemURL; |
59 | 64 |
60 namespace extensions { | 65 namespace extensions { |
61 namespace { | 66 namespace { |
62 | 67 |
68 const char kRootPath[] = "/"; | |
69 | |
63 // Retrieves total and remaining available size on |mount_path|. | 70 // Retrieves total and remaining available size on |mount_path|. |
64 void GetSizeStatsOnBlockingPool(const std::string& mount_path, | 71 void GetSizeStatsOnBlockingPool(const std::string& mount_path, |
65 uint64* total_size, | 72 uint64* total_size, |
66 uint64* remaining_size) { | 73 uint64* remaining_size) { |
67 struct statvfs stat = {}; // Zero-clear | 74 struct statvfs stat = {}; // Zero-clear |
68 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { | 75 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { |
69 *total_size = static_cast<uint64>(stat.f_blocks) * stat.f_frsize; | 76 *total_size = static_cast<uint64>(stat.f_blocks) * stat.f_frsize; |
70 *remaining_size = static_cast<uint64>(stat.f_bavail) * stat.f_frsize; | 77 *remaining_size = static_cast<uint64>(stat.f_bavail) * stat.f_frsize; |
71 } | 78 } |
72 } | 79 } |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 // If stats couldn't be gotten for drive, result should be left | 410 // If stats couldn't be gotten for drive, result should be left |
404 // undefined. See comments in GetDriveAvailableSpaceCallback(). | 411 // undefined. See comments in GetDriveAvailableSpaceCallback(). |
405 SendResponse(true); | 412 SendResponse(true); |
406 return true; | 413 return true; |
407 } | 414 } |
408 | 415 |
409 file_system->GetAvailableSpace( | 416 file_system->GetAvailableSpace( |
410 base::Bind(&FileManagerPrivateGetSizeStatsFunction:: | 417 base::Bind(&FileManagerPrivateGetSizeStatsFunction:: |
411 GetDriveAvailableSpaceCallback, | 418 GetDriveAvailableSpaceCallback, |
412 this)); | 419 this)); |
420 } else if (volume->type() == file_manager::VOLUME_TYPE_MTP) { | |
421 // Resolve storage_name. | |
422 storage_monitor::StorageMonitor* storage_monitor = | |
423 storage_monitor::StorageMonitor::GetInstance(); | |
424 storage_monitor::StorageInfo info; | |
425 storage_monitor->GetStorageInfoForPath(volume->mount_path(), &info); | |
426 std::string storage_name; | |
427 base::RemoveChars(info.location(), kRootPath, &storage_name); | |
428 DCHECK(!storage_name.empty()); | |
429 | |
430 // Get MTP StorageInfo. | |
431 // TODO(yawano) Implement GetStorageInfoFromDevice on chrome side. Currently | |
432 // it returns stale storage info at the mount time. | |
433 device::MediaTransferProtocolManager* manager = | |
434 storage_monitor->media_transfer_protocol_manager(); | |
435 const MtpStorageInfo* mtp_storage_info = | |
436 manager->GetStorageInfo(storage_name); | |
437 if (mtp_storage_info) { | |
438 const uint64 max_capacity = mtp_storage_info->max_capacity(); | |
439 const uint64 free_space_in_bytes = | |
440 mtp_storage_info->free_space_in_bytes(); | |
441 GetSizeStatsCallback(&max_capacity, &free_space_in_bytes); | |
442 } | |
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.
| |
413 } else { | 443 } else { |
414 uint64* total_size = new uint64(0); | 444 uint64* total_size = new uint64(0); |
415 uint64* remaining_size = new uint64(0); | 445 uint64* remaining_size = new uint64(0); |
416 BrowserThread::PostBlockingPoolTaskAndReply( | 446 BrowserThread::PostBlockingPoolTaskAndReply( |
417 FROM_HERE, | 447 FROM_HERE, |
418 base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path().value(), | 448 base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path().value(), |
419 total_size, remaining_size), | 449 total_size, remaining_size), |
420 base::Bind( | 450 base::Bind( |
421 &FileManagerPrivateGetSizeStatsFunction::GetSizeStatsCallback, this, | 451 &FileManagerPrivateGetSizeStatsFunction::GetSizeStatsCallback, this, |
422 base::Owned(total_size), base::Owned(remaining_size))); | 452 base::Owned(total_size), base::Owned(remaining_size))); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 return RespondLater(); | 928 return RespondLater(); |
899 } | 929 } |
900 | 930 |
901 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( | 931 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( |
902 drive::FileError result) { | 932 drive::FileError result) { |
903 Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 933 Respond(result == drive::FILE_ERROR_OK ? NoArguments() |
904 : Error("Failed to set a tag.")); | 934 : Error("Failed to set a tag.")); |
905 } | 935 } |
906 | 936 |
907 } // namespace extensions | 937 } // namespace extensions |
OLD | NEW |