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