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

Unified Diff: chrome/browser/chromeos/dbus/cros_disks_client.h

Issue 8499007: Add CrosDisksClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add mock to gyp Created 9 years, 1 month 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/chromeos/dbus/cros_disks_client.h
diff --git a/chrome/browser/chromeos/dbus/cros_disks_client.h b/chrome/browser/chromeos/dbus/cros_disks_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..732927cbd5be9c7a29ed8b066c4314d02518ea9b
--- /dev/null
+++ b/chrome/browser/chromeos/dbus/cros_disks_client.h
@@ -0,0 +1,230 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
+#define CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+
+namespace dbus {
+class Bus;
+}
+
+namespace chromeos {
+
+enum MountType {
satorux1 2011/11/08 18:07:22 I know this is just inheriting from the original c
hashimoto 2011/11/09 02:33:25 Done.
+ MOUNT_TYPE_INVALID,
+ MOUNT_TYPE_DEVICE,
+ MOUNT_TYPE_ARCHIVE,
+ MOUNT_TYPE_NETWORK_STORAGE
satorux1 2011/11/08 18:07:22 Let's add a comma. It's a good practice, as it'll
hashimoto 2011/11/09 02:33:25 Done.
+};
+
+enum DeviceType {
+ FLASH,
+ HDD,
+ OPTICAL,
+ UNDEFINED
+};
+
+enum MountError {
+ MOUNT_ERROR_NONE = 0,
+ MOUNT_ERROR_UNKNOWN = 1,
+ MOUNT_ERROR_INTERNAL = 2,
+ MOUNT_ERROR_UNKNOWN_FILESYSTEM = 101,
+ MOUNT_ERROR_UNSUPORTED_FILESYSTEM = 102,
+ MOUNT_ERROR_INVALID_ARCHIVE = 201,
+ MOUNT_ERROR_LIBRARY_NOT_LOADED = 501,
+ MOUNT_ERROR_PATH_UNMOUNTED = 901
+ // TODO(tbarzic): Add more error codes as they get added to cros-disks and
+ // consider doing explicit translation from cros-disks error_types.
+};
+
+typedef std::vector<std::pair<std::string, std::string> > MountPathOptions;
satorux1 2011/11/08 18:07:22 Why not map<string>? Maybe the order matters? Woul
hashimoto 2011/11/09 02:33:25 Removed because it is no longer used.
+
+enum CrosDisksClientEventType {
+ MOUNT_DISK_ADDED,
+ MOUNT_DISK_REMOVED,
+ MOUNT_DISK_CHANGED,
+ MOUNT_DISK_MOUNTED,
+ MOUNT_DISK_UNMOUNTED,
+ MOUNT_DEVICE_ADDED,
+ MOUNT_DEVICE_REMOVED,
+ MOUNT_DEVICE_SCANNED,
+ MOUNT_FORMATTING_STARTED,
+ MOUNT_FORMATTING_FINISHED
+};
+
+enum MountCondition {
+ MOUNT_CONDITION_NONE,
+ MOUNT_CONDITION_UNKNOWN_FILESYSTEM,
+ MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM
+};
+
+// This class handles the interaction with cros-disks.
+// Classes can add themselves as observers.
+class CrosDisksClient {
+ public:
+ enum MountEvent {
+ MOUNTING,
+ UNMOUNTING
+ };
+ // Used to house an instance of each found mount device.
+ class Disk {
+ public:
+ Disk(const std::string& device_path,
+ const std::string& mount_path,
+ const std::string& system_path,
+ const std::string& file_path,
+ const std::string& device_label,
+ const std::string& drive_label,
+ const std::string& parent_path,
+ const std::string& system_path_prefix,
+ DeviceType device_type,
+ uint64 total_size,
+ bool is_parent,
+ bool is_read_only,
+ bool has_media,
+ bool on_boot_device,
+ bool is_hidden);
+ ~Disk();
+
+ // The path of the device, used by devicekit-disks.
+ const std::string& device_path() const { return device_path_; }
satorux1 2011/11/08 18:07:22 Please add a blank line between accessors. I think
hashimoto 2011/11/09 02:33:25 Done.
+ // The path to the mount point of this device. Will be empty if not mounted.
+ const std::string& mount_path() const { return mount_path_; }
+ // The path of the device according to the udev system.
+ const std::string& system_path() const { return system_path_; }
+ // The path of the device according to filesystem.
+ const std::string& file_path() const { return file_path_; }
+ // Device's label.
+ const std::string& device_label() const { return device_label_; }
+ // If disk is a parent, then its label, else parents label.
+ const std::string& drive_label() const { return drive_label_; }
+ // Parents device path. If device has no parent, then empty string.
+ const std::string& parent_path() const { return parent_path_; }
+ // Path of the system device this device's block is a part of.
+ const std::string& system_path_prefix() const {
+ return system_path_prefix_;
+ }
+ // Device type.
+ DeviceType device_type() const { return device_type_; }
+ // Total size of the device.
+ uint64 total_size() const { return total_size_; }
+ // Is the device is a parent device (i.e. sdb rather than sdb1).
+ bool is_parent() const { return is_parent_; }
+ // Is the device read only.
+ bool is_read_only() const { return is_read_only_; }
+ // Does the device contains media.
+ bool has_media() const { return has_media_; }
+ // Is the device on the boot device.
+ bool on_boot_device() const { return on_boot_device_; }
+ // Shoud the device be shown in the UI, or automounted.
+ bool is_hidden() const { return is_hidden_; }
+
+ void set_mount_path(const std::string& mount_path) {
+ mount_path_ = mount_path;
+ }
+ void clear_mount_path() { mount_path_.clear(); }
+
+ private:
+ std::string device_path_;
+ std::string mount_path_;
+ std::string system_path_;
+ std::string file_path_;
+ std::string device_label_;
+ std::string drive_label_;
+ std::string parent_path_;
+ std::string system_path_prefix_;
+ DeviceType device_type_;
+ uint64 total_size_;
+ bool is_parent_;
+ bool is_read_only_;
+ bool has_media_;
+ bool on_boot_device_;
+ bool is_hidden_;
+ };
+ typedef std::map<std::string, Disk*> DiskMap;
+ typedef std::map<std::string, std::string> PathMap;
+
+ struct MountPointInfo {
+ std::string source_path;
+ std::string mount_path;
+ MountType mount_type;
+ MountCondition mount_condition;
+
+ MountPointInfo(const std::string& source, const std::string& mount,
+ const MountType type, MountCondition condition)
+ : source_path(source),
+ mount_path(mount),
+ mount_type(type),
+ mount_condition(condition) {
+ }
+ };
+
+ // MountPointMap key is mount_path.
+ typedef std::map<std::string, MountPointInfo> MountPointMap;
+
+ typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool);
+
+ class Observer {
+ public:
+ virtual ~Observer() {}
+ // Async API events.
+ virtual void DiskChanged(CrosDisksClientEventType event,
+ const Disk* disk) = 0;
+ virtual void DeviceChanged(CrosDisksClientEventType event,
+ const std::string& device_path) = 0;
+ virtual void MountCompleted(MountEvent event_type,
+ MountError error_code,
+ const MountPointInfo& mount_info) = 0;
satorux1 2011/11/08 18:07:22 This may be obvious, but please could you add func
hashimoto 2011/11/09 02:33:25 Done.
+ };
+
+ virtual ~CrosDisksClient() {}
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+ virtual const DiskMap& disks() const = 0;
+ virtual const MountPointMap& mount_points() const = 0;
+
+ virtual void RequestMountInfoRefresh() = 0;
satorux1 2011/11/08 18:07:22 Function comment is missing. Please check other fu
hashimoto 2011/11/09 02:33:25 Done.
+ virtual void MountPath(const std::string& source_path,
+ MountType type,
+ const MountPathOptions& options) = 0;
+ // |path| is device's mount path.
+ virtual void UnmountPath(const std::string& path) = 0;
+
+ // Retrieves total and remaining available size on |mount_path|.
+ virtual void GetSizeStatsOnFileThread(const std::string& mount_path,
+ size_t* total_size_kb,
+ size_t* remaining_size_kb) = 0;
+
+ // Formats device given its file path.
+ // Example: file_path: /dev/sdb1
+ virtual void FormatUnmountedDevice(const std::string& file_path) = 0;
+
+ // Formats Device given its mount path. Unmount's the device
+ // Example: mount_path: /media/VOLUME_LABEL
+ virtual void FormatMountedDevice(const std::string& mount_path) = 0;
+
+ // Unmounts device_poath and all of its known children.
+ virtual void UnmountDeviceRecursive(const std::string& device_path,
+ UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0;
+
+ // Helper functions for parameter conversions.
+ static std::string MountTypeToString(MountType type);
+ static MountType MountTypeFromString(const std::string& type_str);
+ static std::string MountConditionToString(MountCondition type);
+
+ // Factory function, creates a new instance and returns ownership.
+ // For normal usage, access the singleton via DBusThreadManager::Get().
+ static CrosDisksClient* Create(dbus::Bus* bus);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
« no previous file with comments | « no previous file | chrome/browser/chromeos/dbus/cros_disks_client.cc » ('j') | chrome/browser/chromeos/dbus/cros_disks_client.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698