| 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/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) | 155 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) |
| 156 return; | 156 return; |
| 157 // Ignore errors. | 157 // Ignore errors. |
| 158 if (error_code != chromeos::MOUNT_ERROR_NONE) | 158 if (error_code != chromeos::MOUNT_ERROR_NONE) |
| 159 return; | 159 return; |
| 160 if (mount_info.mount_condition != chromeos::disks::MOUNT_CONDITION_NONE) | 160 if (mount_info.mount_condition != chromeos::disks::MOUNT_CONDITION_NONE) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 switch (event) { | 163 switch (event) { |
| 164 case DiskMountManager::MOUNTING: { | 164 case DiskMountManager::MOUNTING: { |
| 165 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 165 if (base::ContainsKey(mount_map_, mount_info.mount_path)) { |
| 166 NOTREACHED(); | 166 NOTREACHED(); |
| 167 return; | 167 return; |
| 168 } | 168 } |
| 169 | 169 |
| 170 BrowserThread::PostTaskAndReplyWithResult( | 170 BrowserThread::PostTaskAndReplyWithResult( |
| 171 BrowserThread::FILE, FROM_HERE, | 171 BrowserThread::FILE, FROM_HERE, |
| 172 base::Bind(&CheckMountedPathOnFileThread, mount_info), | 172 base::Bind(&CheckMountedPathOnFileThread, mount_info), |
| 173 base::Bind(&StorageMonitorCros::AddMountedPath, | 173 base::Bind(&StorageMonitorCros::AddMountedPath, |
| 174 weak_ptr_factory_.GetWeakPtr(), mount_info)); | 174 weak_ptr_factory_.GetWeakPtr(), mount_info)); |
| 175 break; | 175 break; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 203 | 203 |
| 204 if (media_transfer_protocol_device_observer_->GetStorageInfoForPath( | 204 if (media_transfer_protocol_device_observer_->GetStorageInfoForPath( |
| 205 path, device_info)) { | 205 path, device_info)) { |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 if (!path.IsAbsolute()) | 209 if (!path.IsAbsolute()) |
| 210 return false; | 210 return false; |
| 211 | 211 |
| 212 base::FilePath current = path; | 212 base::FilePath current = path; |
| 213 while (!ContainsKey(mount_map_, current.value()) && | 213 while (!base::ContainsKey(mount_map_, current.value()) && |
| 214 current != current.DirName()) { | 214 current != current.DirName()) { |
| 215 current = current.DirName(); | 215 current = current.DirName(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 MountMap::const_iterator info_it = mount_map_.find(current.value()); | 218 MountMap::const_iterator info_it = mount_map_.find(current.value()); |
| 219 if (info_it == mount_map_.end()) | 219 if (info_it == mount_map_.end()) |
| 220 return false; | 220 return false; |
| 221 | 221 |
| 222 *device_info = info_it->second; | 222 *device_info = info_it->second; |
| 223 return true; | 223 return true; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 device::MediaTransferProtocolManager* | 273 device::MediaTransferProtocolManager* |
| 274 StorageMonitorCros::media_transfer_protocol_manager() { | 274 StorageMonitorCros::media_transfer_protocol_manager() { |
| 275 return media_transfer_protocol_manager_.get(); | 275 return media_transfer_protocol_manager_.get(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void StorageMonitorCros::AddMountedPath( | 278 void StorageMonitorCros::AddMountedPath( |
| 279 const DiskMountManager::MountPointInfo& mount_info, | 279 const DiskMountManager::MountPointInfo& mount_info, |
| 280 bool has_dcim) { | 280 bool has_dcim) { |
| 281 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 282 | 282 |
| 283 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 283 if (base::ContainsKey(mount_map_, mount_info.mount_path)) { |
| 284 // CheckExistingMountPointsOnUIThread() added the mount point information | 284 // CheckExistingMountPointsOnUIThread() added the mount point information |
| 285 // in the map before the device attached handler is called. Therefore, an | 285 // in the map before the device attached handler is called. Therefore, an |
| 286 // entry for the device already exists in the map. | 286 // entry for the device already exists in the map. |
| 287 return; | 287 return; |
| 288 } | 288 } |
| 289 | 289 |
| 290 // Get the media device uuid and label if exists. | 290 // Get the media device uuid and label if exists. |
| 291 StorageInfo info; | 291 StorageInfo info; |
| 292 if (!GetDeviceInfo(mount_info, has_dcim, &info)) | 292 if (!GetDeviceInfo(mount_info, has_dcim, &info)) |
| 293 return; | 293 return; |
| 294 | 294 |
| 295 if (info.device_id().empty()) | 295 if (info.device_id().empty()) |
| 296 return; | 296 return; |
| 297 | 297 |
| 298 mount_map_.insert(std::make_pair(mount_info.mount_path, info)); | 298 mount_map_.insert(std::make_pair(mount_info.mount_path, info)); |
| 299 | 299 |
| 300 receiver()->ProcessAttach(info); | 300 receiver()->ProcessAttach(info); |
| 301 } | 301 } |
| 302 | 302 |
| 303 StorageMonitor* StorageMonitor::CreateInternal() { | 303 StorageMonitor* StorageMonitor::CreateInternal() { |
| 304 return new StorageMonitorCros(); | 304 return new StorageMonitorCros(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace storage_monitor | 307 } // namespace storage_monitor |
| OLD | NEW |