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

Unified Diff: chrome/browser/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 7 years 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
Index: chrome/browser/storage_monitor/storage_info.cc
diff --git a/chrome/browser/storage_monitor/storage_info.cc b/chrome/browser/storage_monitor/storage_info.cc
index aa355008a063f5e6ea7fd87ece508fcb6d2912f3..7489ff654fe758d0b83a981f53dfa8afa5743abf 100644
--- a/chrome/browser/storage_monitor/storage_info.cc
+++ b/chrome/browser/storage_monitor/storage_info.cc
@@ -5,6 +5,10 @@
#include "chrome/browser/storage_monitor/storage_info.h"
#include "base/logging.h"
+#include "base/strings/utf_string_conversions.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/text/bytes_formatting.h"
namespace {
@@ -18,6 +22,40 @@ const char kITunesPrefix[] = "itunes:";
const char kPicasaPrefix[] = "picasa:";
const char kIPhotoPrefix[] = "iphoto:";
+string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes,
vandebo (ex-Chrome) 2014/01/08 19:46:25 Please inline this function at it's single call si
Haojian Wu 2014/01/20 09:43:00 Done.
+ const string16& name) {
+ DCHECK(!name.empty());
+ return (storage_size_in_bytes == 0) ?
+ name : ui::FormatBytes(storage_size_in_bytes) + ASCIIToUTF16(" ") + name;
+}
+
+// For a device with |device_name| and a relative path |sub_folder|, construct
+// a display name. If |sub_folder| is empty, then just return |device_name|.
+string16 GetDisplayNameForSubFolder(const string16& device_name,
vandebo (ex-Chrome) 2014/01/08 19:46:25 Same with this one.
Haojian Wu 2014/01/20 09:43:00 Done.
+ const base::FilePath& sub_folder) {
+ if (sub_folder.empty())
+ return device_name;
+ return (sub_folder.BaseName().LossyDisplayName() +
+ ASCIIToUTF16(" - ") +
+ device_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 + UTF8ToUTF16(", ") + model_name;
+
+ return product_name;
+}
+
} // namespace
StorageInfo::StorageInfo() : total_size_in_bytes_(0) {
@@ -151,3 +189,45 @@ bool StorageInfo::IsPicasaDevice(const std::string& device_id) {
Type type;
return CrackDeviceId(device_id, &type, NULL) && type == PICASA;
}
+
+base::string16 StorageInfo::GetDisplayName() const {
+ if (!StorageInfo::IsRemovableDevice(device_id_)) {
+ // For fixed storage, the default name is the fully qualified directory
+ // name, or in the case of a root directory, the root directory name.
+ // Exception: ChromeOS -- the full pathname isn't visible there, so only
+ // the directory name is used.
+ base::FilePath path(location_);
+ if (!name_.empty())
+ return name_;
+
+#if defined(OS_CHROMEOS)
+ // See chrome/browser/chromeos/fileapi/file_system_backend.cc
+ base::FilePath home_path;
+ if (PathService::Get(base::DIR_HOME, &home_path)) {
+ home_path = home_path.AppendASCII("Downloads");
+ base::FilePath relative;
+ if (home_path.AppendRelativePath(path, &relative))
+ return relative.LossyDisplayName();
+ }
+ return path.BaseName().LossyDisplayName();
+#else
+ return path.LossyDisplayName();
+#endif
+ }
+
+ string16 name = 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);
+
+ name = GetDisplayNameForDevice(total_size_in_bytes_, name);
+
+ base::FilePath path(location_);
+ if (path.BaseName() != path)
+ name = GetDisplayNameForSubFolder(name, path);
+
+ return name;
+}

Powered by Google App Engine
This is Rietveld 408576698