| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | 15 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
| 15 #include "chrome/browser/storage_monitor/storage_monitor.h" | 16 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "ui/base/text/bytes_formatting.h" |
| 17 | 19 |
| 18 #if defined(OS_LINUX) // Implies OS_CHROMEOS | 20 #if defined(OS_LINUX) // Implies OS_CHROMEOS |
| 19 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" | 21 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
| 20 #endif | 22 #endif |
| 21 | 23 |
| 22 using content::BrowserThread; | 24 using content::BrowserThread; |
| 23 | 25 |
| 24 namespace chrome { | 26 namespace chrome { |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (sub_folder.empty()) | 121 if (sub_folder.empty()) |
| 120 return device_name; | 122 return device_name; |
| 121 return (sub_folder.BaseName().LossyDisplayName() + | 123 return (sub_folder.BaseName().LossyDisplayName() + |
| 122 ASCIIToUTF16(" - ") + | 124 ASCIIToUTF16(" - ") + |
| 123 device_name); | 125 device_name); |
| 124 } | 126 } |
| 125 | 127 |
| 126 } // namespace | 128 } // namespace |
| 127 | 129 |
| 128 // static | 130 // static |
| 131 bool MediaStorageUtil::HasDcim(const base::FilePath::StringType& mount_point) { |
| 132 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 133 |
| 134 base::FilePath dcim_path(mount_point); |
| 135 base::FilePath::StringType dcim_dir(kDCIMDirectoryName); |
| 136 if (!file_util::DirectoryExists(dcim_path.Append(dcim_dir))) { |
| 137 // Check for lowercase 'dcim' as well. |
| 138 base::FilePath dcim_path_lower( |
| 139 dcim_path.Append(StringToLowerASCII(dcim_dir))); |
| 140 if (!file_util::DirectoryExists(dcim_path_lower)) |
| 141 return false; |
| 142 } |
| 143 return true; |
| 144 } |
| 145 |
| 146 // static |
| 147 string16 MediaStorageUtil::GetFullProductName(const std::string& vendor_name, |
| 148 const std::string& model_name) { |
| 149 if (vendor_name.empty() && model_name.empty()) |
| 150 return string16(); |
| 151 |
| 152 std::string product_name; |
| 153 if (vendor_name.empty()) |
| 154 product_name = model_name; |
| 155 else if (model_name.empty()) |
| 156 product_name = vendor_name; |
| 157 else |
| 158 product_name = vendor_name + ", " + model_name; |
| 159 return IsStringUTF8(product_name) ? |
| 160 UTF8ToUTF16("(" + product_name + ")") : string16(); |
| 161 } |
| 162 |
| 163 // static |
| 164 string16 MediaStorageUtil::GetDisplayNameForDevice(uint64 storage_size_in_bytes, |
| 165 const string16& name) { |
| 166 DCHECK(!name.empty()); |
| 167 return (storage_size_in_bytes == 0) ? |
| 168 name : ui::FormatBytes(storage_size_in_bytes) + ASCIIToUTF16(" ") + name; |
| 169 } |
| 170 |
| 171 // static |
| 129 std::string MediaStorageUtil::MakeDeviceId(Type type, | 172 std::string MediaStorageUtil::MakeDeviceId(Type type, |
| 130 const std::string& unique_id) { | 173 const std::string& unique_id) { |
| 131 DCHECK(!unique_id.empty()); | 174 DCHECK(!unique_id.empty()); |
| 132 switch (type) { | 175 switch (type) { |
| 133 case REMOVABLE_MASS_STORAGE_WITH_DCIM: | 176 case REMOVABLE_MASS_STORAGE_WITH_DCIM: |
| 134 return std::string(kRemovableMassStorageWithDCIMPrefix) + unique_id; | 177 return std::string(kRemovableMassStorageWithDCIMPrefix) + unique_id; |
| 135 case REMOVABLE_MASS_STORAGE_NO_DCIM: | 178 case REMOVABLE_MASS_STORAGE_NO_DCIM: |
| 136 return std::string(kRemovableMassStorageNoDCIMPrefix) + unique_id; | 179 return std::string(kRemovableMassStorageNoDCIMPrefix) + unique_id; |
| 137 case FIXED_MASS_STORAGE: | 180 case FIXED_MASS_STORAGE: |
| 138 return std::string(kFixedMassStoragePrefix) + unique_id; | 181 return std::string(kFixedMassStoragePrefix) + unique_id; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 static_cast<enum DeviceInfoHistogramBuckets>(event_number); | 403 static_cast<enum DeviceInfoHistogramBuckets>(event_number); |
| 361 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { | 404 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { |
| 362 NOTREACHED(); | 405 NOTREACHED(); |
| 363 return; | 406 return; |
| 364 } | 407 } |
| 365 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, | 408 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, |
| 366 DEVICE_INFO_BUCKET_BOUNDARY); | 409 DEVICE_INFO_BUCKET_BOUNDARY); |
| 367 } | 410 } |
| 368 | 411 |
| 369 } // namespace chrome | 412 } // namespace chrome |
| OLD | NEW |