OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ |
6 #define CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ | 6 #define CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ |
7 | 7 |
| 8 #include "base/memory/weak_ptr.h" |
8 #include "base/system_monitor/system_monitor.h" | 9 #include "base/system_monitor/system_monitor.h" |
9 | 10 |
10 class Browser; | 11 class Browser; |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 class WebContentsDelegate; | 14 class WebContentsDelegate; |
14 } | 15 } |
15 | 16 |
16 // Listens for media devices attached to the system. When such are detected, | 17 // Listens for media devices attached to the system. When such are detected, |
17 // translates the notification into a Web Intents dispatch. | 18 // translates the notification into a Web Intents dispatch. |
18 // The intent payload is: | 19 // The intent payload is: |
19 // action = "chrome-extension://attach" | 20 // action = "chrome-extension://attach" |
20 // type = "chrome-extension://filesystem" | 21 // type = "chrome-extension://filesystem" |
21 // root_path = the File Path at which the device is accessible | 22 // root_path = the File Path at which the device is accessible |
22 // filesystem_id = registered isolated file system identifier | 23 // filesystem_id = registered isolated file system identifier |
23 class DeviceAttachedIntentSource | 24 class DeviceAttachedIntentSource |
24 : public base::SystemMonitor::DevicesChangedObserver { | 25 : public base::SystemMonitor::DevicesChangedObserver, |
| 26 public base::SupportsWeakPtr<DeviceAttachedIntentSource> { |
25 public: | 27 public: |
26 DeviceAttachedIntentSource(Browser* browser, | 28 DeviceAttachedIntentSource(Browser* browser, |
27 content::WebContentsDelegate* delegate); | 29 content::WebContentsDelegate* delegate); |
28 virtual ~DeviceAttachedIntentSource(); | 30 virtual ~DeviceAttachedIntentSource(); |
29 | 31 |
30 // base::SystemMonitor::DevicesChangedObserver implementation. | 32 // base::SystemMonitor::DevicesChangedObserver implementation. |
31 virtual void OnMediaDeviceAttached( | 33 virtual void OnMediaDeviceAttached( |
32 const std::string& id, | 34 const std::string& id, |
33 const string16& name, | 35 const string16& name, |
34 base::SystemMonitor::MediaDeviceType type, | 36 base::SystemMonitor::MediaDeviceType type, |
35 const FilePath::StringType& location) OVERRIDE; | 37 const FilePath::StringType& location) OVERRIDE; |
36 virtual void OnMediaDeviceDetached(const std::string& id) OVERRIDE; | 38 virtual void OnMediaDeviceDetached(const std::string& id) OVERRIDE; |
37 | 39 |
| 40 // Dispatches web intents for the attached media device specified by |
| 41 // |device_info|. |
| 42 void DispatchIntentsForService( |
| 43 const base::SystemMonitor::MediaDeviceInfo& device_info); |
| 44 |
38 private: | 45 private: |
39 typedef std::map<std::string, base::SystemMonitor::MediaDeviceInfo> | 46 typedef std::map<std::string, base::SystemMonitor::MediaDeviceInfo> |
40 DeviceIdToInfoMap; | 47 DeviceIdToInfoMap; |
41 | 48 |
42 // Weak pointer to browser to which intents will be dispatched. | 49 // Weak pointer to browser to which intents will be dispatched. |
43 Browser* browser_; | 50 Browser* browser_; |
44 content::WebContentsDelegate* delegate_; | 51 content::WebContentsDelegate* delegate_; |
45 DeviceIdToInfoMap device_id_map_; | 52 DeviceIdToInfoMap device_id_map_; |
46 | 53 |
47 DISALLOW_COPY_AND_ASSIGN(DeviceAttachedIntentSource); | 54 DISALLOW_COPY_AND_ASSIGN(DeviceAttachedIntentSource); |
48 }; | 55 }; |
49 | 56 |
50 #endif // CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ | 57 #endif // CHROME_BROWSER_INTENTS_DEVICE_ATTACHED_INTENT_SOURCE_H_ |
OLD | NEW |