OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/singleton.h" | |
joth
2010/12/09 15:06:40
remove, fwd declare traits
| |
12 #include "chrome/browser/chromeos/cros/mount_library.h" | 13 #include "chrome/browser/chromeos/cros/mount_library.h" |
13 #include "chrome/common/notification_observer.h" | 14 #include "chrome/common/notification_observer.h" |
14 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
15 #include "chrome/common/notification_source.h" | 16 #include "chrome/common/notification_source.h" |
16 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
17 | 18 |
18 class Browser; | 19 class Browser; |
19 class Profile; | 20 class Profile; |
20 | 21 |
21 namespace chromeos { // NOLINT | 22 namespace chromeos { // NOLINT |
22 | 23 |
23 // Used to monitor mount changes and popup a new window when | 24 // Used to monitor mount changes and popup a new window when |
24 // a new mounted usb device is found. | 25 // a new mounted usb device is found. |
25 class USBMountObserver : public chromeos::MountLibrary::Observer, | 26 class USBMountObserver : public chromeos::MountLibrary::Observer, |
26 public NotificationObserver { | 27 public NotificationObserver { |
27 public: | 28 public: |
28 struct BrowserWithPath { | 29 struct BrowserWithPath { |
29 Browser* browser; | 30 Browser* browser; |
30 std::string device_path; | 31 std::string device_path; |
31 std::string mount_path; | 32 std::string mount_path; |
32 }; | 33 }; |
33 | 34 |
34 USBMountObserver() {} | 35 static USBMountObserver* Get(); |
35 ~USBMountObserver() {} | |
36 | 36 |
37 static USBMountObserver* Get() { | |
38 return Singleton<USBMountObserver>::get(); | |
39 } | |
40 void Observe(NotificationType type, | 37 void Observe(NotificationType type, |
41 const NotificationSource& source, | 38 const NotificationSource& source, |
42 const NotificationDetails& details); | 39 const NotificationDetails& details); |
43 | 40 |
44 void MountChanged(chromeos::MountLibrary* obj, | 41 void MountChanged(chromeos::MountLibrary* obj, |
45 chromeos::MountEventType evt, | 42 chromeos::MountEventType evt, |
46 const std::string& path); | 43 const std::string& path); |
47 | 44 |
48 void ScanForDevices(chromeos::MountLibrary* obj); | 45 void ScanForDevices(chromeos::MountLibrary* obj); |
49 | 46 |
50 private: | 47 private: |
48 friend struct DefaultSingletonTraits<USBMountObserver>; | |
51 typedef std::vector<BrowserWithPath>::iterator BrowserIterator; | 49 typedef std::vector<BrowserWithPath>::iterator BrowserIterator; |
52 BrowserIterator FindBrowserForPath(const std::string& path); | 50 BrowserIterator FindBrowserForPath(const std::string& path); |
53 | 51 |
52 USBMountObserver() {} | |
53 ~USBMountObserver() {} | |
54 | |
54 void RemoveBrowserFromVector(const std::string& path); | 55 void RemoveBrowserFromVector(const std::string& path); |
55 | 56 |
56 // Used to create a window of a standard size, and add it to a list | 57 // Used to create a window of a standard size, and add it to a list |
57 // of tracked browser windows in case that device goes away. | 58 // of tracked browser windows in case that device goes away. |
58 void OpenFileBrowse(const std::string& url, | 59 void OpenFileBrowse(const std::string& url, |
59 const std::string& device_path, | 60 const std::string& device_path, |
60 bool small); | 61 bool small); |
61 | 62 |
62 std::vector<BrowserWithPath> browsers_; | 63 std::vector<BrowserWithPath> browsers_; |
63 NotificationRegistrar registrar_; | 64 NotificationRegistrar registrar_; |
64 | 65 |
65 DISALLOW_COPY_AND_ASSIGN(USBMountObserver); | 66 DISALLOW_COPY_AND_ASSIGN(USBMountObserver); |
66 }; | 67 }; |
67 | 68 |
68 } // namespace chromeos | 69 } // namespace chromeos |
69 #endif // CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ | 70 #endif // CHROME_BROWSER_CHROMEOS_USB_MOUNT_OBSERVER_H_ |
OLD | NEW |