Chromium Code Reviews| Index: chrome/browser/chromeos/dbus/cros_disks_client.h |
| diff --git a/chrome/browser/chromeos/cros/mount_library.h b/chrome/browser/chromeos/dbus/cros_disks_client.h |
| similarity index 65% |
| rename from chrome/browser/chromeos/cros/mount_library.h |
| rename to chrome/browser/chromeos/dbus/cros_disks_client.h |
| index 3eb7b4777e912d81741008dd64732a50b4d0dd21..732927cbd5be9c7a29ed8b066c4314d02518ea9b 100644 |
| --- a/chrome/browser/chromeos/cros/mount_library.h |
| +++ b/chrome/browser/chromeos/dbus/cros_disks_client.h |
| @@ -2,21 +2,52 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| -#define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| +#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/memory/singleton.h" |
| -#include "base/observer_list.h" |
| -#include "base/time.h" |
| -#include "third_party/cros/chromeos_mount.h" |
| +#include "base/basictypes.h" |
| + |
| +namespace dbus { |
| +class Bus; |
| +} |
| namespace chromeos { |
| -typedef enum MountLibraryEventType { |
| +enum MountType { |
| + MOUNT_TYPE_INVALID, |
| + MOUNT_TYPE_DEVICE, |
| + MOUNT_TYPE_ARCHIVE, |
| + MOUNT_TYPE_NETWORK_STORAGE |
| +}; |
| + |
| +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; |
| + |
| +enum CrosDisksClientEventType { |
| MOUNT_DISK_ADDED, |
| MOUNT_DISK_REMOVED, |
| MOUNT_DISK_CHANGED, |
| @@ -27,45 +58,17 @@ typedef enum MountLibraryEventType { |
| MOUNT_DEVICE_SCANNED, |
| MOUNT_FORMATTING_STARTED, |
| MOUNT_FORMATTING_FINISHED |
| -} MountLibraryEventType; |
| +}; |
| -typedef enum MountCondition { |
| +enum MountCondition { |
| MOUNT_CONDITION_NONE, |
| MOUNT_CONDITION_UNKNOWN_FILESYSTEM, |
| MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM |
| -} MountCondition; |
| - |
| -class MountLibcrosProxy { |
| - public: |
| - virtual ~MountLibcrosProxy() {} |
| - virtual void CallMountPath(const char* source_path, |
| - MountType type, |
| - const MountPathOptions& options, |
| - MountCompletedMonitor callback, |
| - void* object) = 0; |
| - virtual void CallUnmountPath(const char* path, |
| - UnmountRequestCallback callback, |
| - void* object) = 0; |
| - virtual void CallRequestMountInfo(RequestMountInfoCallback callback, |
| - void* object) = 0; |
| - virtual void CallFormatDevice(const char* device_path, |
| - const char* filesystem, |
| - FormatRequestCallback callback, |
| - void* object) = 0; |
| - virtual void CallGetDiskProperties(const char* device_path, |
| - GetDiskPropertiesCallback callback, |
| - void* object) = 0; |
| - virtual MountEventConnection MonitorCrosDisks(MountEventMonitor monitor, |
| - MountCompletedMonitor mount_complete_monitor, |
| - void* object) = 0; |
| - virtual void DisconnectCrosDisksMonitorIfSet(MountEventConnection connection) |
| - = 0; |
| }; |
| -// This class handles the interaction with the ChromeOS mount library APIs. |
| -// Classes can add themselves as observers. Users can get an instance of this |
| -// library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() |
| -class MountLibrary { |
| +// This class handles the interaction with cros-disks. |
| +// Classes can add themselves as observers. |
| +class CrosDisksClient { |
| public: |
| enum MountEvent { |
| MOUNTING, |
| @@ -124,7 +127,9 @@ class MountLibrary { |
| // Shoud the device be shown in the UI, or automounted. |
| bool is_hidden() const { return is_hidden_; } |
| - void set_mount_path(const char* mount_path) { mount_path_ = mount_path; } |
| + void set_mount_path(const std::string& mount_path) { |
| + mount_path_ = mount_path; |
| + } |
| void clear_mount_path() { mount_path_.clear(); } |
| private: |
| @@ -153,10 +158,10 @@ class MountLibrary { |
| MountType mount_type; |
| MountCondition mount_condition; |
| - MountPointInfo(const char* source, const char* mount, const MountType type, |
| - MountCondition condition) |
| - : source_path(source ? source : ""), |
| - mount_path(mount ? mount : ""), |
| + 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) { |
| } |
| @@ -171,44 +176,43 @@ class MountLibrary { |
| public: |
| virtual ~Observer() {} |
| // Async API events. |
| - virtual void DiskChanged(MountLibraryEventType event, |
| + virtual void DiskChanged(CrosDisksClientEventType event, |
| const Disk* disk) = 0; |
| - virtual void DeviceChanged(MountLibraryEventType event, |
| + 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; |
| }; |
| - virtual ~MountLibrary() {} |
| - virtual void Init() = 0; |
| + 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; |
| - virtual void MountPath(const char* source_path, |
| + virtual void MountPath(const std::string& source_path, |
| MountType type, |
| const MountPathOptions& options) = 0; |
| // |path| is device's mount path. |
| - virtual void UnmountPath(const char* path) = 0; |
| + virtual void UnmountPath(const std::string& path) = 0; |
| // Retrieves total and remaining available size on |mount_path|. |
| - virtual void GetSizeStatsOnFileThread(const char* 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 char* file_path) = 0; |
| + 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 char* mount_path) = 0; |
| + virtual void FormatMountedDevice(const std::string& mount_path) = 0; |
| // Unmounts device_poath and all of its known children. |
| - virtual void UnmountDeviceRecursive(const char* device_path, |
| + virtual void UnmountDeviceRecursive(const std::string& device_path, |
| UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; |
| // Helper functions for parameter conversions. |
| @@ -216,14 +220,11 @@ class MountLibrary { |
| static MountType MountTypeFromString(const std::string& type_str); |
| static std::string MountConditionToString(MountCondition type); |
|
satorux1
2011/11/07 23:21:55
Do we need to expose these methods? Otherwise, you
hashimoto
2011/11/08 07:31:05
They are used by extension_file_browser_private_ap
|
| - // Used in testing. Enables mocking libcros. |
| - virtual void SetLibcrosProxy(MountLibcrosProxy* proxy) {} |
| - |
| // Factory function, creates a new instance and returns ownership. |
| - // For normal usage, access the singleton via CrosLibrary::Get(). |
| - static MountLibrary* GetImpl(bool stub); |
| + // For normal usage, access the singleton via DBusThreadManager::Get(). |
| + static CrosDisksClient* Create(dbus::Bus* bus); |
| }; |
| } // namespace chromeos |
| -#endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| +#endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_ |