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

Unified 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: fix unittest build error on mac/linux/chromeos 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/storage_monitor/storage_info.h ('k') | components/storage_monitor/storage_monitor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/storage_monitor/storage_info.cc
diff --git a/components/storage_monitor/storage_info.cc b/components/storage_monitor/storage_info.cc
index b9734e26f04aa99746c689da4ccc07062bdf5f33..52ae0c2502f908a48beb5e4d3b032aa40331c213 100644
--- a/components/storage_monitor/storage_info.cc
+++ b/components/storage_monitor/storage_info.cc
@@ -5,6 +5,10 @@
#include "components/storage_monitor/storage_info.h"
#include "base/logging.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/storage_monitor/media_storage_util.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/text/bytes_formatting.h"
namespace {
@@ -18,6 +22,30 @@ const char kITunesPrefix[] = "itunes:";
const char kPicasaPrefix[] = "picasa:";
const char kIPhotoPrefix[] = "iphoto:";
+base::string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes,
+ const base::string16& name) {
+ DCHECK(!name.empty());
+ return (storage_size_in_bytes == 0) ?
+ name :
+ ui::FormatBytes(storage_size_in_bytes) + base::ASCIIToUTF16(" ") + name;
+}
+
+base::string16 GetFullProductName(const base::string16& vendor_name,
+ const base::string16& model_name) {
+ if (vendor_name.empty() && model_name.empty())
+ return base::string16();
+
+ base::string16 product_name;
+ if (vendor_name.empty())
+ product_name = model_name;
+ else if (model_name.empty())
+ product_name = vendor_name;
+ else if (!vendor_name.empty() && !model_name.empty())
+ product_name = vendor_name + base::UTF8ToUTF16(", ") + model_name;
+
+ return product_name;
+}
+
} // namespace
namespace storage_monitor {
@@ -26,14 +54,12 @@ StorageInfo::StorageInfo() : total_size_in_bytes_(0) {
}
StorageInfo::StorageInfo(const std::string& device_id_in,
- const base::string16& device_name,
const base::FilePath::StringType& device_location,
const base::string16& label,
const base::string16& vendor,
const base::string16& model,
uint64 size_in_bytes)
: device_id_(device_id_in),
- name_(device_name),
location_(device_location),
storage_label_(label),
vendor_name_(vendor),
@@ -154,4 +180,29 @@ bool StorageInfo::IsPicasaDevice(const std::string& device_id) {
return CrackDeviceId(device_id, &type, NULL) && type == PICASA;
}
+base::string16 StorageInfo::GetDisplayName(bool with_size) const {
+ return GetDisplayNameWithOverride(base::string16(), with_size);
+}
+
+base::string16 StorageInfo::GetDisplayNameWithOverride(
+ const base::string16& override_display_name, bool with_size) const {
+ if (!IsRemovableDevice(device_id_)) {
+ if (!storage_label_.empty())
+ return storage_label_;
+ return base::FilePath(location_).LossyDisplayName();
+ }
+
+ base::string16 name = override_display_name;
+ if (name.empty())
+ name = storage_label_;
+ if (name.empty())
+ name = GetFullProductName(vendor_name_, model_name_);
+ if (name.empty())
+ name = base::ASCIIToUTF16("Unlabeled device");
+
+ if (with_size)
+ name = GetDisplayNameForDevice(total_size_in_bytes_, name);
+ return name;
+}
+
} // namespace storage_monitor
« 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