summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/usb_mount_observer.h
blob: c6cb2b9ba943ae3e604eec077e5eaee178a26928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_
#define CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_

#include <string>
#include <vector>

#include "chrome/browser/chromeos/mount_library.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/notification_registrar.h"

class Browser;
class Profile;

namespace chromeos { // NOLINT

// Used to monitor mount changes and popup a new window when
// a new mounted usb device is found.
class USBMountObserver : public chromeos::MountLibrary::Observer,
                         public NotificationObserver {
 public:
  struct BrowserWithPath {
    Browser* browser;
    std::string device_path;
  };

  USBMountObserver() {}
  ~USBMountObserver() {}

  void set_profile(Profile* profile) { profile_ = profile; }

  static USBMountObserver* Get() {
    return Singleton<USBMountObserver>::get();
  }
  void Observe(NotificationType type,
               const NotificationSource& source,
               const NotificationDetails& details);

  void MountChanged(chromeos::MountLibrary* obj,
                    chromeos::MountEventType evt,
                    const std::string& path);
 private:
  typedef std::vector<BrowserWithPath>::iterator BrowserIterator;
  BrowserIterator FindBrowserForPath(const std::string& path);

  void RemoveBrowserFromVector(const std::string& path);

  Profile* profile_;
  std::vector<BrowserWithPath> browsers_;
  NotificationRegistrar registrar_;

  DISALLOW_COPY_AND_ASSIGN(USBMountObserver);
};

} // namespace chromeos
#endif  // CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_