Remove unused MountLibrary

This patch is 3rd part of 3 splitted patches made from http://codereview.chromium.org/8386031

BUG=chromium-os:16556
TEST=build success


Review URL: http://codereview.chromium.org/8499009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110486 0039d316-1c4b-4281-b951-d872f2087c98
parent c7fc13fb
......@@ -8,7 +8,6 @@
#include "chrome/browser/chromeos/cros/cert_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "chrome/browser/chromeos/cros/library_loader.h"
#include "chrome/browser/chromeos/cros/mount_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/cros/power_library.h"
#include "chrome/browser/chromeos/cros/screen_lock_library.h"
......@@ -82,7 +81,6 @@ CrosLibrary* CrosLibrary::Get() {
DEFINE_GET_LIBRARY_METHOD(Burn, burn);
DEFINE_GET_LIBRARY_METHOD(Cert, cert);
DEFINE_GET_LIBRARY_METHOD(Cryptohome, crypto);
DEFINE_GET_LIBRARY_METHOD(Mount, mount);
DEFINE_GET_LIBRARY_METHOD(Network, network);
DEFINE_GET_LIBRARY_METHOD(Power, power);
DEFINE_GET_LIBRARY_METHOD(ScreenLock, screen_lock);
......@@ -128,7 +126,6 @@ void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader, bool own) {
DEFINE_SET_LIBRARY_METHOD(Cert, cert);
DEFINE_SET_LIBRARY_METHOD(Burn, burn);
DEFINE_SET_LIBRARY_METHOD(Cryptohome, crypto);
DEFINE_SET_LIBRARY_METHOD(Mount, mount);
DEFINE_SET_LIBRARY_METHOD(Network, network);
DEFINE_SET_LIBRARY_METHOD(Power, power);
DEFINE_SET_LIBRARY_METHOD(ScreenLock, screen_lock);
......
......@@ -20,7 +20,6 @@ class BurnLibrary;
class CertLibrary;
class CryptohomeLibrary;
class LibraryLoader;
class MountLibrary;
class NetworkLibrary;
class PowerLibrary;
class ScreenLockLibrary;
......@@ -47,7 +46,6 @@ class CrosLibrary {
void SetCertLibrary(CertLibrary* library, bool own);
void SetBurnLibrary(BurnLibrary* library, bool own);
void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own);
void SetMountLibrary(MountLibrary* library, bool own);
void SetNetworkLibrary(NetworkLibrary* library, bool own);
void SetPowerLibrary(PowerLibrary* library, bool own);
void SetScreenLockLibrary(ScreenLockLibrary* library, bool own);
......@@ -73,7 +71,6 @@ class CrosLibrary {
BurnLibrary* GetBurnLibrary();
CertLibrary* GetCertLibrary();
CryptohomeLibrary* GetCryptohomeLibrary();
MountLibrary* GetMountLibrary();
NetworkLibrary* GetNetworkLibrary();
PowerLibrary* GetPowerLibrary();
ScreenLockLibrary* GetScreenLockLibrary();
......@@ -144,7 +141,6 @@ class CrosLibrary {
Library<BurnLibrary> burn_lib_;
Library<CertLibrary> cert_lib_;
Library<CryptohomeLibrary> crypto_lib_;
Library<MountLibrary> mount_lib_;
Library<NetworkLibrary> network_lib_;
Library<PowerLibrary> power_lib_;
Library<ScreenLockLibrary> screen_lock_lib_;
......
// 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.
#include "chrome/browser/chromeos/cros/mock_mount_library.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "content/public/browser/browser_thread.h"
namespace chromeos {
using content::BrowserThread;
using testing::_;
using testing::AnyNumber;
using testing::Invoke;
using testing::ReturnRef;
const char* kTestSystemPath = "/this/system/path";
const char* kTestSystemPathPrefix = "/this/system";
const char* kTestDevicePath = "/this/device/path";
const char* kTestMountPath = "/media/foofoo";
const char* kTestFilePath = "/this/file/path";
const char* kTestDeviceLabel = "A label";
const char* kTestDriveLabel = "Another label";
const char* kTestParentPath = "/this/is/my/parent";
void MockMountLibrary::AddObserverInternal(MountLibrary::Observer* observer) {
observers_.AddObserver(observer);
}
void MockMountLibrary::RemoveObserverInternal(
MountLibrary::Observer* observer) {
observers_.RemoveObserver(observer);
}
MockMountLibrary::MockMountLibrary() {
ON_CALL(*this, AddObserver(_))
.WillByDefault(Invoke(this, &MockMountLibrary::AddObserverInternal));
ON_CALL(*this, RemoveObserver(_))
.WillByDefault(Invoke(this, &MockMountLibrary::RemoveObserverInternal));
ON_CALL(*this, disks())
.WillByDefault(Invoke(this, &MockMountLibrary::disksInternal));
}
MockMountLibrary::~MockMountLibrary() {
}
void MockMountLibrary::FireDeviceInsertEvents() {
scoped_ptr<MountLibrary::Disk> disk1(new MountLibrary::Disk(
std::string(kTestDevicePath),
std::string(),
std::string(kTestSystemPath),
std::string(kTestFilePath),
std::string(),
std::string(kTestDriveLabel),
std::string(kTestParentPath),
std::string(kTestSystemPathPrefix),
FLASH,
4294967295U,
false,
false,
true,
false,
false));
disks_.clear();
disks_.insert(std::pair<std::string, MountLibrary::Disk*>(
std::string(kTestDevicePath), disk1.get()));
// Device Added
chromeos::MountLibraryEventType evt;
evt = chromeos::MOUNT_DEVICE_ADDED;
UpdateDeviceChanged(evt, kTestSystemPath);
// Disk Added
evt = chromeos::MOUNT_DISK_ADDED;
UpdateDiskChanged(evt, disk1.get());
// Disk Changed
scoped_ptr<MountLibrary::Disk> disk2(new MountLibrary::Disk(
std::string(kTestDevicePath),
std::string(kTestMountPath),
std::string(kTestSystemPath),
std::string(kTestFilePath),
std::string(kTestDeviceLabel),
std::string(kTestDriveLabel),
std::string(kTestParentPath),
std::string(kTestSystemPathPrefix),
FLASH,
1073741824,
false,
false,
true,
false,
false));
disks_.clear();
disks_.insert(std::pair<std::string, MountLibrary::Disk*>(
std::string(kTestDevicePath), disk2.get()));
evt = chromeos::MOUNT_DISK_CHANGED;
UpdateDiskChanged(evt, disk2.get());
}
void MockMountLibrary::FireDeviceRemoveEvents() {
scoped_ptr<MountLibrary::Disk> disk(new MountLibrary::Disk(
std::string(kTestDevicePath),
std::string(kTestMountPath),
std::string(kTestSystemPath),
std::string(kTestFilePath),
std::string(kTestDeviceLabel),
std::string(kTestDriveLabel),
std::string(kTestParentPath),
std::string(kTestSystemPathPrefix),
FLASH,
1073741824,
false,
false,
true,
false,
false));
disks_.clear();
disks_.insert(std::pair<std::string, MountLibrary::Disk*>(
std::string(kTestDevicePath), disk.get()));
UpdateDiskChanged(chromeos::MOUNT_DISK_REMOVED, disk.get());
}
void MockMountLibrary::SetupDefaultReplies() {
EXPECT_CALL(*this, AddObserver(_))
.Times(AnyNumber());
EXPECT_CALL(*this, RemoveObserver(_))
.Times(AnyNumber());
EXPECT_CALL(*this, disks())
.WillRepeatedly(ReturnRef(disks_));
EXPECT_CALL(*this, RequestMountInfoRefresh())
.Times(AnyNumber());
EXPECT_CALL(*this, MountPath(_, _, _))
.Times(AnyNumber());
EXPECT_CALL(*this, UnmountPath(_))
.Times(AnyNumber());
EXPECT_CALL(*this, FormatUnmountedDevice(_))
.Times(AnyNumber());
EXPECT_CALL(*this, FormatMountedDevice(_))
.Times(AnyNumber());
EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _))
.Times(AnyNumber());
}
void MockMountLibrary::UpdateDiskChanged(MountLibraryEventType evt,
const MountLibrary::Disk* disk) {
// Make sure we run on UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(evt, disk));
}
void MockMountLibrary::UpdateDeviceChanged(MountLibraryEventType evt,
const std::string& path) {
// Make sure we run on UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(evt, path));
}
} // namespace chromeos
// 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_CROS_MOCK_MOUNT_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_MOUNT_LIBRARY_H_
#pragma once
#include <string>
#include "base/observer_list.h"
#include "base/time.h"
#include "chrome/browser/chromeos/cros/mount_library.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros/chromeos_mount.h"
namespace chromeos {
class MockMountLibrary : public MountLibrary {
public:
MockMountLibrary();
virtual ~MockMountLibrary();
MOCK_METHOD0(Init, void(void));
MOCK_METHOD1(AddObserver, void(MountLibrary::Observer*));
MOCK_METHOD1(RemoveObserver, void(MountLibrary::Observer*));
MOCK_CONST_METHOD0(disks, const MountLibrary::DiskMap&(void));
MOCK_CONST_METHOD0(mount_points, const MountLibrary::MountPointMap&(void));
MOCK_METHOD0(RequestMountInfoRefresh, void(void));
MOCK_METHOD3(MountPath, void(const char*, MountType,
const MountPathOptions&));
MOCK_METHOD1(UnmountPath, void(const char*));
MOCK_METHOD3(GetSizeStatsOnFileThread, void(const char*, size_t*, size_t*));
MOCK_METHOD1(FormatUnmountedDevice, void(const char*));
MOCK_METHOD1(FormatMountedDevice, void(const char*));
MOCK_METHOD3(UnmountDeviceRecursive, void(const char*,
MountLibrary::UnmountDeviceRecursiveCallbackType, void*));
void FireDeviceInsertEvents();
void FireDeviceRemoveEvents();
void SetupDefaultReplies();
private:
void AddObserverInternal(MountLibrary::Observer* observer);
void RemoveObserverInternal(MountLibrary::Observer* observer);
const MountLibrary::DiskMap& disksInternal() const { return disks_; }
void UpdateDeviceChanged(MountLibraryEventType evt,
const std::string& path);
void UpdateDiskChanged(MountLibraryEventType evt,
const MountLibrary::Disk* disk);
ObserverList<MountLibrary::Observer> observers_;
// The list of disks found.
MountLibrary::DiskMap disks_;
DISALLOW_COPY_AND_ASSIGN(MockMountLibrary);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_MOUNT_LIBRARY_H_
This diff is collapsed.
// 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_CROS_MOUNT_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_
#pragma once
#include <map>
#include <string>
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "base/time.h"
#include "third_party/cros/chromeos_mount.h"
namespace chromeos {
typedef enum MountLibraryEventType {
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
} MountLibraryEventType;
typedef 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 {
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_; }
// 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 char* 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 char* source, const char* mount, const MountType type,
MountCondition condition)
: source_path(source ? source : ""),
mount_path(mount ? 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(MountLibraryEventType event,
const Disk* disk) = 0;
virtual void DeviceChanged(MountLibraryEventType 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 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,
MountType type,
const MountPathOptions& options) = 0;
// |path| is device's mount path.
virtual void UnmountPath(const char* path) = 0;
// Retrieves total and remaining available size on |mount_path|.
virtual void GetSizeStatsOnFileThread(const char* 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;
// Formats Device given its mount path. Unmount's the device
// Example: mount_path: /media/VOLUME_LABEL
virtual void FormatMountedDevice(const char* mount_path) = 0;
// Unmounts device_poath and all of its known children.
virtual void UnmountDeviceRecursive(const char* 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);
// 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);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_
......@@ -403,8 +403,6 @@
'browser/chromeos/cros/cryptohome_library.h',
'browser/chromeos/cros/library_loader.cc',
'browser/chromeos/cros/library_loader.h',
'browser/chromeos/cros/mount_library.cc',
'browser/chromeos/cros/mount_library.h',
'browser/chromeos/cros/native_network_constants.cc',
'browser/chromeos/cros/native_network_constants.h',
'browser/chromeos/cros/native_network_parser.cc',
......
......@@ -2436,8 +2436,6 @@
'browser/chromeos/cros/cros_in_process_browser_test.h',
'browser/chromeos/cros/cros_mock.cc',
'browser/chromeos/cros/cros_mock.h',
'browser/chromeos/cros/mock_mount_library.cc',
'browser/chromeos/cros/mock_mount_library.h',
'browser/chromeos/cros/mock_power_library.cc',
'browser/chromeos/cros/mock_power_library.h',
'browser/chromeos/cros/mock_screen_lock_library.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment