1// Copyright (c) 2013 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#ifndef CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_DEVICE_HANDLER_H_
6#define CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_DEVICE_HANDLER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/callback.h"
12#include "chromeos/dbus/cros_disks_client.h"
13#include "chromeos/disks/disk_mount_manager.h"
14
15namespace chromeos {
16namespace imageburner {
17
18// This is the implementation for the communication between BurnManager
19// and DiskMountManager.
20// The main reason this is NOT merged into BurnManager is to improve
21// testability, since both BurnManager and DiskMountManager are singleton
22// in real usage.
23class BurnDeviceHandler : public disks::DiskMountManager::Observer {
24 public:
25  // Triggered when a burnable device is added or removed.
26  typedef base::Callback<void(const disks::DiskMountManager::Disk& disk)>
27      DiskCallback;
28
29  // This class takes the pointer of DiskMountManager to improve testability,
30  // although it is singleton in the real usage.
31  explicit BurnDeviceHandler(disks::DiskMountManager* disk_mount_manager);
32  virtual ~BurnDeviceHandler();
33
34  // |add_callback| will be called when a new burnable device is added with
35  // the device's information.
36  // |remove_callback| will be called when a burnable device is removed.
37  // Note: This class is designed to connect to only one BurnManager,
38  // so it supports only single callback for each add and remove intentionally
39  // (rather than ObserverList).
40  void SetCallbacks(const DiskCallback& add_callback,
41                    const DiskCallback& remove_callback);
42
43  // Returns devices on which we can burn recovery image.
44  std::vector<disks::DiskMountManager::Disk> GetBurnableDevices();
45
46  // DiskMountManager::Observer overrides.
47  virtual void OnDiskEvent(
48      disks::DiskMountManager::DiskEvent event,
49      const disks::DiskMountManager::Disk* disk) OVERRIDE;
50  virtual void OnDeviceEvent(
51      disks::DiskMountManager::DeviceEvent event,
52      const std::string& device_path) OVERRIDE;
53  virtual void OnMountEvent(
54      disks::DiskMountManager::MountEvent event,
55      MountError error_code,
56      const disks::DiskMountManager::MountPointInfo& mount_info) OVERRIDE;
57  virtual void OnFormatEvent(
58      disks::DiskMountManager::FormatEvent event,
59      FormatError error_code,
60      const std::string& device_path) OVERRIDE;
61
62 private:
63  disks::DiskMountManager* disk_mount_manager_;  // Not owned by this class.
64  DiskCallback add_callback_;
65  DiskCallback remove_callback_;
66
67  DISALLOW_COPY_AND_ASSIGN(BurnDeviceHandler);
68};
69
70}  // namespace imageburner
71}  // namespace chromeos
72
73#endif  // CHROME_BROWSER_CHROMEOS_IMAGEBURNER_BURN_DEVICE_HANDLER_H_
74