Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: components/storage_monitor/storage_info.cc

Issue 120303003: [StorageMonitor] Move gallery name generation to StorageInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address vandebo's comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
vandebo (ex-Chrome) 2014/03/04 19:24:48 nit: remove blank line
Haojian Wu 2014/03/05 07:28:09 Done.
190 if (!IsRemovableDevice(device_id_)) {
191 if (storage_label_.empty())
vandebo (ex-Chrome) 2014/03/04 19:24:48 if ! empty
Haojian Wu 2014/03/05 07:28:09 Done.
192 return storage_label_;
193 return MediaStorageUtil::FindDevicePathById(device_id_).LossyDisplayName();
194 }
195
196 base::string16 name = override_display_name;
197 if (name.empty())
198 name = storage_label_;
199 if (name.empty())
200 name = GetFullProductName(vendor_name_, model_name_);
201 if (name.empty())
202 name = base::ASCIIToUTF16("Unlabeled device");
203
204 if (with_size)
205 name = GetDisplayNameForDevice(total_size_in_bytes_, name);
206 return name;
207 }
208
157 } // namespace storage_monitor 209 } // namespace storage_monitor
OLDNEW
« no previous file with comments | « components/storage_monitor/storage_info.h ('k') | components/storage_monitor/storage_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698