This source file includes following definitions.
- IsBurnableDevice
- SetCallbacks
- GetBurnableDevices
- OnDiskEvent
- OnDeviceEvent
- OnMountEvent
- OnFormatEvent
#include "chrome/browser/chromeos/imageburner/burn_device_handler.h"
#include <string>
#include <vector>
#include "base/logging.h"
#include "chromeos/dbus/cros_disks_client.h"
#include "chromeos/disks/disk_mount_manager.h"
namespace chromeos {
namespace imageburner {
using disks::DiskMountManager;
namespace {
bool IsBurnableDevice(const DiskMountManager::Disk& disk) {
return disk.is_parent() && !disk.on_boot_device() && disk.has_media() &&
(disk.device_type() == DEVICE_TYPE_USB ||
disk.device_type() == DEVICE_TYPE_SD);
}
}
BurnDeviceHandler::BurnDeviceHandler(DiskMountManager* disk_mount_manager)
: disk_mount_manager_(disk_mount_manager) {
DCHECK(disk_mount_manager_);
disk_mount_manager_->AddObserver(this);
}
BurnDeviceHandler::~BurnDeviceHandler() {
disk_mount_manager_->RemoveObserver(this);
}
void BurnDeviceHandler::SetCallbacks(const DiskCallback& add_callback,
const DiskCallback& remove_callback) {
add_callback_ = add_callback;
remove_callback_ = remove_callback;
}
std::vector<DiskMountManager::Disk> BurnDeviceHandler::GetBurnableDevices() {
const DiskMountManager::DiskMap& disks = disk_mount_manager_->disks();
std::vector<DiskMountManager::Disk> result;
for (DiskMountManager::DiskMap::const_iterator iter = disks.begin();
iter != disks.end();
++iter) {
const DiskMountManager::Disk& disk = *iter->second;
if (IsBurnableDevice(disk))
result.push_back(disk);
}
return result;
}
void BurnDeviceHandler::OnDiskEvent(DiskMountManager::DiskEvent event,
const DiskMountManager::Disk* disk) {
if (!IsBurnableDevice(*disk))
return;
switch (event) {
case DiskMountManager::DISK_ADDED:
add_callback_.Run(*disk);
break;
case DiskMountManager::DISK_REMOVED:
remove_callback_.Run(*disk);
break;
default: {
}
}
}
void BurnDeviceHandler::OnDeviceEvent(DiskMountManager::DeviceEvent event,
const std::string& device_path) {
}
void BurnDeviceHandler::OnMountEvent(
DiskMountManager::MountEvent event,
MountError error_code,
const DiskMountManager::MountPointInfo& mount_info) {
}
void BurnDeviceHandler::OnFormatEvent(DiskMountManager::FormatEvent event,
FormatError error_code,
const std::string& device_path) {
}
}
}