diff options
author | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 22:47:45 +0000 |
---|---|---|
committer | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-02 22:47:45 +0000 |
commit | b52e52a2fbc2d8222924a5f60fe3fe35bad4ea0f (patch) | |
tree | b3ca1838a3b0ee47cd310df76a4b0fd6a640bba0 | |
parent | 72acf913daa9cbdaeb193a02c5b5958be97bbd28 (diff) | |
download | chromium_src-b52e52a2fbc2d8222924a5f60fe3fe35bad4ea0f.zip chromium_src-b52e52a2fbc2d8222924a5f60fe3fe35bad4ea0f.tar.gz chromium_src-b52e52a2fbc2d8222924a5f60fe3fe35bad4ea0f.tar.bz2 |
CHanging the mount library to mount the drives explicitly. Adding the notion of parent devices as well.
Review URL: http://codereview.chromium.org/1608004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43541 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/cros/mock_mount_library.h | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/mount_library.cc | 20 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/mount_library.h | 16 | ||||
-rw-r--r-- | chrome/browser/chromeos/usb_mount_observer.cc | 15 |
4 files changed, 42 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/cros/mock_mount_library.h b/chrome/browser/chromeos/cros/mock_mount_library.h index 6fb342f..06023e4 100644 --- a/chrome/browser/chromeos/cros/mock_mount_library.h +++ b/chrome/browser/chromeos/cros/mock_mount_library.h @@ -26,6 +26,7 @@ class MockMountLibrary : public MountLibrary { virtual ~MockMountLibrary(); MOCK_METHOD1(AddObserver, void(MountLibrary::Observer*)); + MOCK_METHOD1(MountPath, bool(const char*)); MOCK_METHOD1(RemoveObserver, void(MountLibrary::Observer*)); MOCK_CONST_METHOD0(disks, const MountLibrary::DiskVector&(void)); diff --git a/chrome/browser/chromeos/cros/mount_library.cc b/chrome/browser/chromeos/cros/mount_library.cc index 8126eaa..24eed5f 100644 --- a/chrome/browser/chromeos/cros/mount_library.cc +++ b/chrome/browser/chromeos/cros/mount_library.cc @@ -27,12 +27,18 @@ void MountLibraryImpl::RemoveObserver(Observer* observer) { observers_.RemoveObserver(observer); } +bool MountLibraryImpl::MountPath(const char* device_path) { + return MountDevicePath(device_path); +} + void MountLibraryImpl::ParseDisks(const MountStatus& status) { disks_.clear(); for (int i = 0; i < status.size; i++) { std::string path; std::string mountpath; std::string systempath; + bool parent; + bool hasmedia; if (status.disks[i].path != NULL) { path = status.disks[i].path; } @@ -42,7 +48,13 @@ void MountLibraryImpl::ParseDisks(const MountStatus& status) { if (status.disks[i].systempath != NULL) { systempath = status.disks[i].systempath; } - disks_.push_back(Disk(path, mountpath, systempath)); + parent = status.disks[i].isparent; + hasmedia = status.disks[i].hasmedia; + disks_.push_back(Disk(path, + mountpath, + systempath, + parent, + hasmedia)); } } @@ -62,9 +74,9 @@ MountLibraryImpl::~MountLibraryImpl() { // static void MountLibraryImpl::MountStatusChangedHandler(void* object, - const MountStatus& status, - MountEventType evt, - const char* path) { + const MountStatus& status, + MountEventType evt, + const char* path) { MountLibraryImpl* mount = static_cast<MountLibraryImpl*>(object); std::string devicepath = path; mount->ParseDisks(status); diff --git a/chrome/browser/chromeos/cros/mount_library.h b/chrome/browser/chromeos/cros/mount_library.h index bbbc7cb..4223274 100644 --- a/chrome/browser/chromeos/cros/mount_library.h +++ b/chrome/browser/chromeos/cros/mount_library.h @@ -25,16 +25,24 @@ class MountLibrary { Disk() {} Disk(const std::string& devicepath, const std::string& mountpath, - const std::string& systempath) + const std::string& systempath, + bool isparent, + bool hasmedia) : device_path(devicepath), mount_path(mountpath), - system_path(systempath) {} + system_path(systempath), + is_parent(isparent), + has_media(hasmedia) {} // The path of the device, used by devicekit-disks. std::string device_path; // The path to the mount point of this device. Will be empty if not mounted. std::string mount_path; // The path of the device according to the udev system. std::string system_path; + // if the device is a parent device (i.e. sdb rather than sdb1) + bool is_parent; + // if the device has media currently + bool has_media; }; typedef std::vector<Disk> DiskVector; @@ -49,9 +57,9 @@ class MountLibrary { virtual void AddObserver(Observer* observer) = 0; virtual void RemoveObserver(Observer* observer) = 0; virtual const DiskVector& disks() const = 0; + virtual bool MountPath(const char* device_path) = 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: MountLibrary::Get(). @@ -64,7 +72,7 @@ class MountLibraryImpl : public MountLibrary { virtual void AddObserver(Observer* observer); virtual void RemoveObserver(Observer* observer); virtual const DiskVector& disks() const { return disks_; } - + virtual bool MountPath(const char* device_path); private: void ParseDisks(const MountStatus& status); diff --git a/chrome/browser/chromeos/usb_mount_observer.cc b/chrome/browser/chromeos/usb_mount_observer.cc index a6cb4e6..91790d1 100644 --- a/chrome/browser/chromeos/usb_mount_observer.cc +++ b/chrome/browser/chromeos/usb_mount_observer.cc @@ -51,8 +51,19 @@ void USBMountObserver::MountChanged(chromeos::MountLibrary* obj, chromeos::MountEventType evt, const std::string& path) { if (evt == chromeos::DISK_ADDED) { - // Return since disk added doesn't mean anything until - // its mounted, which is a change event. + const chromeos::MountLibrary::DiskVector& disks = obj->disks(); + for (size_t i = 0; i < disks.size(); ++i) { + chromeos::MountLibrary::Disk disk = disks[i]; + if (disk.device_path == path) { + if (disk.is_parent) { + if (!disk.has_media) { + RemoveBrowserFromVector(disk.system_path); + } + } else if (!obj->MountPath(path.c_str())) { + RemoveBrowserFromVector(disk.system_path); + } + } + } LOG(INFO) << "Got added mount:" << path; } else if (evt == chromeos::DISK_REMOVED || evt == chromeos::DEVICE_REMOVED) { |