| 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 #include "chrome/browser/storage_monitor/media_storage_util.h" | 5 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 47 base::Bind(callback, file_util::PathExists(path))); | 47 base::Bind(callback, file_util::PathExists(path))); |
| 48 } | 48 } |
| 49 | 49 |
| 50 typedef std::vector<StorageInfo> StorageInfoList; | 50 typedef std::vector<StorageInfo> StorageInfoList; |
| 51 | 51 |
| 52 bool IsRemovableStorageAttached(const std::string& id) { | 52 bool IsRemovableStorageAttached(const std::string& id) { |
| 53 StorageInfoList devices = StorageMonitor::GetInstance()->GetAttachedStorage(); | 53 StorageInfoList devices = StorageMonitor::GetInstance()->GetAttachedStorage(); |
| 54 for (StorageInfoList::const_iterator it = devices.begin(); | 54 for (StorageInfoList::const_iterator it = devices.begin(); |
| 55 it != devices.end(); ++it) { | 55 it != devices.end(); ++it) { |
| 56 if (it->device_id == id) | 56 if (it->device_id() == id) |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 base::FilePath::StringType FindRemovableStorageLocationById( | 62 base::FilePath::StringType FindRemovableStorageLocationById( |
| 63 const std::string& device_id) { | 63 const std::string& device_id) { |
| 64 StorageInfoList devices = StorageMonitor::GetInstance()->GetAttachedStorage(); | 64 StorageInfoList devices = StorageMonitor::GetInstance()->GetAttachedStorage(); |
| 65 for (StorageInfoList::const_iterator it = devices.begin(); | 65 for (StorageInfoList::const_iterator it = devices.begin(); |
| 66 it != devices.end(); ++it) { | 66 it != devices.end(); ++it) { |
| 67 if (it->device_id == device_id) | 67 if (it->device_id() == device_id) |
| 68 return it->location; | 68 return it->location(); |
| 69 } | 69 } |
| 70 return base::FilePath::StringType(); | 70 return base::FilePath::StringType(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { | 73 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 75 MediaStorageUtil::DeviceIdSet missing_devices; | 75 MediaStorageUtil::DeviceIdSet missing_devices; |
| 76 | 76 |
| 77 for (MediaStorageUtil::DeviceIdSet::const_iterator it = devices->begin(); | 77 for (MediaStorageUtil::DeviceIdSet::const_iterator it = devices->begin(); |
| 78 it != devices->end(); | 78 it != devices->end(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 DCHECK(device_info); | 155 DCHECK(device_info); |
| 156 DCHECK(relative_path); | 156 DCHECK(relative_path); |
| 157 | 157 |
| 158 if (!path.IsAbsolute()) | 158 if (!path.IsAbsolute()) |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 StorageInfo info; | 161 StorageInfo info; |
| 162 StorageMonitor* monitor = StorageMonitor::GetInstance(); | 162 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
| 163 bool found_device = monitor->GetStorageInfoForPath(path, &info); | 163 bool found_device = monitor->GetStorageInfoForPath(path, &info); |
| 164 | 164 |
| 165 if (found_device && StorageInfo::IsRemovableDevice(info.device_id)) { | 165 if (found_device && StorageInfo::IsRemovableDevice(info.device_id())) { |
| 166 base::FilePath sub_folder_path; | 166 base::FilePath sub_folder_path; |
| 167 base::FilePath device_path(info.location); | 167 base::FilePath device_path(info.location()); |
| 168 if (path != device_path) { | 168 if (path != device_path) { |
| 169 bool success = device_path.AppendRelativePath(path, &sub_folder_path); | 169 bool success = device_path.AppendRelativePath(path, &sub_folder_path); |
| 170 DCHECK(success); | 170 DCHECK(success); |
| 171 } | 171 } |
| 172 | 172 |
| 173 *device_info = info; | 173 *device_info = info; |
| 174 *relative_path = sub_folder_path; | 174 *relative_path = sub_folder_path; |
| 175 return true; | 175 return true; |
| 176 } | 176 } |
| 177 | 177 |
| 178 // TODO(vandebo) Check to see if the path points to an iTunes library file. | 178 // TODO(vandebo) Check to see if the path points to an iTunes library file. |
| 179 | 179 |
| 180 // On Posix systems, there's one root so any absolute path could be valid. | 180 // On Posix systems, there's one root so any absolute path could be valid. |
| 181 // TODO(gbillock): Delete this stanza? Posix systems should have the root | 181 // TODO(gbillock): Delete this stanza? Posix systems should have the root |
| 182 // volume information. If not, we should move the below into the | 182 // volume information. If not, we should move the below into the |
| 183 // right GetStorageInfoForPath implementations. | 183 // right GetStorageInfoForPath implementations. |
| 184 #if !defined(OS_POSIX) | 184 #if !defined(OS_POSIX) |
| 185 if (!found_device) | 185 if (!found_device) |
| 186 return false; | 186 return false; |
| 187 #endif | 187 #endif |
| 188 | 188 |
| 189 // Handle non-removable devices. Note: this is just overwriting | 189 // Handle non-removable devices. Note: this is just overwriting |
| 190 // good values from StorageMonitor. | 190 // good values from StorageMonitor. |
| 191 // TODO(gbillock): Make sure return values from that class are definitive, | 191 // TODO(gbillock): Make sure return values from that class are definitive, |
| 192 // and don't do this here. | 192 // and don't do this here. |
| 193 info.device_id = StorageInfo::MakeDeviceId(StorageInfo::FIXED_MASS_STORAGE, | 193 info.set_device_id( |
| 194 path.AsUTF8Unsafe()); | 194 StorageInfo::MakeDeviceId(StorageInfo::FIXED_MASS_STORAGE, |
| 195 path.AsUTF8Unsafe())); |
| 195 *device_info = info; | 196 *device_info = info; |
| 196 *relative_path = base::FilePath(); | 197 *relative_path = base::FilePath(); |
| 197 return true; | 198 return true; |
| 198 } | 199 } |
| 199 | 200 |
| 200 // static | 201 // static |
| 201 base::FilePath MediaStorageUtil::FindDevicePathById( | 202 base::FilePath MediaStorageUtil::FindDevicePathById( |
| 202 const std::string& device_id) { | 203 const std::string& device_id) { |
| 203 StorageInfo::Type type; | 204 StorageInfo::Type type; |
| 204 std::string unique_id; | 205 std::string unique_id; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 static_cast<enum DeviceInfoHistogramBuckets>(event_number); | 242 static_cast<enum DeviceInfoHistogramBuckets>(event_number); |
| 242 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { | 243 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { |
| 243 NOTREACHED(); | 244 NOTREACHED(); |
| 244 return; | 245 return; |
| 245 } | 246 } |
| 246 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, | 247 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, |
| 247 DEVICE_INFO_BUCKET_BOUNDARY); | 248 DEVICE_INFO_BUCKET_BOUNDARY); |
| 248 } | 249 } |
| 249 | 250 |
| 250 } // namespace chrome | 251 } // namespace chrome |
| OLD | NEW |