• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 namespace extensions {
9 
10 const char kUnknownSDDiskModel[] = "SD Card";
11 const char kUnknownUSBDiskModel[] = "USB Drive";
12 
13 using 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
PopulateDeviceList(scoped_refptr<StorageDeviceList> device_list)20 bool 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->vendor = disk.vendor_name();
37       device->model = disk.product_name();
38 
39       if (device->model.empty() && device->vendor.empty()) {
40         if (disk.device_type() == chromeos::DEVICE_TYPE_USB) {
41           device->model = kUnknownUSBDiskModel;
42         } else {
43           device->model = kUnknownSDDiskModel;
44         }
45       }
46 
47       device_list->data.push_back(device);
48     }
49   }
50 
51   return true;
52 }
53 
54 }  // namespace extensions
55