OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/storage_monitor/storage_info.h" | 5 #include "components/storage_monitor/storage_info.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/storage_monitor/media_storage_util.h" |
| 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/text/bytes_formatting.h" |
8 | 12 |
9 namespace { | 13 namespace { |
10 | 14 |
11 // Prefix constants for different device id spaces. | 15 // Prefix constants for different device id spaces. |
12 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; | 16 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; |
13 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; | 17 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; |
14 const char kFixedMassStoragePrefix[] = "path:"; | 18 const char kFixedMassStoragePrefix[] = "path:"; |
15 const char kMtpPtpPrefix[] = "mtp:"; | 19 const char kMtpPtpPrefix[] = "mtp:"; |
16 const char kMacImageCapturePrefix[] = "ic:"; | 20 const char kMacImageCapturePrefix[] = "ic:"; |
17 const char kITunesPrefix[] = "itunes:"; | 21 const char kITunesPrefix[] = "itunes:"; |
18 const char kPicasaPrefix[] = "picasa:"; | 22 const char kPicasaPrefix[] = "picasa:"; |
19 const char kIPhotoPrefix[] = "iphoto:"; | 23 const char kIPhotoPrefix[] = "iphoto:"; |
20 | 24 |
| 25 base::string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes, |
| 26 const base::string16& name) { |
| 27 DCHECK(!name.empty()); |
| 28 return (storage_size_in_bytes == 0) ? |
| 29 name : |
| 30 ui::FormatBytes(storage_size_in_bytes) + base::ASCIIToUTF16(" ") + name; |
| 31 } |
| 32 |
| 33 base::string16 GetFullProductName(const base::string16& vendor_name, |
| 34 const base::string16& model_name) { |
| 35 if (vendor_name.empty() && model_name.empty()) |
| 36 return base::string16(); |
| 37 |
| 38 base::string16 product_name; |
| 39 if (vendor_name.empty()) |
| 40 product_name = model_name; |
| 41 else if (model_name.empty()) |
| 42 product_name = vendor_name; |
| 43 else if (!vendor_name.empty() && !model_name.empty()) |
| 44 product_name = vendor_name + base::UTF8ToUTF16(", ") + model_name; |
| 45 |
| 46 return product_name; |
| 47 } |
| 48 |
21 } // namespace | 49 } // namespace |
22 | 50 |
23 namespace storage_monitor { | 51 namespace storage_monitor { |
24 | 52 |
25 StorageInfo::StorageInfo() : total_size_in_bytes_(0) { | 53 StorageInfo::StorageInfo() : total_size_in_bytes_(0) { |
26 } | 54 } |
27 | 55 |
28 StorageInfo::StorageInfo(const std::string& device_id_in, | 56 StorageInfo::StorageInfo(const std::string& device_id_in, |
29 const base::string16& device_name, | |
30 const base::FilePath::StringType& device_location, | 57 const base::FilePath::StringType& device_location, |
31 const base::string16& label, | 58 const base::string16& label, |
32 const base::string16& vendor, | 59 const base::string16& vendor, |
33 const base::string16& model, | 60 const base::string16& model, |
34 uint64 size_in_bytes) | 61 uint64 size_in_bytes) |
35 : device_id_(device_id_in), | 62 : device_id_(device_id_in), |
36 name_(device_name), | |
37 location_(device_location), | 63 location_(device_location), |
38 storage_label_(label), | 64 storage_label_(label), |
39 vendor_name_(vendor), | 65 vendor_name_(vendor), |
40 model_name_(model), | 66 model_name_(model), |
41 total_size_in_bytes_(size_in_bytes) { | 67 total_size_in_bytes_(size_in_bytes) { |
42 } | 68 } |
43 | 69 |
44 StorageInfo::~StorageInfo() { | 70 StorageInfo::~StorageInfo() { |
45 } | 71 } |
46 | 72 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 Type type; | 173 Type type; |
148 return CrackDeviceId(device_id, &type, NULL) && type == IPHOTO; | 174 return CrackDeviceId(device_id, &type, NULL) && type == IPHOTO; |
149 } | 175 } |
150 | 176 |
151 // static | 177 // static |
152 bool StorageInfo::IsPicasaDevice(const std::string& device_id) { | 178 bool StorageInfo::IsPicasaDevice(const std::string& device_id) { |
153 Type type; | 179 Type type; |
154 return CrackDeviceId(device_id, &type, NULL) && type == PICASA; | 180 return CrackDeviceId(device_id, &type, NULL) && type == PICASA; |
155 } | 181 } |
156 | 182 |
| 183 base::string16 StorageInfo::GetDisplayName(bool with_size) const { |
| 184 return GetDisplayNameWithOverride(base::string16(), with_size); |
| 185 } |
| 186 |
| 187 base::string16 StorageInfo::GetDisplayNameWithOverride( |
| 188 const base::string16& override_display_name, bool with_size) const { |
| 189 if (!IsRemovableDevice(device_id_)) { |
| 190 if (!storage_label_.empty()) |
| 191 return storage_label_; |
| 192 return base::FilePath(location_).LossyDisplayName(); |
| 193 } |
| 194 |
| 195 base::string16 name = override_display_name; |
| 196 if (name.empty()) |
| 197 name = storage_label_; |
| 198 if (name.empty()) |
| 199 name = GetFullProductName(vendor_name_, model_name_); |
| 200 if (name.empty()) |
| 201 name = base::ASCIIToUTF16("Unlabeled device"); |
| 202 |
| 203 if (with_size) |
| 204 name = GetDisplayNameForDevice(total_size_in_bytes_, name); |
| 205 return name; |
| 206 } |
| 207 |
157 } // namespace storage_monitor | 208 } // namespace storage_monitor |
OLD | NEW |