| 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::RemovableDeviceNotificationsCros implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/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_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" | 15 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
| 16 #include "chrome/browser/system_monitor/media_storage_util.h" | 16 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 17 #include "chrome/browser/system_monitor/removable_device_constants.h" | 17 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 | 21 |
| 22 using base::SystemMonitor; | |
| 23 | |
| 24 namespace { | 22 namespace { |
| 25 | 23 |
| 26 // Constructs a device name using label or manufacturer (vendor and product) | 24 // Constructs a device name using label or manufacturer (vendor and product) |
| 27 // name details. | 25 // name details. |
| 28 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { | 26 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { |
| 29 if (disk.device_type() == DEVICE_TYPE_SD) { | 27 if (disk.device_type() == DEVICE_TYPE_SD) { |
| 30 // Mount path of an SD card will be one of the following: | 28 // Mount path of an SD card will be one of the following: |
| 31 // (1) /media/removable/<volume_label> | 29 // (1) /media/removable/<volume_label> |
| 32 // (2) /media/removable/SD Card | 30 // (2) /media/removable/SD Card |
| 33 // If the volume label is available, mount path will be (1) else (2). | 31 // If the volume label is available, mount path will be (1) else (2). |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 BrowserThread::FILE, FROM_HERE, | 156 BrowserThread::FILE, FROM_HERE, |
| 159 base::Bind( | 157 base::Bind( |
| 160 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, | 158 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, |
| 161 this, mount_info)); | 159 this, mount_info)); |
| 162 break; | 160 break; |
| 163 } | 161 } |
| 164 case disks::DiskMountManager::UNMOUNTING: { | 162 case disks::DiskMountManager::UNMOUNTING: { |
| 165 MountMap::iterator it = mount_map_.find(mount_info.mount_path); | 163 MountMap::iterator it = mount_map_.find(mount_info.mount_path); |
| 166 if (it == mount_map_.end()) | 164 if (it == mount_map_.end()) |
| 167 return; | 165 return; |
| 168 SystemMonitor::Get()->ProcessRemovableStorageDetached( | 166 ProcessDetach(it->second.storage_info.device_id); |
| 169 it->second.storage_info.device_id); | |
| 170 mount_map_.erase(it); | 167 mount_map_.erase(it); |
| 171 break; | 168 break; |
| 172 } | 169 } |
| 173 } | 170 } |
| 174 } | 171 } |
| 175 | 172 |
| 176 void RemovableDeviceNotificationsCros::OnFormatEvent( | 173 void RemovableDeviceNotificationsCros::OnFormatEvent( |
| 177 disks::DiskMountManager::FormatEvent event, | 174 disks::DiskMountManager::FormatEvent event, |
| 178 FormatError error_code, | 175 FormatError error_code, |
| 179 const std::string& device_path) { | 176 const std::string& device_path) { |
| 180 } | 177 } |
| 181 | 178 |
| 182 bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath( | 179 bool RemovableDeviceNotificationsCros::GetDeviceInfoForPath( |
| 183 const FilePath& path, | 180 const FilePath& path, |
| 184 SystemMonitor::RemovableStorageInfo* device_info) const { | 181 StorageInfo* device_info) const { |
| 185 if (!path.IsAbsolute()) | 182 if (!path.IsAbsolute()) |
| 186 return false; | 183 return false; |
| 187 | 184 |
| 188 FilePath current = path; | 185 FilePath current = path; |
| 189 while (!ContainsKey(mount_map_, current.value()) && | 186 while (!ContainsKey(mount_map_, current.value()) && |
| 190 current != current.DirName()) { | 187 current != current.DirName()) { |
| 191 current = current.DirName(); | 188 current = current.DirName(); |
| 192 } | 189 } |
| 193 | 190 |
| 194 MountMap::const_iterator info_it = mount_map_.find(current.value()); | 191 MountMap::const_iterator info_it = mount_map_.find(current.value()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (unique_id.empty() || device_label.empty()) | 242 if (unique_id.empty() || device_label.empty()) |
| 246 return; | 243 return; |
| 247 | 244 |
| 248 chrome::MediaStorageUtil::Type type = has_dcim ? | 245 chrome::MediaStorageUtil::Type type = has_dcim ? |
| 249 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : | 246 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : |
| 250 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; | 247 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; |
| 251 | 248 |
| 252 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, | 249 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, |
| 253 unique_id); | 250 unique_id); |
| 254 StorageObjectInfo object_info = { | 251 StorageObjectInfo object_info = { |
| 255 base::SystemMonitor::RemovableStorageInfo(device_id, device_label, | 252 StorageInfo(device_id, device_label, mount_info.mount_path), |
| 256 mount_info.mount_path), | |
| 257 storage_size_in_bytes | 253 storage_size_in_bytes |
| 258 }; | 254 }; |
| 259 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); | 255 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
| 260 SystemMonitor::Get()->ProcessRemovableStorageAttached( | 256 ProcessAttach( |
| 261 device_id, | 257 device_id, |
| 262 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), | 258 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), |
| 263 mount_info.mount_path); | 259 mount_info.mount_path); |
| 264 } | 260 } |
| 265 | 261 |
| 266 } // namespace chromeos | 262 } // namespace chromeos |
| 267 | 263 |
| 268 namespace chrome { | 264 namespace chrome { |
| 269 | 265 |
| 270 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { | 266 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { |
| 271 return chromeos::g_removable_device_notifications_chromeos; | 267 return chromeos::g_removable_device_notifications_chromeos; |
| 272 } | 268 } |
| 273 | 269 |
| 274 } // namespace chrome | 270 } // namespace chrome |
| OLD | NEW |