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 // chrome::MediaStorageUtil implementation. | 5 // chrome::MediaStorageUtil implementation. |
6 | 6 |
7 #include "chrome/browser/system_monitor/media_storage_util.h" | 7 #include "chrome/browser/system_monitor/media_storage_util.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/system_monitor/system_monitor.h" | 15 #include "base/system_monitor/system_monitor.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 | 19 |
19 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
20 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" | 21 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" |
21 #elif defined(OS_LINUX) | 22 #elif defined(OS_LINUX) |
22 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" | 23 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" |
23 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
24 #include "chrome/browser/system_monitor/removable_device_notifications_mac.h" | 25 #include "chrome/browser/system_monitor/removable_device_notifications_mac.h" |
25 #elif defined(OS_WIN) | 26 #elif defined(OS_WIN) |
26 #include "chrome/browser/system_monitor/removable_device_notifications_window_wi
n.h" | 27 #include "chrome/browser/system_monitor/removable_device_notifications_window_wi
n.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 248 |
248 #if defined(OS_LINUX) | 249 #if defined(OS_LINUX) |
249 if (!found_device) { | 250 if (!found_device) { |
250 MediaTransferProtocolDeviceObserverLinux* mtp_manager = | 251 MediaTransferProtocolDeviceObserverLinux* mtp_manager = |
251 MediaTransferProtocolDeviceObserverLinux::GetInstance(); | 252 MediaTransferProtocolDeviceObserverLinux::GetInstance(); |
252 found_device = mtp_manager->GetStorageInfoForPath(path, &device_info); | 253 found_device = mtp_manager->GetStorageInfoForPath(path, &device_info); |
253 } | 254 } |
254 #endif | 255 #endif |
255 | 256 |
256 if (found_device && IsRemovableDevice(device_info.device_id)) { | 257 if (found_device && IsRemovableDevice(device_info.device_id)) { |
| 258 FilePath sub_folder_path; |
| 259 if (device_name || relative_path) { |
| 260 bool success = FilePath(device_info.location) |
| 261 .AppendRelativePath(path, &sub_folder_path); |
| 262 DCHECK(success); |
| 263 } |
| 264 |
257 if (device_id) | 265 if (device_id) |
258 *device_id = device_info.device_id; | 266 *device_id = device_info.device_id; |
259 if (device_name) | 267 |
| 268 if (device_name) { |
| 269 #if defined(OS_CHROMEOS) |
| 270 *device_name = GetDisplayNameForDevice( |
| 271 notifier->GetStorageSize(device_info.location), |
| 272 sub_folder_path.value().empty() ? |
| 273 device_info.name : |
| 274 sub_folder_path.BaseName().LossyDisplayName() + |
| 275 ASCIIToUTF16(" - ") + device_info.name); |
| 276 #else |
260 *device_name = device_info.name; | 277 *device_name = device_info.name; |
261 if (relative_path) { | |
262 *relative_path = FilePath(); | |
263 FilePath mount_point(device_info.location); | |
264 bool success = mount_point.AppendRelativePath(path, relative_path); | |
265 #if defined(OS_POSIX) | |
266 if (!relative_path->value().empty() && device_name) { | |
267 *device_name += ASCIIToUTF16(" (") + | |
268 relative_path->BaseName().LossyDisplayName() + ASCIIToUTF16(")"); | |
269 } | |
270 #endif | 278 #endif |
271 DCHECK(success); | |
272 } | 279 } |
| 280 |
| 281 if (relative_path) |
| 282 *relative_path = sub_folder_path; |
273 return true; | 283 return true; |
274 } | 284 } |
275 | 285 |
276 // On Posix systems, there's one root so any absolute path could be valid. | 286 // On Posix systems, there's one root so any absolute path could be valid. |
277 #if !defined(OS_POSIX) | 287 #if !defined(OS_POSIX) |
278 if (!found_device) | 288 if (!found_device) |
279 return false; | 289 return false; |
280 #endif | 290 #endif |
281 | 291 |
282 if (device_id) | 292 if (device_id) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 341 |
332 // static | 342 // static |
333 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 343 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
334 GetDeviceInfoFromPathFunction function) { | 344 GetDeviceInfoFromPathFunction function) { |
335 g_test_get_device_info_from_path_function = function; | 345 g_test_get_device_info_from_path_function = function; |
336 } | 346 } |
337 | 347 |
338 MediaStorageUtil::MediaStorageUtil() {} | 348 MediaStorageUtil::MediaStorageUtil() {} |
339 | 349 |
340 } // namespace chrome | 350 } // namespace chrome |
OLD | NEW |