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

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: update 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, 57 //const base::string16& device_name,
vandebo (ex-Chrome) 2014/03/03 19:58:31 Remove
Haojian Wu 2014/03/04 05:00:12 Done.
30 const base::FilePath::StringType& device_location, 58 const base::FilePath::StringType& device_location,
31 const base::string16& label, 59 const base::string16& label,
32 const base::string16& vendor, 60 const base::string16& vendor,
33 const base::string16& model, 61 const base::string16& model,
34 uint64 size_in_bytes) 62 uint64 size_in_bytes)
35 : device_id_(device_id_in), 63 : device_id_(device_id_in),
36 name_(device_name),
37 location_(device_location), 64 location_(device_location),
38 storage_label_(label), 65 storage_label_(label),
39 vendor_name_(vendor), 66 vendor_name_(vendor),
40 model_name_(model), 67 model_name_(model),
41 total_size_in_bytes_(size_in_bytes) { 68 total_size_in_bytes_(size_in_bytes) {
42 } 69 }
43 70
44 StorageInfo::~StorageInfo() { 71 StorageInfo::~StorageInfo() {
45 } 72 }
46 73
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 Type type; 174 Type type;
148 return CrackDeviceId(device_id, &type, NULL) && type == IPHOTO; 175 return CrackDeviceId(device_id, &type, NULL) && type == IPHOTO;
149 } 176 }
150 177
151 // static 178 // static
152 bool StorageInfo::IsPicasaDevice(const std::string& device_id) { 179 bool StorageInfo::IsPicasaDevice(const std::string& device_id) {
153 Type type; 180 Type type;
154 return CrackDeviceId(device_id, &type, NULL) && type == PICASA; 181 return CrackDeviceId(device_id, &type, NULL) && type == PICASA;
155 } 182 }
156 183
184 base::string16 StorageInfo::GetDisplayName(bool with_size) const {
185 return GetDisplayNameWithOverride(base::string16(), with_size);
186 }
187
188 base::string16 StorageInfo::GetDisplayNameWithOverride(
189 const base::string16& override_display_name, bool with_size) const {
190 base::string16 name;
191
192 if (!IsRemovableDevice(device_id_)) {
vandebo (ex-Chrome) 2014/03/03 19:58:31 Storage Monitor should support names for non-remov
Haojian Wu 2014/03/04 05:00:12 Done.
193 NOTREACHED();
194 return name;
195 }
196
197 name = override_display_name;
198 if (name.empty())
199 name = storage_label_;
200 if (name.empty())
201 name = GetFullProductName(vendor_name_, model_name_);
202 if (name.empty())
203 name = base::ASCIIToUTF16("Unlabeled device");
204
205 if (with_size)
206 name = GetDisplayNameForDevice(total_size_in_bytes_, name);
207 return name;
208 }
209
157 } // namespace storage_monitor 210 } // namespace storage_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698