| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/storage_monitor/storage_monitor_chromeos.h" | 5 #include "components/storage_monitor/storage_monitor_chromeos.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 device_label, | 72 device_label, |
| 73 base::UTF8ToUTF16(disk->vendor_name()), | 73 base::UTF8ToUTF16(disk->vendor_name()), |
| 74 base::UTF8ToUTF16(disk->product_name()), | 74 base::UTF8ToUTF16(disk->product_name()), |
| 75 disk->total_size_in_bytes()); | 75 disk->total_size_in_bytes()); |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Returns whether the mount point in |mount_info| is a media device or not. | 79 // Returns whether the mount point in |mount_info| is a media device or not. |
| 80 bool CheckMountedPathOnFileThread( | 80 bool CheckMountedPathOnFileThread( |
| 81 const DiskMountManager::MountPointInfo& mount_info) { | 81 const DiskMountManager::MountPointInfo& mount_info) { |
| 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 82 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 83 return MediaStorageUtil::HasDcim(base::FilePath(mount_info.mount_path)); | 83 return MediaStorageUtil::HasDcim(base::FilePath(mount_info.mount_path)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 using content::BrowserThread; | 88 using content::BrowserThread; |
| 89 | 89 |
| 90 StorageMonitorCros::StorageMonitorCros() | 90 StorageMonitorCros::StorageMonitorCros() |
| 91 : weak_ptr_factory_(this) { | 91 : weak_ptr_factory_(this) { |
| 92 } | 92 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 media_transfer_protocol_manager_.reset( | 108 media_transfer_protocol_manager_.reset( |
| 109 device::MediaTransferProtocolManager::Initialize(loop_proxy)); | 109 device::MediaTransferProtocolManager::Initialize(loop_proxy)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 media_transfer_protocol_device_observer_.reset( | 112 media_transfer_protocol_device_observer_.reset( |
| 113 new MediaTransferProtocolDeviceObserverLinux( | 113 new MediaTransferProtocolDeviceObserverLinux( |
| 114 receiver(), media_transfer_protocol_manager_.get())); | 114 receiver(), media_transfer_protocol_manager_.get())); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void StorageMonitorCros::CheckExistingMountPoints() { | 117 void StorageMonitorCros::CheckExistingMountPoints() { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 119 const DiskMountManager::MountPointMap& mount_point_map = | 119 const DiskMountManager::MountPointMap& mount_point_map = |
| 120 DiskMountManager::GetInstance()->mount_points(); | 120 DiskMountManager::GetInstance()->mount_points(); |
| 121 for (DiskMountManager::MountPointMap::const_iterator it = | 121 for (DiskMountManager::MountPointMap::const_iterator it = |
| 122 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 122 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
| 123 BrowserThread::PostTaskAndReplyWithResult( | 123 BrowserThread::PostTaskAndReplyWithResult( |
| 124 BrowserThread::FILE, FROM_HERE, | 124 BrowserThread::FILE, FROM_HERE, |
| 125 base::Bind(&CheckMountedPathOnFileThread, it->second), | 125 base::Bind(&CheckMountedPathOnFileThread, it->second), |
| 126 base::Bind(&StorageMonitorCros::AddMountedPath, | 126 base::Bind(&StorageMonitorCros::AddMountedPath, |
| 127 weak_ptr_factory_.GetWeakPtr(), it->second)); | 127 weak_ptr_factory_.GetWeakPtr(), it->second)); |
| 128 } | 128 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 141 void StorageMonitorCros::OnDiskEvent(DiskMountManager::DiskEvent event, | 141 void StorageMonitorCros::OnDiskEvent(DiskMountManager::DiskEvent event, |
| 142 const DiskMountManager::Disk* disk) {} | 142 const DiskMountManager::Disk* disk) {} |
| 143 | 143 |
| 144 void StorageMonitorCros::OnDeviceEvent(DiskMountManager::DeviceEvent event, | 144 void StorageMonitorCros::OnDeviceEvent(DiskMountManager::DeviceEvent event, |
| 145 const std::string& device_path) {} | 145 const std::string& device_path) {} |
| 146 | 146 |
| 147 void StorageMonitorCros::OnMountEvent( | 147 void StorageMonitorCros::OnMountEvent( |
| 148 DiskMountManager::MountEvent event, | 148 DiskMountManager::MountEvent event, |
| 149 chromeos::MountError error_code, | 149 chromeos::MountError error_code, |
| 150 const DiskMountManager::MountPointInfo& mount_info) { | 150 const DiskMountManager::MountPointInfo& mount_info) { |
| 151 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 151 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 152 | 152 |
| 153 // Ignore mount points that are not devices. | 153 // Ignore mount points that are not devices. |
| 154 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) | 154 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) |
| 155 return; | 155 return; |
| 156 // Ignore errors. | 156 // Ignore errors. |
| 157 if (error_code != chromeos::MOUNT_ERROR_NONE) | 157 if (error_code != chromeos::MOUNT_ERROR_NONE) |
| 158 return; | 158 return; |
| 159 if (mount_info.mount_condition != chromeos::disks::MOUNT_CONDITION_NONE) | 159 if (mount_info.mount_condition != chromeos::disks::MOUNT_CONDITION_NONE) |
| 160 return; | 160 return; |
| 161 | 161 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 270 } |
| 271 | 271 |
| 272 device::MediaTransferProtocolManager* | 272 device::MediaTransferProtocolManager* |
| 273 StorageMonitorCros::media_transfer_protocol_manager() { | 273 StorageMonitorCros::media_transfer_protocol_manager() { |
| 274 return media_transfer_protocol_manager_.get(); | 274 return media_transfer_protocol_manager_.get(); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void StorageMonitorCros::AddMountedPath( | 277 void StorageMonitorCros::AddMountedPath( |
| 278 const DiskMountManager::MountPointInfo& mount_info, | 278 const DiskMountManager::MountPointInfo& mount_info, |
| 279 bool has_dcim) { | 279 bool has_dcim) { |
| 280 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 281 | 281 |
| 282 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 282 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
| 283 // CheckExistingMountPointsOnUIThread() added the mount point information | 283 // CheckExistingMountPointsOnUIThread() added the mount point information |
| 284 // in the map before the device attached handler is called. Therefore, an | 284 // in the map before the device attached handler is called. Therefore, an |
| 285 // entry for the device already exists in the map. | 285 // entry for the device already exists in the map. |
| 286 return; | 286 return; |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Get the media device uuid and label if exists. | 289 // Get the media device uuid and label if exists. |
| 290 StorageInfo info; | 290 StorageInfo info; |
| 291 if (!GetDeviceInfo(mount_info, has_dcim, &info)) | 291 if (!GetDeviceInfo(mount_info, has_dcim, &info)) |
| 292 return; | 292 return; |
| 293 | 293 |
| 294 if (info.device_id().empty()) | 294 if (info.device_id().empty()) |
| 295 return; | 295 return; |
| 296 | 296 |
| 297 mount_map_.insert(std::make_pair(mount_info.mount_path, info)); | 297 mount_map_.insert(std::make_pair(mount_info.mount_path, info)); |
| 298 | 298 |
| 299 receiver()->ProcessAttach(info); | 299 receiver()->ProcessAttach(info); |
| 300 } | 300 } |
| 301 | 301 |
| 302 StorageMonitor* StorageMonitor::CreateInternal() { | 302 StorageMonitor* StorageMonitor::CreateInternal() { |
| 303 return new StorageMonitorCros(); | 303 return new StorageMonitorCros(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace storage_monitor | 306 } // namespace storage_monitor |
| OLD | NEW |