1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h" 6#include "chromeos/disks/disk_mount_manager.h" 7 8namespace extensions { 9 10const char kUnknownSDDiskModel[] = "SD Card"; 11const char kUnknownUSBDiskModel[] = "USB Drive"; 12 13using chromeos::disks::DiskMountManager; 14 15// The Chrome OS implementation takes advantage of the Chrome OS 16// DiskMountManager. This does not expose whether the device is a removable or 17// fixed disk. In fact, some SD cards will present themselves as fixed disks 18// (see http://crbug.com/340761). Thus we just expose all USB and SD drives. 19// static 20bool RemovableStorageProvider::PopulateDeviceList( 21 scoped_refptr<StorageDeviceList> device_list) { 22 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 23 const DiskMountManager::DiskMap& disks = disk_mount_manager->disks(); 24 25 for (DiskMountManager::DiskMap::const_iterator iter = disks.begin(); 26 iter != disks.end(); 27 ++iter) { 28 const DiskMountManager::Disk& disk = *iter->second; 29 if (disk.is_parent() && !disk.on_boot_device() && disk.has_media() && 30 (disk.device_type() == chromeos::DEVICE_TYPE_USB || 31 disk.device_type() == chromeos::DEVICE_TYPE_SD)) { 32 linked_ptr<api::image_writer_private::RemovableStorageDevice> device( 33 new api::image_writer_private::RemovableStorageDevice()); 34 device->storage_unit_id = disk.device_path(); 35 device->capacity = disk.total_size_in_bytes(); 36 device->removable = disk.on_removable_device(); 37 device->vendor = disk.vendor_name(); 38 device->model = disk.product_name(); 39 40 if (device->model.empty() && device->vendor.empty()) { 41 if (disk.device_type() == chromeos::DEVICE_TYPE_USB) { 42 device->model = kUnknownUSBDiskModel; 43 } else { 44 device->model = kUnknownSDDiskModel; 45 } 46 } 47 48 device_list->data.push_back(device); 49 } 50 } 51 52 return true; 53} 54 55} // namespace extensions 56