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/storage_info.h" | 5 #include "chrome/browser/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 "chrome/browser/storage_monitor/media_storage_util.h" |
| 10 #include "grit/generated_resources.h" |
| 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/base/text/bytes_formatting.h" |
8 | 13 |
9 namespace chrome { | 14 namespace chrome { |
10 | 15 |
11 namespace { | 16 namespace { |
12 | 17 |
13 // Prefix constants for different device id spaces. | 18 // Prefix constants for different device id spaces. |
14 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; | 19 const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:"; |
15 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; | 20 const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:"; |
16 const char kFixedMassStoragePrefix[] = "path:"; | 21 const char kFixedMassStoragePrefix[] = "path:"; |
17 const char kMtpPtpPrefix[] = "mtp:"; | 22 const char kMtpPtpPrefix[] = "mtp:"; |
18 const char kMacImageCapturePrefix[] = "ic:"; | 23 const char kMacImageCapturePrefix[] = "ic:"; |
19 const char kITunesPrefix[] = "itunes:"; | 24 const char kITunesPrefix[] = "itunes:"; |
20 const char kPicasaPrefix[] = "picasa:"; | 25 const char kPicasaPrefix[] = "picasa:"; |
21 | 26 |
| 27 string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes, |
| 28 const string16& name) { |
| 29 DCHECK(!name.empty()); |
| 30 return (storage_size_in_bytes == 0) ? |
| 31 name : |
| 32 ui::FormatBytes(storage_size_in_bytes) + base::ASCIIToUTF16(" ") + name; |
| 33 } |
| 34 |
| 35 string16 GetFullProductName(const string16& vendor_name, |
| 36 const string16& model_name) { |
| 37 if (vendor_name.empty() && model_name.empty()) |
| 38 return string16(); |
| 39 |
| 40 string16 product_name; |
| 41 if (vendor_name.empty()) |
| 42 product_name = model_name; |
| 43 else if (model_name.empty()) |
| 44 product_name = vendor_name; |
| 45 else if (!vendor_name.empty() && !model_name.empty()) |
| 46 product_name = vendor_name + base::UTF8ToUTF16(", ") + model_name; |
| 47 |
| 48 return product_name; |
| 49 } |
| 50 |
22 } // namespace | 51 } // namespace |
23 | 52 |
24 StorageInfo::StorageInfo() : total_size_in_bytes_(0) { | 53 StorageInfo::StorageInfo() : total_size_in_bytes_(0) { |
25 } | 54 } |
26 | 55 |
27 StorageInfo::StorageInfo(const std::string& device_id_in, | 56 StorageInfo::StorageInfo(const std::string& device_id_in, |
28 const string16& device_name, | |
29 const base::FilePath::StringType& device_location, | 57 const base::FilePath::StringType& device_location, |
30 const string16& label, | 58 const string16& label, |
31 const string16& vendor, | 59 const string16& vendor, |
32 const string16& model, | 60 const string16& model, |
33 uint64 size_in_bytes) | 61 uint64 size_in_bytes) |
34 : device_id_(device_id_in), | 62 : device_id_(device_id_in), |
35 name_(device_name), | |
36 location_(device_location), | 63 location_(device_location), |
37 storage_label_(label), | 64 storage_label_(label), |
38 vendor_name_(vendor), | 65 vendor_name_(vendor), |
39 model_name_(model), | 66 model_name_(model), |
40 total_size_in_bytes_(size_in_bytes) { | 67 total_size_in_bytes_(size_in_bytes) { |
41 } | 68 } |
42 | 69 |
43 StorageInfo::~StorageInfo() { | 70 StorageInfo::~StorageInfo() { |
44 } | 71 } |
45 | 72 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 Type type; | 162 Type type; |
136 return CrackDeviceId(device_id, &type, NULL) && type == ITUNES; | 163 return CrackDeviceId(device_id, &type, NULL) && type == ITUNES; |
137 } | 164 } |
138 | 165 |
139 // static | 166 // static |
140 bool StorageInfo::IsPicasaDevice(const std::string& device_id) { | 167 bool StorageInfo::IsPicasaDevice(const std::string& device_id) { |
141 Type type; | 168 Type type; |
142 return CrackDeviceId(device_id, &type, NULL) && type == PICASA; | 169 return CrackDeviceId(device_id, &type, NULL) && type == PICASA; |
143 } | 170 } |
144 | 171 |
| 172 base::string16 StorageInfo::GetDisplayName(bool with_size) const { |
| 173 return GetDisplayNameWithOverride(base::string16(), with_size); |
| 174 } |
| 175 |
| 176 base::string16 StorageInfo::GetDisplayNameWithOverride( |
| 177 const base::string16& override_display_name, bool with_size) const { |
| 178 base::string16 name; |
| 179 |
| 180 if (!IsRemovableDevice(device_id_)) { |
| 181 NOTREACHED(); |
| 182 return name; |
| 183 } |
| 184 |
| 185 name = override_display_name; |
| 186 if (name.empty()) |
| 187 name = storage_label_; |
| 188 if (name.empty()) |
| 189 name = GetFullProductName(vendor_name_, model_name_); |
| 190 if (name.empty()) |
| 191 name = l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_UNLABELED_DEVICE); |
| 192 |
| 193 if (with_size) |
| 194 name = GetDisplayNameForDevice(total_size_in_bytes_, name); |
| 195 return name; |
| 196 } |
| 197 |
145 } // namespace chrome | 198 } // namespace chrome |
OLD | NEW |