Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // chromeos::RemovableDeviceNotificationsCros implementation. | 5 // chromeos::StorageMonitorCros implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/storage_monitor/removable_device_notifications_chromeos .h" | 7 #include "chrome/browser/storage_monitor/storage_monitor_chromeos.h" |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | 15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |
| 16 #include "chrome/browser/storage_monitor/media_storage_util.h" | 16 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 17 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 17 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 79 |
| 80 if (storage_size_in_bytes) | 80 if (storage_size_in_bytes) |
| 81 *storage_size_in_bytes = disk->total_size_in_bytes(); | 81 *storage_size_in_bytes = disk->total_size_in_bytes(); |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| 87 using content::BrowserThread; | 87 using content::BrowserThread; |
| 88 | 88 |
| 89 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { | 89 StorageMonitorCros::StorageMonitorCros() { |
| 90 DCHECK(disks::DiskMountManager::GetInstance()); | 90 DCHECK(disks::DiskMountManager::GetInstance()); |
| 91 disks::DiskMountManager::GetInstance()->AddObserver(this); | 91 disks::DiskMountManager::GetInstance()->AddObserver(this); |
| 92 CheckExistingMountPointsOnUIThread(); | 92 CheckExistingMountPointsOnUIThread(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { | 95 StorageMonitorCros::~StorageMonitorCros() { |
| 96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
| 97 if (manager) { | 97 if (manager) { |
| 98 manager->RemoveObserver(this); | 98 manager->RemoveObserver(this); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { | 102 void StorageMonitorCros::CheckExistingMountPointsOnUIThread() { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 104 const disks::DiskMountManager::MountPointMap& mount_point_map = | 104 const disks::DiskMountManager::MountPointMap& mount_point_map = |
| 105 disks::DiskMountManager::GetInstance()->mount_points(); | 105 disks::DiskMountManager::GetInstance()->mount_points(); |
| 106 for (disks::DiskMountManager::MountPointMap::const_iterator it = | 106 for (disks::DiskMountManager::MountPointMap::const_iterator it = |
| 107 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 107 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
| 108 BrowserThread::PostTask( | 108 BrowserThread::PostTask( |
| 109 BrowserThread::FILE, FROM_HERE, | 109 BrowserThread::FILE, FROM_HERE, |
| 110 base::Bind( | 110 base::Bind( |
|
vandebo (ex-Chrome)
2013/03/02 00:23:37
nit: line wrap.
| |
| 111 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, | 111 &StorageMonitorCros::CheckMountedPathOnFileThread, |
| 112 this, it->second)); | 112 this, it->second)); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 void RemovableDeviceNotificationsCros::OnDiskEvent( | 116 void StorageMonitorCros::OnDiskEvent( |
| 117 disks::DiskMountManager::DiskEvent event, | 117 disks::DiskMountManager::DiskEvent event, |
| 118 const disks::DiskMountManager::Disk* disk) { | 118 const disks::DiskMountManager::Disk* disk) { |
| 119 } | 119 } |
| 120 | 120 |
| 121 void RemovableDeviceNotificationsCros::OnDeviceEvent( | 121 void StorageMonitorCros::OnDeviceEvent( |
| 122 disks::DiskMountManager::DeviceEvent event, | 122 disks::DiskMountManager::DeviceEvent event, |
| 123 const std::string& device_path) { | 123 const std::string& device_path) { |
| 124 } | 124 } |
| 125 | 125 |
| 126 void RemovableDeviceNotificationsCros::OnMountEvent( | 126 void StorageMonitorCros::OnMountEvent( |
| 127 disks::DiskMountManager::MountEvent event, | 127 disks::DiskMountManager::MountEvent event, |
| 128 MountError error_code, | 128 MountError error_code, |
| 129 const disks::DiskMountManager::MountPointInfo& mount_info) { | 129 const disks::DiskMountManager::MountPointInfo& mount_info) { |
| 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 131 | 131 |
| 132 // Ignore mount points that are not devices. | 132 // Ignore mount points that are not devices. |
| 133 if (mount_info.mount_type != MOUNT_TYPE_DEVICE) | 133 if (mount_info.mount_type != MOUNT_TYPE_DEVICE) |
| 134 return; | 134 return; |
| 135 // Ignore errors. | 135 // Ignore errors. |
| 136 if (error_code != MOUNT_ERROR_NONE) | 136 if (error_code != MOUNT_ERROR_NONE) |
| 137 return; | 137 return; |
| 138 if (mount_info.mount_condition != disks::MOUNT_CONDITION_NONE) | 138 if (mount_info.mount_condition != disks::MOUNT_CONDITION_NONE) |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 switch (event) { | 141 switch (event) { |
| 142 case disks::DiskMountManager::MOUNTING: { | 142 case disks::DiskMountManager::MOUNTING: { |
| 143 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 143 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
| 144 NOTREACHED(); | 144 NOTREACHED(); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
| 149 BrowserThread::FILE, FROM_HERE, | 149 BrowserThread::FILE, FROM_HERE, |
| 150 base::Bind( | 150 base::Bind( |
| 151 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, | 151 &StorageMonitorCros::CheckMountedPathOnFileThread, |
|
vandebo (ex-Chrome)
2013/03/02 00:23:37
nit: line wrap.
| |
| 152 this, mount_info)); | 152 this, mount_info)); |
| 153 break; | 153 break; |
| 154 } | 154 } |
| 155 case disks::DiskMountManager::UNMOUNTING: { | 155 case disks::DiskMountManager::UNMOUNTING: { |
| 156 MountMap::iterator it = mount_map_.find(mount_info.mount_path); | 156 MountMap::iterator it = mount_map_.find(mount_info.mount_path); |
| 157 if (it == mount_map_.end()) | 157 if (it == mount_map_.end()) |
| 158 return; | 158 return; |
| 159 receiver()->ProcessDetach(it->second.storage_info.device_id); | 159 receiver()->ProcessDetach(it->second.storage_info.device_id); |
| 160 mount_map_.erase(it); | 160 mount_map_.erase(it); |
| 161 break; | 161 break; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 void RemovableDeviceNotificationsCros::OnFormatEvent( | 166 void StorageMonitorCros::OnFormatEvent( |
| 167 disks::DiskMountManager::FormatEvent event, | 167 disks::DiskMountManager::FormatEvent event, |
| 168 FormatError error_code, | 168 FormatError error_code, |
| 169 const std::string& device_path) { | 169 const std::string& device_path) { |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool RemovableDeviceNotificationsCros::GetStorageInfoForPath( | 172 bool StorageMonitorCros::GetStorageInfoForPath( |
| 173 const base::FilePath& path, | 173 const base::FilePath& path, |
| 174 StorageInfo* device_info) const { | 174 StorageInfo* device_info) const { |
| 175 if (!path.IsAbsolute()) | 175 if (!path.IsAbsolute()) |
| 176 return false; | 176 return false; |
| 177 | 177 |
| 178 base::FilePath current = path; | 178 base::FilePath current = path; |
| 179 while (!ContainsKey(mount_map_, current.value()) && | 179 while (!ContainsKey(mount_map_, current.value()) && |
| 180 current != current.DirName()) { | 180 current != current.DirName()) { |
| 181 current = current.DirName(); | 181 current = current.DirName(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 MountMap::const_iterator info_it = mount_map_.find(current.value()); | 184 MountMap::const_iterator info_it = mount_map_.find(current.value()); |
| 185 if (info_it == mount_map_.end()) | 185 if (info_it == mount_map_.end()) |
| 186 return false; | 186 return false; |
| 187 | 187 |
| 188 if (device_info) | 188 if (device_info) |
| 189 *device_info = info_it->second.storage_info; | 189 *device_info = info_it->second.storage_info; |
| 190 return true; | 190 return true; |
| 191 } | 191 } |
| 192 | 192 |
| 193 uint64 RemovableDeviceNotificationsCros::GetStorageSize( | 193 uint64 StorageMonitorCros::GetStorageSize( |
| 194 const std::string& device_location) const { | 194 const std::string& device_location) const { |
| 195 MountMap::const_iterator info_it = mount_map_.find(device_location); | 195 MountMap::const_iterator info_it = mount_map_.find(device_location); |
| 196 return (info_it != mount_map_.end()) ? | 196 return (info_it != mount_map_.end()) ? |
| 197 info_it->second.storage_size_in_bytes : 0; | 197 info_it->second.storage_size_in_bytes : 0; |
| 198 } | 198 } |
| 199 | 199 |
| 200 void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread( | 200 void StorageMonitorCros::CheckMountedPathOnFileThread( |
| 201 const disks::DiskMountManager::MountPointInfo& mount_info) { | 201 const disks::DiskMountManager::MountPointInfo& mount_info) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 203 | 203 |
| 204 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); | 204 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); |
| 205 | 205 |
| 206 BrowserThread::PostTask( | 206 BrowserThread::PostTask( |
| 207 BrowserThread::UI, FROM_HERE, | 207 BrowserThread::UI, FROM_HERE, |
| 208 base::Bind(&RemovableDeviceNotificationsCros::AddMountedPathOnUIThread, | 208 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, |
| 209 this, mount_info, has_dcim)); | 209 this, mount_info, has_dcim)); |
|
vandebo (ex-Chrome)
2013/03/02 00:23:37
'this,' will fit on the previous line
| |
| 210 } | 210 } |
| 211 | 211 |
| 212 void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread( | 212 void StorageMonitorCros::AddMountedPathOnUIThread( |
| 213 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { | 213 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { |
| 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 215 | 215 |
| 216 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 216 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
| 217 // CheckExistingMountPointsOnUIThread() added the mount point information | 217 // CheckExistingMountPointsOnUIThread() added the mount point information |
| 218 // in the map before the device attached handler is called. Therefore, an | 218 // in the map before the device attached handler is called. Therefore, an |
| 219 // entry for the device already exists in the map. | 219 // entry for the device already exists in the map. |
| 220 return; | 220 return; |
| 221 } | 221 } |
| 222 | 222 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 246 storage_size_in_bytes | 246 storage_size_in_bytes |
| 247 }; | 247 }; |
| 248 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); | 248 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
| 249 receiver()->ProcessAttach(StorageInfo( | 249 receiver()->ProcessAttach(StorageInfo( |
| 250 device_id, | 250 device_id, |
| 251 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), | 251 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), |
| 252 mount_info.mount_path)); | 252 mount_info.mount_path)); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace chromeos | 255 } // namespace chromeos |
| OLD | NEW |