summaryrefslogtreecommitdiffstats
path: root/components/storage_monitor/storage_info.cc
diff options
context:
space:
mode:
authorthiago.santos@intel.com <thiago.santos@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-17 18:57:17 +0000
committerthiago.santos@intel.com <thiago.santos@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-17 18:57:17 +0000
commite4c5f97bbe47b29dd306b13087422a85c6afb2a1 (patch)
treedab060bd4768fed2d884b42a63a59db5d8e77a78 /components/storage_monitor/storage_info.cc
parent3eb20115ec1c4f07aba2f0f3eec63da789a28ebc (diff)
downloadchromium_src-e4c5f97bbe47b29dd306b13087422a85c6afb2a1.zip
chromium_src-e4c5f97bbe47b29dd306b13087422a85c6afb2a1.tar.gz
chromium_src-e4c5f97bbe47b29dd306b13087422a85c6afb2a1.tar.bz2
Make storage_monitor a component
Move storage_monitor to the components directory and: - Make the unit tests part of the components unit tests. - Update the include headers for both chrome and storage_monitor code. - Update the buildsystem dependencies and paths. - Update the DEPS files for both chrome and storage_monitor with the new restrictions. R=joi@chromium.org,thestig@chromium.org BUG= Review URL: https://codereview.chromium.org/152343005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251699 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/storage_monitor/storage_info.cc')
-rw-r--r--components/storage_monitor/storage_info.cc153
1 files changed, 153 insertions, 0 deletions
diff --git a/components/storage_monitor/storage_info.cc b/components/storage_monitor/storage_info.cc
new file mode 100644
index 0000000..a389611
--- /dev/null
+++ b/components/storage_monitor/storage_info.cc
@@ -0,0 +1,153 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/storage_monitor/storage_info.h"
+
+#include "base/logging.h"
+
+namespace {
+
+// Prefix constants for different device id spaces.
+const char kRemovableMassStorageWithDCIMPrefix[] = "dcim:";
+const char kRemovableMassStorageNoDCIMPrefix[] = "nodcim:";
+const char kFixedMassStoragePrefix[] = "path:";
+const char kMtpPtpPrefix[] = "mtp:";
+const char kMacImageCapturePrefix[] = "ic:";
+const char kITunesPrefix[] = "itunes:";
+const char kPicasaPrefix[] = "picasa:";
+const char kIPhotoPrefix[] = "iphoto:";
+
+} // namespace
+
+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),
+ model_name_(model),
+ total_size_in_bytes_(size_in_bytes) {
+}
+
+StorageInfo::~StorageInfo() {
+}
+
+// static
+std::string StorageInfo::MakeDeviceId(Type type, const std::string& unique_id) {
+ DCHECK(!unique_id.empty());
+ switch (type) {
+ case REMOVABLE_MASS_STORAGE_WITH_DCIM:
+ return std::string(kRemovableMassStorageWithDCIMPrefix) + unique_id;
+ case REMOVABLE_MASS_STORAGE_NO_DCIM:
+ return std::string(kRemovableMassStorageNoDCIMPrefix) + unique_id;
+ case FIXED_MASS_STORAGE:
+ return std::string(kFixedMassStoragePrefix) + unique_id;
+ case MTP_OR_PTP:
+ return std::string(kMtpPtpPrefix) + unique_id;
+ case MAC_IMAGE_CAPTURE:
+ return std::string(kMacImageCapturePrefix) + unique_id;
+ case ITUNES:
+ return std::string(kITunesPrefix) + unique_id;
+ case PICASA:
+ return std::string(kPicasaPrefix) + unique_id;
+ case IPHOTO:
+ return std::string(kIPhotoPrefix) + unique_id;
+ }
+ NOTREACHED();
+ return std::string();
+}
+
+// static
+bool StorageInfo::CrackDeviceId(const std::string& device_id,
+ Type* type, std::string* unique_id) {
+ size_t prefix_length = device_id.find_first_of(':');
+ std::string prefix = prefix_length != std::string::npos
+ ? device_id.substr(0, prefix_length + 1)
+ : std::string();
+
+ Type found_type;
+ if (prefix == kRemovableMassStorageWithDCIMPrefix) {
+ found_type = REMOVABLE_MASS_STORAGE_WITH_DCIM;
+ } else if (prefix == kRemovableMassStorageNoDCIMPrefix) {
+ found_type = REMOVABLE_MASS_STORAGE_NO_DCIM;
+ } else if (prefix == kFixedMassStoragePrefix) {
+ found_type = FIXED_MASS_STORAGE;
+ } else if (prefix == kMtpPtpPrefix) {
+ found_type = MTP_OR_PTP;
+ } else if (prefix == kMacImageCapturePrefix) {
+ found_type = MAC_IMAGE_CAPTURE;
+ } else if (prefix == kITunesPrefix) {
+ found_type = ITUNES;
+ } else if (prefix == kPicasaPrefix) {
+ found_type = PICASA;
+ } else if (prefix == kIPhotoPrefix) {
+ found_type = IPHOTO;
+ } else {
+ NOTREACHED();
+ return false;
+ }
+ if (type)
+ *type = found_type;
+
+ if (unique_id)
+ *unique_id = device_id.substr(prefix_length + 1);
+ return true;
+}
+
+// static
+bool StorageInfo::IsMediaDevice(const std::string& device_id) {
+ Type type;
+ return CrackDeviceId(device_id, &type, NULL) &&
+ (type == REMOVABLE_MASS_STORAGE_WITH_DCIM || type == MTP_OR_PTP ||
+ type == MAC_IMAGE_CAPTURE);
+}
+
+// static
+bool StorageInfo::IsRemovableDevice(const std::string& device_id) {
+ Type type;
+ return CrackDeviceId(device_id, &type, NULL) &&
+ (type == REMOVABLE_MASS_STORAGE_WITH_DCIM ||
+ type == REMOVABLE_MASS_STORAGE_NO_DCIM ||
+ type == MTP_OR_PTP ||
+ type == MAC_IMAGE_CAPTURE);
+}
+
+// static
+bool StorageInfo::IsMassStorageDevice(const std::string& device_id) {
+ Type type;
+ return CrackDeviceId(device_id, &type, NULL) &&
+ (type == REMOVABLE_MASS_STORAGE_WITH_DCIM ||
+ type == REMOVABLE_MASS_STORAGE_NO_DCIM ||
+ type == FIXED_MASS_STORAGE ||
+ type == ITUNES ||
+ type == IPHOTO ||
+ type == PICASA);
+}
+
+// static
+bool StorageInfo::IsITunesDevice(const std::string& device_id) {
+ Type type;
+ return CrackDeviceId(device_id, &type, NULL) && type == ITUNES;
+}
+
+// static
+bool StorageInfo::IsIPhotoDevice(const std::string& device_id) {
+ Type type;
+ return CrackDeviceId(device_id, &type, NULL) && type == IPHOTO;
+}
+
+// static
+bool StorageInfo::IsPicasaDevice(const std::string& device_id) {
+ Type type;
+ return CrackDeviceId(device_id, &type, NULL) && type == PICASA;
+}