Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / image_writer_private / removable_storage_provider_chromeos.cc
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
20 void RemovableStorageProvider::GetAllDevices(DeviceListReadyCallback callback) {
21   scoped_refptr<StorageDeviceList> device_list(new StorageDeviceList());
22
23   DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
24   const DiskMountManager::DiskMap& disks = disk_mount_manager->disks();
25
26   for (DiskMountManager::DiskMap::const_iterator iter = disks.begin();
27        iter != disks.end();
28        ++iter) {
29     const DiskMountManager::Disk& disk = *iter->second;
30     if (disk.is_parent() && !disk.on_boot_device() && disk.has_media() &&
31         (disk.device_type() == chromeos::DEVICE_TYPE_USB ||
32          disk.device_type() == chromeos::DEVICE_TYPE_SD)) {
33       linked_ptr<api::image_writer_private::RemovableStorageDevice> device(
34           new api::image_writer_private::RemovableStorageDevice());
35       device->storage_unit_id = disk.file_path();
36       device->capacity = disk.total_size_in_bytes();
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   callback.Run(device_list, true);
53 }
54
55 }  // namespace extensions