| 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/system_monitor/system_monitor.h" | 15 #include "base/system_monitor/system_monitor.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 | 17 |
| 17 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_
chromeos.h" | 19 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_
chromeos.h" |
| 19 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" | 20 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" |
| 20 #elif defined(OS_LINUX) | 21 #elif defined(OS_LINUX) |
| 21 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" | 22 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" |
| 22 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
| 23 #include "chrome/browser/system_monitor/removable_device_notifications_mac.h" | 24 #include "chrome/browser/system_monitor/removable_device_notifications_mac.h" |
| 24 #elif defined(OS_WIN) | 25 #elif defined(OS_WIN) |
| 25 #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" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 using base::SystemMonitor; | 29 using base::SystemMonitor; |
| 29 using content::BrowserThread; | 30 using content::BrowserThread; |
| 30 | 31 |
| 31 namespace chrome { | 32 namespace chrome { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 typedef std::vector<SystemMonitor::RemovableStorageInfo> RemovableStorageInfo; | 36 typedef std::vector<SystemMonitor::RemovableStorageInfo> RemovableStorageInfo; |
| 36 | 37 |
| 38 // MediaDeviceNotification.DeviceInfo histogram values. |
| 39 enum DeviceInfoHistogramBuckets { |
| 40 MASS_STORAGE_DEVICE_NAME_AND_UUID_AVAILABLE, |
| 41 MASS_STORAGE_DEVICE_UUID_MISSING, |
| 42 MASS_STORAGE_DEVICE_NAME_MISSING, |
| 43 MASS_STORAGE_DEVICE_NAME_AND_UUID_MISSING, |
| 44 MTP_STORAGE_DEVICE_NAME_AND_UUID_AVAILABLE, |
| 45 MTP_STORAGE_DEVICE_UUID_MISSING, |
| 46 MTP_STORAGE_DEVICE_NAME_MISSING, |
| 47 MTP_STORAGE_DEVICE_NAME_AND_UUID_MISSING, |
| 48 DEVICE_INFO_BUCKET_BOUNDARY |
| 49 }; |
| 50 |
| 37 // Prefix constants for different device id spaces. | 51 // Prefix constants for different device id spaces. |
| 38 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; | 52 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; |
| 39 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; | 53 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; |
| 40 const char kFixedMassStoragePrefix[] = "path:"; | 54 const char kFixedMassStoragePrefix[] = "path:"; |
| 41 const char kMtpPtpPrefix[] = "mtp:"; | 55 const char kMtpPtpPrefix[] = "mtp:"; |
| 42 | 56 |
| 43 static bool (*g_test_get_device_info_from_path_function)( | 57 static bool (*g_test_get_device_info_from_path_function)( |
| 44 const FilePath& path, std::string* device_id, string16* device_name, | 58 const FilePath& path, std::string* device_id, string16* device_name, |
| 45 FilePath* relative_path) = NULL; | 59 FilePath* relative_path) = NULL; |
| 46 | 60 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return FilePath::FromUTF8Unsafe(unique_id); | 283 return FilePath::FromUTF8Unsafe(unique_id); |
| 270 } | 284 } |
| 271 | 285 |
| 272 DCHECK(type == MTP_OR_PTP || | 286 DCHECK(type == MTP_OR_PTP || |
| 273 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || | 287 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || |
| 274 type == REMOVABLE_MASS_STORAGE_NO_DCIM); | 288 type == REMOVABLE_MASS_STORAGE_NO_DCIM); |
| 275 return FilePath(FindRemovableStorageLocationById(device_id)); | 289 return FilePath(FindRemovableStorageLocationById(device_id)); |
| 276 } | 290 } |
| 277 | 291 |
| 278 // static | 292 // static |
| 293 void MediaStorageUtil::RecordDeviceInfoHistogram(bool mass_storage, |
| 294 const std::string& device_uuid, |
| 295 const string16& device_name) { |
| 296 unsigned int event_number = 0; |
| 297 if (!mass_storage) |
| 298 event_number = 4; |
| 299 |
| 300 if (device_name.empty()) |
| 301 event_number += 2; |
| 302 |
| 303 if (device_uuid.empty()) |
| 304 event_number += 1; |
| 305 enum DeviceInfoHistogramBuckets event = |
| 306 static_cast<enum DeviceInfoHistogramBuckets>(event_number); |
| 307 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { |
| 308 NOTREACHED(); |
| 309 return; |
| 310 } |
| 311 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, |
| 312 DEVICE_INFO_BUCKET_BOUNDARY); |
| 313 } |
| 314 |
| 315 // static |
| 279 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( | 316 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( |
| 280 GetDeviceInfoFromPathFunction function) { | 317 GetDeviceInfoFromPathFunction function) { |
| 281 g_test_get_device_info_from_path_function = function; | 318 g_test_get_device_info_from_path_function = function; |
| 282 } | 319 } |
| 283 | 320 |
| 284 MediaStorageUtil::MediaStorageUtil() {} | 321 MediaStorageUtil::MediaStorageUtil() {} |
| 285 | 322 |
| 286 } // namespace chrome | 323 } // namespace chrome |
| OLD | NEW |