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