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

Unified Diff: chrome/browser/storage_monitor/storage_info.cc

Issue 19489006: Media Galleries: Move gallery name generation back to StorageMonitor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 7 years, 4 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 | « chrome/browser/storage_monitor/storage_info.h ('k') | chrome/browser/storage_monitor/storage_monitor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/storage_monitor/storage_info.cc
===================================================================
--- chrome/browser/storage_monitor/storage_info.cc (revision 218837)
+++ chrome/browser/storage_monitor/storage_info.cc (working copy)
@@ -5,6 +5,11 @@
#include "chrome/browser/storage_monitor/storage_info.h"
#include "base/logging.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/storage_monitor/media_storage_util.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/text/bytes_formatting.h"
namespace chrome {
@@ -19,20 +24,42 @@
const char kITunesPrefix[] = "itunes:";
const char kPicasaPrefix[] = "picasa:";
+string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes,
+ const string16& name) {
+ DCHECK(!name.empty());
+ return (storage_size_in_bytes == 0) ?
+ name :
+ ui::FormatBytes(storage_size_in_bytes) + base::ASCIIToUTF16(" ") + name;
+}
+
+string16 GetFullProductName(const string16& vendor_name,
+ const string16& model_name) {
+ if (vendor_name.empty() && model_name.empty())
+ return string16();
+
+ 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
StorageInfo::StorageInfo() : total_size_in_bytes_(0) {
}
StorageInfo::StorageInfo(const std::string& device_id_in,
- const string16& device_name,
const base::FilePath::StringType& device_location,
const string16& label,
const string16& vendor,
const string16& model,
uint64 size_in_bytes)
: device_id_(device_id_in),
- name_(device_name),
location_(device_location),
storage_label_(label),
vendor_name_(vendor),
@@ -142,4 +169,30 @@
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 {
+ base::string16 name;
+
+ if (!IsRemovableDevice(device_id_)) {
+ NOTREACHED();
+ return name;
+ }
+
+ name = override_display_name;
+ if (name.empty())
+ name = storage_label_;
+ if (name.empty())
+ name = GetFullProductName(vendor_name_, model_name_);
+ if (name.empty())
+ name = l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_UNLABELED_DEVICE);
+
+ if (with_size)
+ name = GetDisplayNameForDevice(total_size_in_bytes_, name);
+ return name;
+}
+
} // namespace chrome
« no previous file with comments | « chrome/browser/storage_monitor/storage_info.h ('k') | chrome/browser/storage_monitor/storage_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698